Skip to content

Commit a0c23f6

Browse files
authored
Merge pull request #11245 from quarto-dev/test/quarto-require-env-var
Add a test for the environment variable QUARTO_VERSION_REQUIREMENT
2 parents 72304b9 + d3a80b4 commit a0c23f6

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

tests/docs/quarto-required.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: Hello Callout!
33
format:
44
html:
55
quarto-required: "<= 0.0.0"
6+
html+norequire: default
67
---
78

89
This file will not be rendered as it does not respect the quarto version requirement

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,35 @@ testQuartoCmd(
1616
[input],
1717
[printsMessage("ERROR", /does not satisfy version/)]
1818
);
19+
20+
let oldVersionRequirement: string | undefined;
21+
let originalDenoExit: typeof Deno.exit;
22+
23+
testQuartoCmd(
24+
"render",
25+
[input, "--to", "html+norequire"],
26+
[printsMessage("ERROR", /does not meet semver requirement/)],
27+
{
28+
setup: async () => {
29+
// Save current version of QUARTO_VERSION_REQUIREMENT env var and set it to a value that will not be satisfied
30+
oldVersionRequirement = Deno.env.get("QUARTO_VERSION_REQUIREMENT");
31+
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+
};
38+
},
39+
teardown: async () => {
40+
// Restore QUARTO_VERSION_REQUIREMENT
41+
if (oldVersionRequirement) {
42+
Deno.env.set("QUARTO_VERSION_REQUIREMENT", oldVersionRequirement);
43+
} else {
44+
Deno.env.delete("QUARTO_VERSION_REQUIREMENT");
45+
}
46+
// Restore Deno.exit
47+
Deno.exit = originalDenoExit;
48+
},
49+
}
50+
);

0 commit comments

Comments
 (0)