Skip to content

Commit 562418b

Browse files
committed
Added color indication to pass/fail for accessibility.
1 parent b6d9411 commit 562418b

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"closure-compiler-npm": "google/closure-compiler-npm"
99
},
1010
"dependencies": {
11+
"chalk": "^4.1.0",
1112
"future-event": "^1.5.0",
1213
"glob": "^7.1.6",
1314
"google-closure-library": "^20200719.0.0",

utils/js/runtimeTests.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
*/
2222

2323
const { JSDOM, VirtualConsole } = require('jsdom');
24+
const { fail } = require('assert');
25+
const chalk = require('chalk');
2426
const fs = require('fs');
25-
const path = require('path');
2627
const FutureEvent = require('future-event');
27-
const { fail } = require('assert');
2828
const glob = require('glob');
29+
const path = require('path');
2930

3031
const TEST_FILES = glob.sync(path.resolve(
3132
__dirname,
@@ -35,13 +36,29 @@ const TEST_FILES = glob.sync(path.resolve(
3536
describe('Runtime tests', () => {
3637
for (const TEST_URL of TEST_FILES) {
3738
const logs = [];
39+
const passed = /PASSED/i;
40+
const failed = /FAILED/i;
41+
3842
const allLogs = () => logs.join('\n');
43+
const chalkMsg = (msg) => {
44+
const isPass = passed.test(msg);
45+
const isFail = failed.test(msg);
46+
47+
if (isPass || isFail) {
48+
return msg.replace(
49+
passed, chalk.green('PASSED')
50+
).replace(
51+
failed, chalk.red('FAILED')
52+
);
53+
}
54+
else return msg;
55+
}
3956

4057
const TEST_NAME = path.basename(TEST_URL);
4158
const TestIsFinished = new FutureEvent();
4259
const virtualConsole = new VirtualConsole()
4360
.on('log', (msg) => {
44-
logs.push(msg);
61+
logs.push(chalkMsg(msg));
4562
if (/Tests complete/i.test(msg)) TestIsFinished.ready(allLogs());
4663
else if (/Tests failed/i.test(msg)) TestIsFinished.cancel(allLogs());
4764
});
@@ -65,9 +82,9 @@ describe('Runtime tests', () => {
6582
try {
6683
await TestIsFinished;
6784
} catch(e) {
68-
fail(`Failed test in suite ${TEST_NAME}: \n\n${e}`);
85+
fail(`Failed test in suite ${TEST_NAME}: \n${e}\n`);
6986
}
7087
console.log(`Passed all tests in suite ${TEST_NAME}`);
71-
});
88+
}, 20000);
7289
}
7390
});

0 commit comments

Comments
 (0)