Skip to content

Commit 09c2f42

Browse files
committed
Add a test with a timeout for unitTest
1 parent 138768d commit 09c2f42

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { assert } from "testing/asserts";
2+
import { execProcess } from "../../../src/core/process.ts";
3+
import { quartoDevCmd } from "../../utils.ts";
4+
import { unitTest } from "../../test.ts";
5+
6+
const testPassthroughCmd = (name: string, command: string, args: string[]) => {
7+
unitTest(name, async () => {
8+
const result = await execProcess({
9+
cmd: [
10+
quartoDevCmd(),
11+
command,
12+
...args,
13+
]
14+
});
15+
assert(result.success);
16+
});
17+
}
18+
19+
// Check Pandoc passthrough
20+
testPassthroughCmd("passthrough-pandoc", "pandoc", ["--version"]);
21+
// Check Typst passthrough
22+
testPassthroughCmd("passthrough-typst", "typst", ["--version"]);

tests/test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*/
77
import { existsSync } from "../src/deno_ral/fs.ts";
8-
import { fail } from "testing/asserts";
8+
import { AssertionError, fail } from "testing/asserts";
99
import { warning } from "../src/deno_ral/log.ts";
1010
import { initDenoDom } from "../src/core/deno-dom.ts";
1111

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

0 commit comments

Comments
 (0)