How to use valueWidths method in stryker-parent

Best JavaScript code snippet using stryker-parent

terminal.ts

Source:terminal.ts Github

copy

Full Screen

1// http://ascii-table.com/ansi-escape-sequences.php2// console.log('\x1b[36m%s\x1b[0m', 'I am cyan'); //cyan3// console.log('\x1b[33m%s\x1b[0m', stringToMakeYellow); //yellow4// - Position the Cursor:5// \033[<L>;<C>H6// Or7// \033[<L>;<C>f8// puts the cursor at line L and column C.9// - Move the cursor up N lines:10// \033[<N>A11// - Move the cursor down N lines:12// \033[<N>B13// - Move the cursor forward N columns:14// \033[<N>C15// - Move the cursor backward N columns:16// \033[<N>D17// - Clear the screen, move to (0,0):18// \033[2J19// - Erase to end of line:20// \033[K21// - Save cursor position:22// \033[s23// - Restore cursor position:24// \033[u25// TO HEX:26// console.log('\033c'); // Clear screen27// console.log('\x1Bc'); // Clear screen 1B = 3328const Reset = "\x1b[0m"29const Bright = "\x1b[1m"30const Dim = "\x1b[2m"31const Underscore = "\x1b[4m"32const Blink = "\x1b[5m"33const Reverse = "\x1b[7m"34const Hidden = "\x1b[8m"35const FgBlack = "\x1b[30m"36const FgRed = "\x1b[31m"37const FgGreen = "\x1b[32m"38const FgYellow = "\x1b[33m"39const FgBlue = "\x1b[34m"40const FgMagenta = "\x1b[35m"41const FgCyan = "\x1b[36m"42const FgWhite = "\x1b[37m"43const BgBlack = "\x1b[40m"44const BgRed = "\x1b[41m"45const BgGreen = "\x1b[42m"46const BgYellow = "\x1b[43m"47const BgBlue = "\x1b[44m"48const BgMagenta = "\x1b[45m"49const BgCyan = "\x1b[46m"50const BgWhite = "\x1b[47m"51// console.info(FgGreen);52// console.info("FgGreen");53// console.info(Reset);54// console.log('Terminal size: ' + process.stdout.columns + 'x' + process.stdout.rows);55// setTimeout(() => {56// process.stdout.write('\n\033[1A');57// console.info('Your text here');58// }, 2000);59const maxLen = (data: string[]) => {60 let max = 0;61 data.forEach(item => max = Math.max(max, item.length));62 return max;63}64const sum = (data: number[]) => {65 let sum = 0;66 data.forEach(item => sum += item);67 return sum;68}69const padRight = (item: string, len: number) => {70 while (item.length < len) { item += ' ' }71 return item;72}73interface KeyCallback {74 println: (text: string) => void;75}76export class TerminalTools {77 public static selectArray(options: string[]) {78 return new Promise<string>((res, rej) => {79 var len = maxLen(options);80 var lines = options.map(line => padRight(line, len));81 var index = 0;82 var printHeight = 0;83 var print = () => {84 TerminalTools.backLine(printHeight);85 console.info(lines.map((line, idx) => {86 if (idx == index) {87 return ' [' + line + ']';88 } else {89 return ' ' + line + ' ';90 }91 }).join('\n'));92 printHeight = lines.length;93 }94 var stdin = process.stdin;95 var stdout = process.stdout;96 stdin.setRawMode(true);97 stdin.resume();98 var callback = function (key) {99 if (key[0] == 13) {100 stdin.pause();101 stdin.removeListener('data', callback);102 TerminalTools.backLine(printHeight);103 res(options[index]);104 return;105 }106 if (key[0] == 3) {107 stdin.pause();108 stdin.removeListener('data', callback);109 TerminalTools.backLine(printHeight);110 //process.exit();111 rej();112 return;113 }114 // UP 115 if (key.length == 3 && key[0] == 27 && key[1] == 91 && key[2] == 65) {116 index = Math.max(0, index - 1);117 }118 // DOWN119 if (key.length == 3 && key[0] == 27 && key[1] == 91 && key[2] == 66) {120 index = Math.min(options.length - 1, index + 1);121 }122 print();123 }124 stdin.on('data', callback);125 print();126 });127 }128 public static readLine(prompt: string, callabck?: (line: string, action: KeyCallback) => void) {129 return new Promise<string>((res, rej) => {130 var stdin = process.stdin;131 var stdout = process.stdout;132 stdin.setRawMode(true);133 stdin.resume();134 ///stdin.setEncoding('utf8');135 stdout.write('\n\x1B[1A' + prompt);136 var line = '';137 var callback = function (key) {138 if (key[0] == 13) {139 stdin.pause();140 stdin.removeListener('data', callback);141 stdout.write('\n');142 res(line);143 return;144 }145 if (key[0] == 3) {146 stdin.pause();147 stdin.removeListener('data', callback);148 stdout.write('\n');149 //process.exit();150 rej();151 return;152 }153 if (key[0] == 127) {154 line = line.substr(0, Math.max(0, line.length - 1))155 } else {156 line += key.toString('UTF-8');157 }158 if (callabck) {159 callabck(line, {160 println: (text: string) => {161 stdout.write('\n\x1B[1A\x1B[K');162 stdout.write(prompt + text + '');163 }164 });165 } else {166 stdout.write('\n\x1B[1A\x1B[K');167 stdout.write(prompt + line + '');168 }169 }170 stdin.on('data', callback);171 });172 }173 public static backLine(count: number = 1) {174 var stdout = process.stdout;175 for (let i = 0; i < count; i++) {176 stdout.write('\x1B[1A\x1B[K');177 }178 }179 public static printArray(data: string[]) {180 let width = process.stdout.columns;181 for (var height = 1; height <= data.length; height++) {182 let widths = [];183 for (var chunkIndex = 0; chunkIndex < data.length; chunkIndex += height) {184 widths.push(maxLen(data.slice(chunkIndex, chunkIndex + height)));185 }186 if (sum(widths) + (widths.length - 1) * 2 < width) {187 // print out 188 let chunks = [];189 for (var chunkIndex = 0; chunkIndex < data.length; chunkIndex += height) {190 chunks.push(data.slice(chunkIndex, chunkIndex + height));191 }192 let lines = [];193 for (var i = 0; i < height; i++) {194 let line = [];195 chunks.forEach((chunk, col) => {196 if (chunk.length > i) { line.push(padRight(chunk[i], widths[col])); }197 });198 lines.push(line);199 }200 console.info(lines.map(line => line.join(' ')).join('\n'));201 return lines.length;202 }203 }204 }205 public static printObject(obj: any) {206 let width = process.stdout.columns;207 let data = Object.entries(obj).map(entry => [entry[0], '' + entry[1]]);208 let keys = data.map(entry => entry[0]);209 let values = data.map(entry => entry[1]);210 for (var height = 1; height <= data.length; height++) {211 let keyWidths = [];212 let valueWidths = [];213 for (var chunkIndex = 0; chunkIndex < data.length; chunkIndex += height) {214 keyWidths.push(maxLen(keys.slice(chunkIndex, chunkIndex + height)));215 valueWidths.push(maxLen(values.slice(chunkIndex, chunkIndex + height)));216 }217 if (sum(keyWidths) + sum(valueWidths) + (keyWidths.length * 2) + (valueWidths.length) - 1 < width) {218 // print out 219 let chunks = [];220 for (var chunkIndex = 0; chunkIndex < data.length; chunkIndex += height) {221 chunks.push(data.slice(chunkIndex, chunkIndex + height));222 }223 let lines = [];224 for (var i = 0; i < height; i++) {225 let line = [];226 chunks.forEach((chunk, col) => {227 if (chunk.length > i) {228 line.push(padRight(chunk[i][0], keyWidths[col]) + ' ' + padRight(chunk[i][1], valueWidths[col]));229 }230 });231 lines.push(line);232 }233 console.info(lines.map(line => line.join(' ')).join('\n'));234 return lines.length;235 }236 }237 }...

