Skip to content

Commit dcae417

Browse files
committed
Fixed test runner not failing
1 parent ea2942b commit dcae417

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

test/runner.ts

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestRunner, TestSet } from "alsatian";
1+
import { TestRunner, TestSet, TestOutcome } from "alsatian";
22

33
import * as fs from "fs";
44
import * as path from "path";
@@ -20,21 +20,44 @@ fs.copyFileSync(
2020

2121
// setup the output
2222
testRunner.outputStream
23-
// pipe to the console
24-
.pipe(process.stdout);
23+
// pipe to the console
24+
.pipe(process.stdout);
25+
26+
let success = 0;
27+
let ignored = 0;
28+
let run = 0;
29+
testRunner.onTestComplete(test => {
30+
run++;
31+
32+
if (test.outcome === TestOutcome.Pass) {
33+
success++;
34+
} else if (test.outcome === TestOutcome.Skip) {
35+
ignored++;
36+
}
37+
});
2538

2639
// run the test set
2740
testRunner.run(testSet)
28-
// this will be called after all tests have been run
29-
.then(result => {
30-
// Remove lualib bundle again
31-
fs.unlinkSync("lualib_bundle.lua");
32-
})
33-
// this will be called if there was a problem
34-
.catch(error => {
35-
// Remove lualib bundle again
36-
fs.unlinkSync("lualib_bundle.lua");
37-
38-
console.error(error);
39-
process.exit(1);
40-
});
41+
// this will be called after all tests have been run
42+
.then(result => {
43+
// Remove lualib bundle again
44+
fs.unlinkSync("lualib_bundle.lua");
45+
46+
const nonIgnoredTests = run - ignored;
47+
const failedTests = nonIgnoredTests - success;
48+
console.log(`Ignored ${ignored}/${run} tests.`);
49+
console.log(`Failed ${failedTests}/${nonIgnoredTests} tests.`);
50+
console.log(`Passed ${success}/${nonIgnoredTests} tests.`);
51+
52+
if (failedTests > 0) {
53+
process.exit(1);
54+
}
55+
})
56+
// this will be called if there was a problem
57+
.catch(error => {
58+
// Remove lualib bundle again
59+
fs.unlinkSync("lualib_bundle.lua");
60+
61+
console.error(error);
62+
process.exit(1);
63+
});

0 commit comments

Comments
 (0)