ts-ci/src/test/index.ts

50 lines
1 KiB
TypeScript
Raw Normal View History

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