Skip to content

Commit d3a80b4

Browse files
committed
Mock Deno.exit() in the test to throw an error
This is required as Deno.exit(1) after `error()` is making `test.execute()` exit without possibility to cath the error and log the error to be verified. Our test logic does not even fail on this Deno.exit() happening. Tests continue and nor OK or FAILED is thrown. Our usual pattern to throw an error when using error(), but it may not apply in this case for checking version requirement in quarto.ts. This is why mocking is chosen here.
1 parent e846425 commit d3a80b4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/smoke/render/render-required.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ testQuartoCmd(
1818
);
1919

2020
let oldVersionRequirement: string | undefined;
21+
let originalDenoExit: typeof Deno.exit;
2122

2223
testQuartoCmd(
2324
"render",
@@ -28,6 +29,12 @@ testQuartoCmd(
2829
// Save current version of QUARTO_VERSION_REQUIREMENT env var and set it to a value that will not be satisfied
2930
oldVersionRequirement = Deno.env.get("QUARTO_VERSION_REQUIREMENT");
3031
Deno.env.set("QUARTO_VERSION_REQUIREMENT", "< 0.0.0");
32+
// Mock Deno.exit to throw an error instead of exiting
33+
// Otherwise we would not check the error assertion
34+
originalDenoExit = Deno.exit;
35+
Deno.exit = (code?: number) => {
36+
throw new Error(`Deno.exit called with code: ${code}`);
37+
};
3138
},
3239
teardown: async () => {
3340
// Restore QUARTO_VERSION_REQUIREMENT
@@ -36,6 +43,8 @@ testQuartoCmd(
3643
} else {
3744
Deno.env.delete("QUARTO_VERSION_REQUIREMENT");
3845
}
46+
// Restore Deno.exit
47+
Deno.exit = originalDenoExit;
3948
},
4049
}
4150
);

0 commit comments

Comments
 (0)