summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-10-03 21:54:26 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-10-04 00:25:55 -0400
commit1331a4882cae67a771eb62266714efd8942521a1 (patch)
treec1ac548b08d3f4cd19a1d1d4e839306971cabed9 /js
parent2f44db6756f974ad3e258e4a777db2519f1b9091 (diff)
Better color output in JS unit tests.
Diffstat (limited to 'js')
-rw-r--r--js/testing/testing.ts31
1 files changed, 28 insertions, 3 deletions
diff --git a/js/testing/testing.ts b/js/testing/testing.ts
index b172688b7..64ecbb6bc 100644
--- a/js/testing/testing.ts
+++ b/js/testing/testing.ts
@@ -52,27 +52,52 @@ function filter(name: string): boolean {
}
}
+const RESET = "\x1b[0m";
+const FG_RED = "\x1b[31m";
+const FG_GREEN = "\x1b[32m";
+
+function red_failed() {
+ return FG_RED + "FAILED" + RESET
+}
+
+
+function green_ok() {
+ return FG_GREEN + "ok" + RESET
+}
+
async function runTests() {
let passed = 0;
let failed = 0;
+ console.log("running", tests.length, "tests");
for (let i = 0; i < tests.length; i++) {
const { fn, name } = tests[i];
- console.log(`${i + 1}/${tests.length} +${passed} -${failed}: ${name}`);
+ let result = green_ok();
try {
await fn();
passed++;
} catch (e) {
- console.error("\nTest FAIL", name);
+ result = red_failed();
console.error((e && e.stack) || e);
failed++;
if (exitOnFail) {
break;
}
}
+ console.log("test", name, "...", result);
}
- console.log(`\nDONE. Test passed: ${passed}, failed: ${failed}`);
+ // TODO counts for ignored , measured, filtered.
+ const filtered = 0;
+ const ignored = 0;
+ const measured = 0;
+
+ // Attempting to match the output of Rust's test runner.
+ const result = failed > 0 ? red_failed() : green_ok();
+ console.log(
+ `\ntest result: ${result}. ${passed} passed; ${failed} failed; ` +
+ `${ignored} ignored; ${measured} measured; ${filtered} filtered out\n`);
+
if (failed === 0) {
// All good.