Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/render/render-r.test.ts
12925 views
1
/*
2
* render-r.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
8
import { docs, fileLoader, inTempDirectory } from "../../utils.ts";
9
import { join } from "../../../src/deno_ral/path.ts";
10
import { ensureHtmlElements, ensureHtmlSelectorSatisfies, fileExists } from "../../verify.ts";
11
import { testRender } from "./render.ts";
12
13
inTempDirectory((dir) => {
14
const tempInput = join(dir, "test.Rmd");
15
Deno.copyFileSync(docs("test.Rmd"), tempInput);
16
const thisPlotPath = join(dir, "test_files/figure-html");
17
18
testRender(tempInput, "html", false, [
19
fileExists(thisPlotPath),
20
], {
21
teardown: () => {
22
return Deno.remove(dir, { recursive: true });
23
},
24
});
25
});
26
27
inTempDirectory((dir) => {
28
const tempInput = join(dir, "test.Rmd");
29
Deno.copyFileSync(docs("test.Rmd"), tempInput);
30
31
const thisPlotPath = join(dir, "test_files/figure-html");
32
testRender(tempInput, "html", false, [
33
fileExists(thisPlotPath),
34
], {
35
teardown: () => {
36
return Deno.remove(dir, { recursive: true });
37
},
38
}, ["--execute-params", "docs/params.yml"]);
39
});
40
41
const knitrOptions = fileLoader()("test-knitr-options.qmd", "html");
42
testRender(knitrOptions.input, "html", false, [
43
ensureHtmlSelectorSatisfies(
44
knitrOptions.output.outputPath,
45
"#comment-empty code",
46
(nodeList) => {
47
return /\n\[1\] 3/.test(nodeList[0].textContent);
48
},
49
),
50
ensureHtmlSelectorSatisfies(
51
knitrOptions.output.outputPath,
52
"#comment-change code",
53
(nodeList) => {
54
return /\n\$ \[1\] 3/.test(nodeList[0].textContent);
55
},
56
),
57
ensureHtmlSelectorSatisfies(
58
knitrOptions.output.outputPath,
59
"#prompt code.sourceCode",
60
(nodeList) => {
61
return Array.from(nodeList).every((e) => /^>/.test(e.textContent));
62
},
63
),
64
ensureHtmlSelectorSatisfies(
65
knitrOptions.output.outputPath,
66
"#no-prompt code.sourceCode",
67
(nodeList) => {
68
return Array.from(nodeList).every((e) => /^[^>]/.test(e.textContent));
69
},
70
),
71
]);
72
73
const sqlEngine = fileLoader()("test-knitr-sql.qmd", "html");
74
testRender(sqlEngine.input, "html", false);
75
76
77
const toSpin = fileLoader()("knitr-spin.R", "html");
78
testRender(toSpin.input, "html", false, [
79
ensureHtmlElements(
80
toSpin.output.outputPath, ["#block img"]
81
),
82
ensureHtmlSelectorSatisfies(
83
toSpin.output.outputPath,
84
"#inline code",
85
(nodeList) => {
86
return /^3\.14+/.test(nodeList[0].textContent);
87
},
88
),
89
]);
90