Full Screen

Full Screen

clear-text-score-table.ts

Source:clear-text-score-table.ts Github

copy

Full Screen

1import os from 'os';2import { MutationScoreThresholds } from '@stryker-mutator/api/core';3import { MetricsResult } from 'mutation-testing-metrics';4import chalk from 'chalk';5import flatMap from 'lodash.flatmap';6const FILES_ROOT_NAME = 'All files';7type TableCellValueFactory = (row: MetricsResult, ancestorCount: number) => string;8const repeat = (char: string, nTimes: number) => new Array(nTimes > -1 ? nTimes + 1 : 0).join(char);9const spaces = (n: number) => repeat(' ', n);10const dots = (n: number) => repeat('.', n);11/**12 * Represents a column in the clear text table13 */14class Column {15 protected width: number;16 constructor(public header: string, public valueFactory: TableCellValueFactory, public rows: MetricsResult) {17 const maxContentSize = this.determineValueSize();18 this.width = this.pad(dots(maxContentSize)).length;19 }20 protected determineValueSize(row: MetricsResult = this.rows, ancestorCount = 0): number {21 const valueWidths = row.childResults.map((child) => this.determineValueSize(child, ancestorCount + 1));22 valueWidths.push(this.header.length);23 valueWidths.push(this.valueFactory(row, ancestorCount).length);24 return Math.max(...valueWidths);25 }26 /**27 * Adds padding (spaces) to the front and end of a value28 * @param input The string input29 */30 protected pad(input: string): string {31 return `${spaces(this.width - input.length - 2)} ${input} `;32 }33 public drawLine(): string {34 return repeat('-', this.width);35 }36 public drawTableCell(score: MetricsResult, ancestorCount: number) {37 return this.color(score)(this.pad(this.valueFactory(score, ancestorCount)));38 }39 public drawHeader() {40 return this.pad(this.header);41 }42 protected color(_score: MetricsResult) {43 return (input: string) => input;44 }45}46class MutationScoreColumn extends Column {47 constructor(rows: MetricsResult, private readonly thresholds: MutationScoreThresholds) {48 super('% score', (row) => row.metrics.mutationScore.toFixed(2), rows);49 }50 protected color(metricsResult: MetricsResult) {51 if (metricsResult.metrics.mutationScore >= this.thresholds.high) {52 return chalk.green;53 } else if (metricsResult.metrics.mutationScore >= this.thresholds.low) {54 return chalk.yellow;55 } else {56 return chalk.red;57 }58 }59}60class FileColumn extends Column {61 constructor(rows: MetricsResult) {62 super('File', (row, ancestorCount) => spaces(ancestorCount) + (ancestorCount === 0 ? FILES_ROOT_NAME : row.name), rows);63 }64 protected pad(input: string): string {65 return `${input} ${spaces(this.width - input.length - 1)}`;66 }67}68/**69 * Represents a clear text table for mutation score70 */71export class ClearTextScoreTable {72 private readonly columns: Column[];73 constructor(private readonly metricsResult: MetricsResult, thresholds: MutationScoreThresholds) {74 this.columns = [75 new FileColumn(metricsResult),76 new MutationScoreColumn(metricsResult, thresholds),77 new Column('# killed', (row) => row.metrics.killed.toString(), metricsResult),78 new Column('# timeout', (row) => row.metrics.timeout.toString(), metricsResult),79 new Column('# survived', (row) => row.metrics.survived.toString(), metricsResult),80 new Column('# no cov', (row) => row.metrics.noCoverage.toString(), metricsResult),81 new Column('# error', (row) => (row.metrics.runtimeErrors + row.metrics.compileErrors).toString(), metricsResult),82 ];83 }84 private drawBorder() {85 return this.drawRow((column) => column.drawLine());86 }87 private drawHeader() {88 return this.drawRow((c) => c.drawHeader());89 }90 private drawRow(toDraw: (col: Column) => string) {91 return this.columns.map(toDraw).join('|') + '|';92 }93 private drawValues(current = this.metricsResult, ancestorCount = 0): string[] {94 return [this.drawRow((c) => c.drawTableCell(current, ancestorCount))].concat(95 flatMap(current.childResults, (child) => this.drawValues(child, ancestorCount + 1))96 );97 }98 /**99 * Returns a string with the score results drawn in a table.100 */101 public draw(): string {102 return [this.drawBorder(), this.drawHeader(), this.drawBorder(), this.drawValues().join(os.EOL), this.drawBorder()].join(os.EOL);103 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const valueWidths = require('stryker-parent').valueWidths;2const obj = {3};4console.log(valueWidths(obj));5const valueWidths = require('stryker-parent').valueWidths;6const obj = {7};8console.log(valueWidths(obj));

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful