-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathproject-website.test.ts
More file actions
124 lines (114 loc) · 3.09 KB
/
project-website.test.ts
File metadata and controls
124 lines (114 loc) · 3.09 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
/*
* project-website.test.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
*/
import { existsSync } from "../../../src/deno_ral/fs.ts";
import { join } from "../../../src/deno_ral/path.ts";
import { Metadata } from "../../../src/config/types.ts";
import { ExecuteOutput, testQuartoCmd, Verify } from "../../test.ts";
import { docs } from "../../utils.ts";
import {
directoryEmptyButFor,
fileExists,
verifyYamlFile,
} from "../../verify.ts";
import {
cleanWorking,
kProjectWorkingDir,
kQuartoProjectFile,
} from "./common.ts";
import { assert } from "testing/asserts";
// A website project
testQuartoCmd(
"create-project",
[kProjectWorkingDir, "--type", "website"],
[
fileExists(kQuartoProjectFile),
fileExists(join(kProjectWorkingDir, "index.qmd")),
verifyYamlFile(
kQuartoProjectFile,
(yaml: unknown) => {
// Make sure there is a project yaml section
const metadata = yaml as Metadata;
if (
metadata["project"] !== undefined && metadata["website"] !== undefined
) {
const type = (metadata["project"] as Metadata)["type"];
return type === "website";
} else {
return false;
}
},
),
],
{
setup: cleanWorking,
teardown: cleanWorking,
},
);
// Site render
const websiteOutputFiles: string[] = [
"index.html",
"about.html",
"search.json",
"styles.css",
"site_libs",
];
const outDir = "_site";
const siteProjDir = docs("project/site");
const siteOutDir = join(siteProjDir, outDir);
const verifySiteFiles = websiteOutputFiles.map((file) => {
return fileExists(join(siteOutDir, file));
});
const verifyPdfBook: Verify[] = [
...verifySiteFiles,
directoryEmptyButFor(siteOutDir, websiteOutputFiles),
];
testQuartoCmd(
"render",
[siteProjDir],
verifyPdfBook,
{
teardown: async () => {
if (existsSync(siteOutDir)) {
await Deno.remove(siteOutDir, { recursive: true });
}
},
},
);
const mergeNavbarCrumbsConfigSite = docs(
"websites/search/merge-navbar-crumbs-configuration",
);
const mergeNavbarCrumbsConfigSiteOutDir = join(mergeNavbarCrumbsConfigSite, outDir);
testQuartoCmd(
"render",
[mergeNavbarCrumbsConfigSite],
[
{
name: "verify-no-navbar-crumbs-in-searchjson",
verify: async (outputs: ExecuteOutput[]) => {
// Verify that the search.json file does not contain any navbar breadcrumbs
const searchJson = join(mergeNavbarCrumbsConfigSite, "_site", "search.json");
const searchJsonExists = existsSync(searchJson);
if (!searchJsonExists) {
throw new Error(`File ${searchJson} does not exist`);
}
const searchJsonContent = await Deno.readTextFile(searchJson);
const json = JSON.parse(searchJsonContent);
for (const entry of json) {
if (entry.crumbs) {
assert(entry.crumbs[0] !== "Home");
}
}
},
},
],
{
teardown: async () => {
if (existsSync(mergeNavbarCrumbsConfigSiteOutDir)) {
await Deno.remove(mergeNavbarCrumbsConfigSiteOutDir, { recursive: true });
}
},
},
);