55 */
66import { existsSync } from "../../../src/deno_ral/fs.ts" ;
77import { 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" ;
1010import { ensureHtmlElements , noErrorsOrWarnings } from "../../verify.ts" ;
1111
1212export 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