Skip to content

Commit

Permalink
fix(test): catch errors from global setup and teardown (#1594)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkdev98 committed Feb 9, 2022
1 parent 2aa26d4 commit 5a2e6bf
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/cli/src/testing/test.js
@@ -1,6 +1,7 @@
import { setTimeout } from "timers/promises";
import { pathToFileURL } from "url";
import { isMainThread, parentPort, threadId } from "worker_threads";
import { mainFn } from "@compas/stdlib";
import { AppError, mainFn } from "@compas/stdlib";
import { loadTestConfig } from "./config.js";
import {
markTestFailuresRecursively,
Expand Down Expand Up @@ -29,11 +30,36 @@ async function main(logger) {
setTestLogger(logger);

await loadTestConfig();
await globalSetup();

try {
await globalSetup();
} catch (e) {
logger.error({
message: "Error when calling the 'setup' defined in 'test/config.js'.",
error: AppError.format(e),
});

// Give time to propagate the message to the main thread
await setTimeout(5);
process.exit(1);
}

const teardown = async () => {
await globalTeardown();
process.exit(0);
try {
await globalTeardown();
await setTimeout(5);
process.exit(0);
} catch (e) {
logger.error({
message:
"Error when calling the 'teardown' defined in 'test/config.js'.",
error: AppError.format(e),
});

// Give time to propagate the message to the main thread
await setTimeout(5);
process.exit(1);
}
};

const messageDispatcher = createMessageDispatcher(logger, teardown);
Expand Down

0 comments on commit 5a2e6bf

Please sign in to comment.