Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/project/project-prepost.test.ts
12925 views
1
/*
2
* project-prepost.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
import { docs } from "../../utils.ts";
8
9
import { join } from "../../../src/deno_ral/path.ts";
10
import { existsSync } from "../../../src/deno_ral/fs.ts";
11
import { testQuartoCmd } from "../../test.ts";
12
import { fileExists, noErrors, printsMessage, validJsonWithFields, verifyNoPath, verifyPath } from "../../verify.ts";
13
import { normalizePath, safeRemoveIfExists } from "../../../src/core/path.ts";
14
15
const renderDir = docs("project/prepost/mutate-render-list");
16
const dir = join(Deno.cwd(), renderDir);
17
const outDir = join(dir, "_site");
18
19
const sidebarContents = ["sidebar/test1.html", "sidebar/test2.html"]
20
const sidebarContentsExists = sidebarContents.map((path) => {
21
return fileExists(join(outDir, path))
22
});
23
24
testQuartoCmd(
25
"render",
26
[renderDir],
27
[noErrors, ...sidebarContentsExists],
28
{
29
teardown: async () => {
30
if (existsSync(outDir)) {
31
await Deno.remove(outDir, { recursive: true });
32
}
33
},
34
},
35
);
36
37
38
39
// Tests that if the pre-render script mutates the output directory
40
// we throw an error that complains about this.
41
const mutateRenderDir = docs("project/prepost/invalid-mutate");
42
const mutateRenderDirAbs = join(Deno.cwd(), mutateRenderDir);
43
const mutateRenderOutDir = join(mutateRenderDirAbs, "_site");
44
45
testQuartoCmd(
46
"render",
47
[mutateRenderDir],
48
[printsMessage({level: "ERROR", regex: /output-dir may not be mutated/gm})],
49
{
50
teardown: async () => {
51
const mdClean = join(mutateRenderDirAbs, "_metadata.yml");
52
console.log({mdClean});
53
if (existsSync(mdClean)) {
54
await Deno.remove(mdClean);
55
}
56
if (existsSync(mutateRenderOutDir)) {
57
await Deno.remove(mutateRenderOutDir, { recursive: true });
58
}
59
},
60
},
61
);
62
63
testQuartoCmd(
64
"render",
65
[docs("project/prepost/extension")],
66
[{
67
name: "i-exist.txt exists",
68
verify: async () => {
69
const path = join(docs("project/prepost/extension"), "i-exist.txt");
70
verifyNoPath(path);
71
}
72
}],
73
{
74
teardown: async () => {
75
const path = join(docs("project/prepost/extension"), "i-was-created.txt");
76
verifyPath(path);
77
safeRemoveIfExists(path);
78
const siteDir = join(docs("project/prepost/extension"), "_site");
79
if (existsSync(siteDir)) {
80
await Deno.remove(siteDir, { recursive: true });
81
}
82
}
83
});
84
85
testQuartoCmd(
86
"render",
87
[docs("project/prepost/issue-10828")],
88
[],
89
{
90
env: {
91
"QUARTO_USE_FILE_FOR_PROJECT_INPUT_FILES": normalizePath(docs("project/prepost/issue-10828/input-files.txt")),
92
"QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES": normalizePath(docs("project/prepost/issue-10828/output-files.txt"))
93
},
94
teardown: async () => {
95
const inputPath = normalizePath(docs("project/prepost/issue-10828/input-files.txt"));
96
const outputPath = normalizePath(docs("project/prepost/issue-10828/output-files.txt"));
97
verifyPath(inputPath);
98
safeRemoveIfExists(inputPath);
99
verifyPath(outputPath);
100
safeRemoveIfExists(outputPath);
101
const siteDir = join(docs("project/prepost/issue-10828"), "_site");
102
if (existsSync(siteDir)) {
103
await Deno.remove(siteDir, { recursive: true });
104
}
105
}
106
}
107
)
108
109
// Verify that pre-render scripts receive QUARTO_PROJECT_SCRIPT_PROGRESS
110
// and QUARTO_PROJECT_SCRIPT_QUIET environment variables
111
const scriptEnvDir = docs("project/prepost/script-env-vars");
112
const scriptEnvDirAbs = join(Deno.cwd(), scriptEnvDir);
113
const envDumpPath = join(scriptEnvDirAbs, "env-dump.json");
114
const scriptEnvOutDir = join(scriptEnvDirAbs, "_site");
115
116
testQuartoCmd(
117
"render",
118
[scriptEnvDir],
119
[
120
noErrors,
121
validJsonWithFields(envDumpPath, {
122
progress: "1",
123
quiet: "0",
124
}),
125
],
126
{
127
teardown: async () => {
128
safeRemoveIfExists(envDumpPath);
129
if (existsSync(scriptEnvOutDir)) {
130
await Deno.remove(scriptEnvOutDir, { recursive: true });
131
}
132
},
133
},
134
);
135
136