Skip to content

Commit

Permalink
Add a test with a timeout for unitTest
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv committed Nov 15, 2024
1 parent 138768d commit 09c2f42
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
22 changes: 22 additions & 0 deletions tests/smoke/run/command-passthrough.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { assert } from "testing/asserts";
import { execProcess } from "../../../src/core/process.ts";
import { quartoDevCmd } from "../../utils.ts";
import { unitTest } from "../../test.ts";

const testPassthroughCmd = (name: string, command: string, args: string[]) => {
unitTest(name, async () => {
const result = await execProcess({
cmd: [
quartoDevCmd(),
command,
...args,
]
});
assert(result.success);
});
}

// Check Pandoc passthrough
testPassthroughCmd("passthrough-pandoc", "pandoc", ["--version"]);
// Check Typst passthrough
testPassthroughCmd("passthrough-typst", "typst", ["--version"]);
7 changes: 5 additions & 2 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
*/
import { existsSync } from "../src/deno_ral/fs.ts";
import { fail } from "testing/asserts";
import { AssertionError, fail } from "testing/asserts";
import { warning } from "../src/deno_ral/log.ts";
import { initDenoDom } from "../src/core/deno-dom.ts";

Expand Down Expand Up @@ -153,7 +153,10 @@ export function unitTest(
{
name: `${name}`,
verify: async (_outputs: ExecuteOutput[]) => {
await ver();
const timeout = new Promise((_resolve, reject) => {
setTimeout(() => reject(new AssertionError(`timed out after 2 minutes. Something may be wrong with verify function in the test '${name}'.`)), 120000);
});
await Promise.race([ver(), timeout]);
},
},
],
Expand Down

0 comments on commit 09c2f42

Please sign in to comment.