@@ -12,58 +12,42 @@ import { assertEquals } from "testing/asserts";
1212import { join } from "../../src/deno_ral/path.ts" ;
1313import { normalizePath } from "../../src/core/path.ts" ;
1414import { previewInitialPath } from "../../src/command/preview/preview.ts" ;
15- import { ProjectContext } from "../../src/project/types.ts" ;
16-
17- function mockProjectContext (
18- dir : string ,
19- isSingleFile : boolean ,
20- ) : ProjectContext {
21- return {
22- dir : normalizePath ( dir ) ,
23- isSingleFile,
24- engines : [ ] ,
25- files : { input : [ ] , resources : [ ] , config : [ ] , configResources : [ ] } ,
26- config : { project : { } } ,
27- notebookContext : ( ) => ( { resolve : ( ) => undefined , get : ( ) => undefined } ) ,
28- resolveFullMarkdownForFile : ( ) => Promise . resolve ( undefined ) ,
29- cleanup : ( ) => { } ,
30- } as unknown as ProjectContext ;
31- }
15+ import { createMockProjectContext } from "./project/utils.ts" ;
3216
3317// deno-lint-ignore require-await
3418unitTest ( "previewInitialPath - single file returns empty path (#14298)" , async ( ) => {
3519 const dir = normalizePath ( Deno . makeTempDirSync ( { prefix : "quarto-test" } ) ) ;
3620 const outputFile = join ( dir , "hello.html" ) ;
37- const project = mockProjectContext ( dir , true ) ;
21+ const project = createMockProjectContext ( { dir, isSingleFile : true } ) ;
3822
3923 const result = previewInitialPath ( outputFile , project ) ;
4024 assertEquals ( result , "" , "Single-file preview should use root path, not filename" ) ;
4125
42- Deno . removeSync ( dir , { recursive : true } ) ;
26+ project . cleanup ( ) ;
4327} ) ;
4428
4529// deno-lint-ignore require-await
4630unitTest ( "previewInitialPath - project file returns relative path" , async ( ) => {
4731 const dir = normalizePath ( Deno . makeTempDirSync ( { prefix : "quarto-test" } ) ) ;
4832 const outputFile = join ( dir , "chapter.html" ) ;
49- const project = mockProjectContext ( dir , false ) ;
33+ const project = createMockProjectContext ( { dir } ) ;
5034
5135 const result = previewInitialPath ( outputFile , project ) ;
5236 assertEquals ( result , "chapter.html" , "Project preview should include relative path" ) ;
5337
54- Deno . removeSync ( dir , { recursive : true } ) ;
38+ project . cleanup ( ) ;
5539} ) ;
5640
5741// deno-lint-ignore require-await
5842unitTest ( "previewInitialPath - project subdir returns relative path" , async ( ) => {
5943 const dir = normalizePath ( Deno . makeTempDirSync ( { prefix : "quarto-test" } ) ) ;
6044 const outputFile = join ( dir , "pages" , "about.html" ) ;
61- const project = mockProjectContext ( dir , false ) ;
45+ const project = createMockProjectContext ( { dir } ) ;
6246
6347 const result = previewInitialPath ( outputFile , project ) ;
6448 assertEquals ( result , "pages/about.html" , "Project preview should include subdirectory path" ) ;
6549
66- Deno . removeSync ( dir , { recursive : true } ) ;
50+ project . cleanup ( ) ;
6751} ) ;
6852
6953// deno-lint-ignore require-await
0 commit comments