-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderInNonBrowser.js
47 lines (39 loc) · 1.46 KB
/
renderInNonBrowser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {renderTestReport} from './renderInBoth.js';
// import {genFix} from './fix.js';
// import { readFileSync, writeFileSync } from 'fs';
export const verboseReportStart = '--vrstart--';
const resetColor = `\x1b[0m`;
const hiddenColor = `\x1b[8m`;
export function renderInNonBrowser(testReport, failureReports, callerInfo) {
if (failureReports.length) {
consoleRenderFunc([
verboseReportStart,
JSON.stringify({
filePath: callerInfo.filePath,
failureReports: failureReports.map(fRep => {
return {
name: fRep.name,
errString: fRep.errString ? fRep.errString : undefined,
got: fRep.errString ? undefined : fRep.got,
};
}),
}),
].join(''), {color: hiddenColor});
consoleRenderFunc('--'.repeat(20), {color: resetColor});
consoleRenderFunc('');
}
renderTestReport(testReport, consoleRenderFunc);
if (failureReports.length) {
consoleRenderFunc(`\n🔧 To auto-fix the above test (i.e. assuming that the implementation is correct), run the following:`);
consoleRenderFunc(`${process.argv.join(' ')} | npx @clubfest/table-test\n`, {indent: 4});
}
}
function consoleRenderFunc(possStr, opts) {
opts = opts || {};
const lines = possStr ? possStr.split('\n') : [possStr];
lines.forEach(line => {
const args = opts.color ? [`${opts.color}%s`] : [`${resetColor}%s`];
args.push(' '.repeat(opts.indent || 0) + line);
console.log(...args);
});
}