Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/embed/render-embed.test.ts
12926 views
1
/*
2
* render-embed.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
import { dirname, extname, join } from "../../../src/deno_ral/path.ts";
8
import { docs, outputForInput } from "../../utils.ts";
9
import {
10
ensureFileRegexMatches,
11
ensureHtmlElements,
12
fileExists,
13
noErrorsOrWarnings,
14
} from "../../verify.ts";
15
import { testRender } from "../render/render.ts";
16
17
const format = "html";
18
const input = docs("embed/embed-qmd.qmd");
19
const output = outputForInput(input, format);
20
21
// Test qmd embedding
22
// The notebook preview that is generated
23
const nbOutput = join(dirname(output.outputPath), "notebook.embed-preview.html");
24
const nbSupporting = join(dirname(nbOutput), "notebook.embed_files");
25
26
testRender(input, format, false, [
27
noErrorsOrWarnings,
28
// Make sure that the preview is generated as expected
29
fileExists(nbOutput),
30
fileExists(nbSupporting),
31
ensureHtmlElements(output.outputPath, [
32
// Make sure the embeds produce expected output
33
"#fig-mtcars",
34
// Make sure notebook links are present
35
"a.quarto-notebook-link",
36
".quarto-alternate-notebooks a",
37
]),
38
// Ensure the captions look good
39
ensureFileRegexMatches(output.outputPath, [
40
/Figure.*1:/,
41
]),
42
], {
43
teardown: () => {
44
// clean up the notebook that is referenced by `embed-qmd-qmd`
45
Deno.removeSync(nbOutput);
46
Deno.removeSync(nbSupporting, { recursive: true });
47
48
return Promise.resolve();
49
},
50
});
51
52
// Test ipynb emebedding
53
// The notebook preview that is generated
54
const ipynbInput = docs("embed/embed-ipynb.qmd");
55
const ipynbOutput = outputForInput(ipynbInput, format);
56
57
const ipynbPreviewNb = join(
58
dirname(ipynbOutput.outputPath),
59
"penguins-preview.html",
60
);
61
const ipynbPreviewSupporting = join(
62
dirname(ipynbOutput.outputPath),
63
"penguins_files",
64
);
65
66
const ipynbPreviewRendered = join(
67
dirname(ipynbOutput.outputPath),
68
"penguins.out.ipynb",
69
);
70
71
testRender(ipynbInput, format, false, [
72
noErrorsOrWarnings,
73
// Make sure that the preview is generated as expected
74
fileExists(ipynbPreviewNb),
75
fileExists(ipynbPreviewSupporting),
76
fileExists(ipynbPreviewRendered),
77
ensureHtmlElements(ipynbOutput.outputPath, [
78
// Make sure the embeds produce expected output
79
"#fig-bill-scatter",
80
`[data-tags='["bill-ratio"]']`,
81
"#fig-bill-marginal",
82
"#fig-bill-marginal-1",
83
"#fig-bill-marginal-2",
84
"#cell-species-counts",
85
"#cell-species-counts .sourceCode",
86
// Make sure notebook links are present
87
"a.quarto-notebook-link",
88
".quarto-alternate-notebooks a",
89
]),
90
// Ensure the captions look good
91
ensureFileRegexMatches(ipynbOutput.outputPath, [
92
/Figure.*1:/,
93
/Figure.*2:/,
94
]),
95
], {
96
teardown: () => {
97
// clean up the notebook that is referenced by `embed-qmd-qmd`
98
Deno.removeSync(ipynbPreviewNb);
99
Deno.removeSync(ipynbPreviewSupporting, { recursive: true });
100
Deno.removeSync(ipynbPreviewRendered);
101
102
return Promise.resolve();
103
},
104
});
105
106
// Test different echo settings (bug 8472)
107
const docInput = docs("embed/qmd-embed/index.qmd");
108
const docOutput = outputForInput(docInput, "html");
109
testRender(docInput, "html", false, [
110
noErrorsOrWarnings,
111
ensureHtmlElements(docOutput.outputPath, [
112
// Make sure the embeds produce expected output
113
"#fig-polar",
114
"#fig-index-plot",
115
// Make sure notebook links are present
116
"a.quarto-notebook-link",
117
".quarto-alternate-notebooks a",
118
]),
119
// Ensure the captions look good
120
ensureFileRegexMatches(docOutput.outputPath, [
121
/Figure.*1:/,
122
/Figure.*2:/,
123
]),
124
], {
125
teardown: () => {
126
// Only qmds should be left in this directory
127
const dir = join(Deno.cwd(), dirname(docInput));
128
129
const cleanup = ["notebook.embed_files", "notebook.embed-preview.html", "notebook2.embed_files", "notebook2.embed-preview.html"];
130
cleanup.forEach((path) => {
131
Deno.removeSync(join(dir, path), {recursive: true});
132
})
133
return Promise.resolve();
134
},
135
});
136
137
138