-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtest.js
103 lines (83 loc) · 3.03 KB
/
test.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const ChildProcess = require("child_process");
const chalk = require("chalk");
const os = require("os");
const fs = require("fs");
// Avoiding "DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code."
// by actually doing the respective exit with non-zero code.
// This allows the watcher to restart this process.
process.on(
"unhandledRejection",
(reason, promise) =>
{
console.log("[" + process.pid + "] Unhandled Rejection at: Promise", promise, "reason", reason);
process.exit(1);
}
);
process.on(
"uncaughtException",
(error) => {
console.log("[" + process.pid + "] Unhandled exception.");
console.error(error);
process.exit(1);
}
);
async function spawnPassthru(strExecutablePath, arrParams = [])
{
const childProcess = ChildProcess.spawn(strExecutablePath, arrParams, {stdio: "inherit"});
//childProcess.stdout.pipe(process.stdout);
//childProcess.stderr.pipe(process.stderr);
return new Promise(async(fnResolve, fnReject) => {
childProcess.on("error", fnReject);
childProcess.on("exit", (nCode) => {
if(nCode === 0)
{
fnResolve();
}
else
{
fnReject(new Error(`Exec process exited with error code ${nCode}`));
}
});
});
}
(async() => {
process.chdir(__dirname);
let bBuiltNow = false;
try
{
if(!fs.existsSync("./builds/browser/es5/jsonrpc.min.js"))
{
bBuiltNow = true;
console.log(chalk.bgWhite.black("npm run build"));
await spawnPassthru("npm" + (os.platform() === "win32" ? ".cmd" : ""), ["run", "build"]);
}
console.log(chalk.bgWhite.black("npm run test_lib"));
await spawnPassthru("npm" + (os.platform() === "win32" ? ".cmd" : ""), ["run", "test_lib"]);
console.log(chalk.bgWhite.black("npm run test_cluster"));
await spawnPassthru("npm" + (os.platform() === "win32" ? ".cmd" : ""), ["run", "test_cluster"]);
console.log(chalk.bgWhite.black("npm run test_worker_threads"));
await spawnPassthru("npm" + (os.platform() === "win32" ? ".cmd" : ""), ["run", "test_worker_threads"]);
// @TODO: automate test_rtc using headless Chrome.
// console.log(chalk.bgWhite.black("npm run test_rtc"));
// await spawnPassthru("npm" + (os.platform() === "win32" ? ".cmd" : ""), ["run", "test_rtc"]);
// @TODO Add CPU stress parallel process to test for race conditions.
console.log("");
console.log("[" + process.pid + "] \x1b[42m\x1b[30mAll tests done (test_lib, test_cluster, test_worker_threads). No unhandled (intentional) errors encountered.\x1b[0m Which means all is good or the tests are incomplete/buggy.");
console.log("");
}
catch(error)
{
if(bBuiltNow)
{
if(fs.existsSync("./builds/browser/es5/jsonrpc.min.js"))
{
fs.unlinkSync("./builds/browser/es5/jsonrpc.min.js");
}
if(fs.existsSync("./builds/browser/es7/jsonrpc.min.js"))
{
fs.unlinkSync("./builds/browser/es7/jsonrpc.min.js");
}
}
throw error;
}
})();