diff --git a/tests/docs/quarto-required.qmd b/tests/docs/quarto-required.qmd index f4d8242f5b2..78fcd072785 100644 --- a/tests/docs/quarto-required.qmd +++ b/tests/docs/quarto-required.qmd @@ -3,6 +3,7 @@ title: Hello Callout! format: html: quarto-required: "<= 0.0.0" + html+norequire: default --- This file will not be rendered as it does not respect the quarto version requirement \ No newline at end of file diff --git a/tests/smoke/render/render-required.test.ts b/tests/smoke/render/render-required.test.ts index 68a216e9a2a..4cb83d36bb3 100644 --- a/tests/smoke/render/render-required.test.ts +++ b/tests/smoke/render/render-required.test.ts @@ -16,3 +16,35 @@ testQuartoCmd( [input], [printsMessage("ERROR", /does not satisfy version/)] ); + +let oldVersionRequirement: string | undefined; +let originalDenoExit: typeof Deno.exit; + +testQuartoCmd( + "render", + [input, "--to", "html+norequire"], + [printsMessage("ERROR", /does not meet semver requirement/)], + { + setup: async () => { + // Save current version of QUARTO_VERSION_REQUIREMENT env var and set it to a value that will not be satisfied + oldVersionRequirement = Deno.env.get("QUARTO_VERSION_REQUIREMENT"); + Deno.env.set("QUARTO_VERSION_REQUIREMENT", "< 0.0.0"); + // Mock Deno.exit to throw an error instead of exiting + // Otherwise we would not check the error assertion + originalDenoExit = Deno.exit; + Deno.exit = (code?: number) => { + throw new Error(`Deno.exit called with code: ${code}`); + }; + }, + teardown: async () => { + // Restore QUARTO_VERSION_REQUIREMENT + if (oldVersionRequirement) { + Deno.env.set("QUARTO_VERSION_REQUIREMENT", oldVersionRequirement); + } else { + Deno.env.delete("QUARTO_VERSION_REQUIREMENT"); + } + // Restore Deno.exit + Deno.exit = originalDenoExit; + }, + } +);