Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/unit/project/utils.ts
6451 views
1
/*
2
* utils.ts
3
*
4
* Test utilities for project-related unit tests
5
*
6
* Copyright (C) 2026 Posit Software, PBC
7
*/
8
9
import { ProjectContext } from "../../../src/project/types.ts";
10
import { FileInformationCacheMap } from "../../../src/project/project-shared.ts";
11
12
/**
13
* Create a minimal mock ProjectContext for testing.
14
* Only provides the essential properties needed for cache-related tests.
15
*
16
* @param dir - The project directory (defaults to a temp directory)
17
* @returns A mock ProjectContext suitable for unit testing
18
*/
19
export function createMockProjectContext(
20
dir?: string,
21
): ProjectContext {
22
const projectDir = dir ?? Deno.makeTempDirSync({ prefix: "quarto-test" });
23
const ownsDir = dir === undefined;
24
25
return {
26
dir: projectDir,
27
engines: [],
28
files: { input: [] },
29
notebookContext: {} as ProjectContext["notebookContext"],
30
fileInformationCache: new FileInformationCacheMap(),
31
resolveBrand: () => Promise.resolve(undefined),
32
resolveFullMarkdownForFile: () => Promise.resolve({} as never),
33
fileExecutionEngineAndTarget: () => Promise.resolve({} as never),
34
fileMetadata: () => Promise.resolve({}),
35
environment: () => Promise.resolve({} as never),
36
renderFormats: () => Promise.resolve({}),
37
clone: function () {
38
return this;
39
},
40
isSingleFile: false,
41
diskCache: {} as ProjectContext["diskCache"],
42
temp: {} as ProjectContext["temp"],
43
cleanup: () => {
44
if (ownsDir) {
45
try {
46
Deno.removeSync(projectDir, { recursive: true });
47
} catch {
48
// Ignore cleanup errors in tests
49
}
50
}
51
},
52
} as ProjectContext;
53
}
54
55