Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/project/project-book.test.ts
12921 views
1
/*
2
* project-render.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
import { existsSync } from "../../../src/deno_ral/fs.ts";
7
import { join } from "../../../src/deno_ral/path.ts";
8
import { Metadata } from "../../../src/config/types.ts";
9
10
import { testQuartoCmd, Verify } from "../../test.ts";
11
import { docs } from "../../utils.ts";
12
import {
13
directoryEmptyButFor,
14
fileExists,
15
verifyYamlFile,
16
} from "../../verify.ts";
17
18
import {
19
cleanWorking,
20
kProjectWorkingDir,
21
kQuartoProjectFile,
22
} from "./common.ts";
23
24
// A book project
25
testQuartoCmd(
26
"create-project",
27
[kProjectWorkingDir, "--type", "book"],
28
[
29
fileExists(kQuartoProjectFile),
30
fileExists(join(kProjectWorkingDir, "index.qmd")),
31
fileExists(join(kProjectWorkingDir, "references.bib")),
32
verifyYamlFile(
33
kQuartoProjectFile,
34
(yaml: unknown) => {
35
// Make sure there is a project yaml section
36
const metadata = yaml as Metadata;
37
if (
38
metadata["project"] !== undefined && metadata["book"] !== undefined
39
) {
40
const type = (metadata["project"] as Metadata)["type"];
41
return type === "book";
42
} else {
43
return false;
44
}
45
},
46
),
47
],
48
{
49
setup: cleanWorking,
50
teardown: cleanWorking,
51
},
52
);
53
54
// Book render
55
const outDir = "_book";
56
const bookProjDir = docs("project/book");
57
const bookOutDir = join(bookProjDir, outDir);
58
59
const bookPdfDir = bookOutDir;
60
const verifyPdfBook: Verify[] = [
61
fileExists(join(bookPdfDir, "book.pdf")),
62
directoryEmptyButFor(bookPdfDir, ["book.pdf"]),
63
];
64
testQuartoCmd(
65
"render",
66
[bookProjDir, "--to", "pdf"],
67
verifyPdfBook,
68
{
69
teardown: async () => {
70
if (existsSync(bookOutDir)) {
71
await Deno.remove(bookOutDir, { recursive: true });
72
}
73
},
74
},
75
);
76
77
const bookDocxDir = bookOutDir;
78
const verifyDocxBook: Verify[] = [
79
fileExists(join(bookDocxDir, "book.docx")),
80
directoryEmptyButFor(bookDocxDir, ["book.docx"]),
81
];
82
testQuartoCmd(
83
"render",
84
[bookProjDir, "--to", "docx"],
85
verifyDocxBook,
86
{
87
teardown: async () => {
88
if (existsSync(bookOutDir)) {
89
await Deno.remove(bookOutDir, { recursive: true });
90
}
91
},
92
},
93
);
94
95
const bookEpubDir = bookOutDir;
96
const verifyEpubBook: Verify[] = [
97
fileExists(join(bookEpubDir, "book.epub")),
98
directoryEmptyButFor(bookEpubDir, ["book.epub"]),
99
];
100
testQuartoCmd(
101
"render",
102
[bookProjDir, "--to", "epub"],
103
verifyEpubBook,
104
{
105
teardown: async () => {
106
if (existsSync(bookOutDir)) {
107
await Deno.remove(bookOutDir, { recursive: true });
108
}
109
},
110
},
111
);
112
113
const verifyHtmlBook: Verify[] = [
114
"index.html",
115
"intro.html",
116
"references.html",
117
"search.json",
118
"site_libs",
119
"summary.html",
120
].map((path) => {
121
return fileExists(join(bookOutDir, path));
122
});
123
testQuartoCmd(
124
"render",
125
[bookProjDir, "--to", "html"],
126
verifyHtmlBook,
127
{
128
teardown: async () => {
129
if (existsSync(bookOutDir)) {
130
await Deno.remove(bookOutDir, { recursive: true });
131
}
132
},
133
},
134
);
135
136