Skip to content

Commit 2d00e97

Browse files
committed
try a test Site wrapper to run with profile
Running a render with profile is tricky as it needs to be done using environment variable, which is tricky in async tests. So probably not enough
1 parent ed1e04c commit 2d00e97

1 file changed

Lines changed: 35 additions & 10 deletions

File tree

tests/smoke/site/site.ts

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
*/
66
import { existsSync } from "../../../src/deno_ral/fs.ts";
77
import { dirname } from "../../../src/deno_ral/path.ts";
8-
import { testQuartoCmd, Verify } from "../../test.ts";
9-
import { projectOutputForInput } from "../../utils.ts";
8+
import { testQuartoCmd, Verify, TestContext, mergeTestContexts } from "../../test.ts";
9+
import { projectOutputForInput, restoreEnvVar, setEnvVar } from "../../utils.ts";
1010
import { ensureHtmlElements, noErrorsOrWarnings } from "../../verify.ts";
1111

1212
export const testSite = (
1313
input: string,
1414
renderTarget: string,
1515
includeSelectors: string[],
1616
excludeSelectors: string[],
17+
additionalContext?: TestContext,
1718
...verify: Verify[]
1819
) => {
1920
const output = projectOutputForInput(input);
@@ -24,18 +25,42 @@ export const testSite = (
2425
excludeSelectors,
2526
);
2627

28+
const baseContext: TestContext = {
29+
teardown: async () => {
30+
const siteDir = dirname(output.outputPath);
31+
if (existsSync(siteDir)) {
32+
await Deno.remove(siteDir, { recursive: true });
33+
}
34+
},
35+
};
36+
2737
// Run the command
2838
testQuartoCmd(
2939
"render",
3040
[renderTarget],
3141
[noErrorsOrWarnings, verifySel, ...verify],
32-
{
33-
teardown: async () => {
34-
const siteDir = dirname(output.outputPath);
35-
if (existsSync(siteDir)) {
36-
await Deno.remove(siteDir, { recursive: true });
37-
}
38-
},
39-
},
42+
mergeTestContexts(baseContext, additionalContext),
4043
);
4144
};
45+
46+
export function testSiteWithProfile(profile: string) {
47+
return (
48+
input: string,
49+
renderTarget: string,
50+
includeSelectors: string[],
51+
excludeSelectors: string[],
52+
...verify: Verify[]
53+
) => {
54+
let profileEnv: string | undefined;
55+
const additionalContext: TestContext = {
56+
name: `with profile: ${profile}`,
57+
setup: async () => {
58+
profileEnv = setEnvVar("QUARTO_PROFILE", profile);
59+
},
60+
teardown: async () => {
61+
restoreEnvVar("QUARTO_PROFILE", profileEnv);
62+
}
63+
}
64+
testSite(input, renderTarget, includeSelectors, excludeSelectors, additionalContext, ...verify);
65+
};
66+
}

0 commit comments

Comments
 (0)