33 *
44 * Copyright (C) 2023 Posit Software, PBC
55 */
6+ import { dirname , join } from "path" ;
67import { quarto } from "../../../src/quarto.ts" ;
78import { test } from "../../test.ts" ;
8- import { assertEquals } from "testing/asserts" ;
9+ import { docs } from "../../utils.ts" ;
10+ import { folderExists , printsMessage } from "../../verify.ts" ;
11+ import { fileLoader } from "../../utils.ts" ;
12+ import { safeExistsSync , safeRemoveSync } from "../../../src/core/path.ts" ;
13+
14+ const testInput = fileLoader ( "jupyter" , "cache" ) ( "test.qmd" , "html" )
15+ const cacheFolder = join ( dirname ( testInput . input ) , ".jupyter_cache" )
916
1017test ( {
11- name : "jupyter:cache:test-1" ,
12- context : { } ,
18+ name : "Jupyter cache is working" ,
1319 execute : async ( ) => {
1420 // return await new Promise((_resolve, reject) => {
1521 // setTimeout(reject, 10000, "timed out after 10 seconds");
1622 // })
1723 // https://github.com/quarto-dev/quarto-cli/issues/9618
1824 // repeated executions to trigger jupyter cache
19- await quarto ( [ "render" , "docs/jupyter/cache/test.qmd" , "--no-execute-daemon" ] ) ;
20- await quarto ( [ "render" , "docs/jupyter/cache/test.qmd" , "--no-execute-daemon" ] ) ;
25+ await quarto ( [ "render" , testInput . input , "--to" , "html" , "--no-execute-daemon" ] ) ;
26+ await quarto ( [ "render" , testInput . input , "--to" , "html" , "--no-execute-daemon" ] ) ;
27+ } ,
28+ context : {
29+ teardown : async ( ) => {
30+ if ( safeExistsSync ( cacheFolder ) ) {
31+ safeRemoveSync ( cacheFolder , { recursive : true } ) ;
32+ }
33+ if ( safeExistsSync ( testInput . output . outputPath ) ) {
34+ safeRemoveSync ( testInput . output . outputPath ) ;
35+ }
36+ if ( safeExistsSync ( testInput . output . supportPath ) ) {
37+ safeRemoveSync ( testInput . output . supportPath , { recursive : true } ) ;
38+ }
39+ }
2140 } ,
22- verify : [ ] ,
41+ verify : [
42+ folderExists ( cacheFolder ) ,
43+ // this will check only for the second render that should be read from cache
44+ printsMessage ( "INFO" , / N o t e b o o k r e a d f r o m c a c h e / )
45+ ] ,
2346 type : "smoke" ,
2447} ) ;
48+
49+ // -- Testing changing cache folder
50+
51+ const testInput2 = fileLoader ( "jupyter" , "cache-non-default" ) ( "test.qmd" , "html" )
52+ // From value of cache set in _environment in test quarto project
53+ const cacheFolder2 = join ( dirname ( testInput2 . input ) , ".cache/jupyter-cache" )
54+
55+ test ( {
56+ name : "Jupyter cache folder can be change" ,
57+ execute : async ( ) => {
58+ // return await new Promise((_resolve, reject) => {
59+ // setTimeout(reject, 10000, "timed out after 10 seconds");
60+ // })
61+ // https://github.com/quarto-dev/quarto-cli/issues/9618
62+ // repeated executions to trigger jupyter cache
63+ await quarto ( [ "render" , testInput2 . input , "--to" , "html" , "--no-execute-daemon" ] ) ;
64+ await quarto ( [ "render" , testInput2 . input , "--to" , "html" , "--no-execute-daemon" ] ) ;
65+ } ,
66+ context : {
67+ teardown : async ( ) => {
68+ if ( safeExistsSync ( cacheFolder2 ) ) {
69+ safeRemoveSync ( cacheFolder2 , { recursive : true } ) ;
70+ }
71+ if ( safeExistsSync ( testInput2 . output . outputPath ) ) {
72+ safeRemoveSync ( testInput2 . output . outputPath ) ;
73+ }
74+ if ( safeExistsSync ( testInput2 . output . supportPath ) ) {
75+ safeRemoveSync ( testInput2 . output . supportPath , { recursive : true } ) ;
76+ }
77+ if ( safeExistsSync ( join ( dirname ( testInput2 . input ) , ".quarto" ) ) ) {
78+ safeRemoveSync ( join ( dirname ( testInput2 . input ) , ".quarto" ) , { recursive : true } ) ;
79+ }
80+ }
81+ } ,
82+ verify : [
83+ folderExists ( cacheFolder2 ) ,
84+ // this will check only for the second render that should be read from cache
85+ printsMessage ( "INFO" , / N o t e b o o k r e a d f r o m c a c h e / )
86+ ] ,
87+ type : "smoke" ,
88+ } ) ;
0 commit comments