ts-ci/src/test/index.ts

42 lines
1 KiB
TypeScript
Raw Normal View History

2020-05-27 22:02:44 +02:00
//This will not run on deno, we need a separate test runner for Deno (./mod.ts).
2020-05-14 00:47:15 +02:00
import * as child_process from "child_process";
import * as path from "path";
2020-05-22 17:49:14 +02:00
import { Deferred } from "evt/tools/Deferred";
2020-05-14 00:47:15 +02:00
2020-05-27 22:02:44 +02:00
const names = ["myFunction", "myObject", "getProjectRoot"];
2020-05-14 00:47:15 +02:00
2020-05-27 22:02:44 +02:00
(async () => {
2020-05-14 00:47:15 +02:00
if (!!process.env.FORK) {
2020-05-27 22:02:44 +02:00
process.once("unhandledRejection", error => {
throw error;
});
2020-05-14 00:47:15 +02:00
require(process.env.FORK);
return;
}
2020-05-27 22:02:44 +02:00
for (const name of names) {
2020-05-14 00:47:15 +02:00
console.log(`Running: ${name}`);
const dExitCode = new Deferred<number>();
2020-05-27 22:02:44 +02:00
child_process
.fork(__filename, undefined, {
"env": { "FORK": path.join(__dirname, name) },
})
2020-05-14 00:47:15 +02:00
.on("message", console.log)
2020-05-27 22:02:44 +02:00
.once("exit", code => dExitCode.resolve(code ?? 1));
2020-05-14 00:47:15 +02:00
const exitCode = await dExitCode.pr;
if (exitCode !== 0) {
console.log(`${name} exited with error code: ${exitCode}`);
process.exit(exitCode);
}
console.log("\n");
}
})();