forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreaded_runner.ts
More file actions
83 lines (72 loc) · 2.48 KB
/
Copy paththreaded_runner.ts
File metadata and controls
83 lines (72 loc) · 2.48 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import {MatchError} from "alsatian";
import * as glob from "glob";
import * as os from "os";
import * as path from "path";
import {config, Pool} from "threads";
function fileArrToString(fileArr: string[]): string {
return fileArr.map(val => path.basename(val).replace(".spec.js", "")).join(", ");
}
function printTestStats(testCount: number, failedTestCount: number, header: string, footer: string): void {
console.log("-----------------");
console.log(header);
console.log(`Total: ${testCount}`);
console.log(`Passed: ${testCount - failedTestCount}`);
console.log(`Failed: ${failedTestCount}`);
console.log(footer);
console.log("-----------------");
}
config.set({
basepath: {
node: __dirname,
}
});
let cpuCount = os.cpus().length + 1;
if ("TRAVIS" in process.env && "CI" in process.env) {
// fixed thread count for CI
cpuCount = 8;
}
const testFiles: string[] = glob.sync("./test/**/*.spec.js");
const pool = new Pool(cpuCount);
let jobCounter = 0;
const testStartTime = new Date();
const fileCount = testFiles.length;
let exitWithError = false;
let totalTestCount = 0;
let totalFailedTestCount = 0;
console.log(
`Running tests: ${fileArrToString(testFiles)} with ${cpuCount} threads`);
testFiles.forEach(file => {
pool.run("./test_thread")
.send({files: [file]})
.on("done",
(testCount, failedTestCount) => {
if (failedTestCount !== 0) {
exitWithError = true;
}
totalTestCount += testCount;
totalFailedTestCount += failedTestCount;
jobCounter++;
printTestStats(
testCount,
failedTestCount,
`Tests ${file} results:`,
`Thread: ${jobCounter}/${fileCount} done.`);
})
.on("error", error => {
console.log("Fatal non test related Exception in test file:", file, error);
});
});
pool.on("finished", () => {
let footer = "All tests passed!";
if (exitWithError) {
footer = "Exiting with Error: One or more tests failed!";
}
printTestStats(totalTestCount, totalFailedTestCount, "Final Results:", footer);
console.log("Everything done, shutting down the thread pool.");
const timeInMs = (new Date().valueOf() - testStartTime.valueOf());
console.log(`Tests took: ${Math.floor(timeInMs / 1000 / 60)}:${Math.floor(timeInMs / 1000) % 60}`);
pool.killAll();
if (exitWithError) {
process.exit(1);
}
});