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