Skip to content

Commit

Permalink
test(examples): added assertions for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mgordel committed Sep 19, 2023
1 parent e366264 commit a13c7bf
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions tests/examples/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const spawnedExamples: ChildProcess[] = [];
async function examplesTest(cmd: string, path: string, args: string[] = [], timeout = 120) {
const file = basename(path);
const cwd = dirname(path);
const spawnedExample = spawn(cmd, [file, ...args], { stdio: "inherit", cwd });
const spawnedExample = spawn(cmd, [file, ...args], { cwd });
spawnedExamples.push(spawnedExample);
spawnedExample.stdout?.setEncoding("utf-8");
const testPromise = new Promise((res, rej) => {
Expand All @@ -53,19 +53,22 @@ async function examplesTest(cmd: string, path: string, args: string[] = [], time

async function testAll(examples: Example[]) {
let exitCode = 0;
const failedTests = new Map<string, boolean>();
await Promise.race([goth.start(), timeoutPromise(180)]);
try {
for (const example of examples) {
console.log(`\n---- Starting test for example ${example.path} ----\n`);
for (const example of examples) {
try {
console.log(`\n---- Starting test for example: "${example.path}" ----\n`);
await examplesTest(example.cmd, example.path, example.args);
} catch (error) {
console.error(error);
failedTests.set(example.path, false);
}
} catch (error) {
console.error(error);
exitCode = 1;
} finally {
await goth.end().catch((error) => console.error(error));
spawnedExamples.forEach((example) => example?.kill());
}
await goth.end().catch((error) => console.error(error));
spawnedExamples.forEach((example) => example?.kill());
console.log(
`TESTS:\t${examples.length - failedTests.size} passed, ${failedTests.size} failed, ${examples.length} total`,
);
process.exit(exitCode);
}

Expand Down

0 comments on commit a13c7bf

Please sign in to comment.