Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/render/render-pdf-svg-conversion.test.ts
12921 views
1
/*
2
* render-pdf-svg-conversion.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
8
import { which } from "../../../src/core/path.ts";
9
import { docs, outputForInput } from "../../utils.ts";
10
import { ensureFileRegexMatches, ensureLatexFileRegexMatches, printsMessage } from "../../verify.ts";
11
12
import { testRender } from "./render.ts";
13
14
// Check for rsvg-convert availability (static for this test run)
15
const hasRsvgConvert = await which("rsvg-convert") !== undefined;
16
17
// Test 1: SVG to PDF with rsvg-convert available
18
// Only runs if rsvg-convert is on PATH
19
// Verifies that SVG is converted to PDF (not kept as SVG)Skipping SVG conversion for " .. path .. " because output file already exists:
20
const test1Input = docs("svg-conversion/with-rsvg/index.qmd");
21
const test1Output = outputForInput(test1Input, "pdf");
22
testRender(test1Input, "pdf", false, [
23
ensureLatexFileRegexMatches(
24
test1Output.outputPath,
25
[
26
/\\includegraphics(\[.*?\])?\{[^}]*simple-svg\.pdf[^}]*\}/, // Converted PDF included
27
],
28
[
29
/\\includesvg/, // Should NOT use includesvg (SVG was converted)
30
],
31
),
32
], {
33
ignore: !hasRsvgConvert,
34
});
35
36
// Test 2: SVG to PDF without rsvg-convert, with pre-converted PDF
37
// Should use existing PDF without warnings
38
const test2Input = docs("svg-conversion/with-rsvg-with-pdf/index.qmd");
39
const test2Output = outputForInput(test2Input, "pdf");
40
testRender(test2Input, "pdf", false, [
41
ensureLatexFileRegexMatches(
42
test2Output.outputPath,
43
[
44
/\\includegraphics(\[.*?\])?\{[^}]*simple-svg\.pdf[^}]*\}/, // Existing PDF included
45
],
46
[
47
/\\includesvg/, // Should NOT use includesvg (PDF was provided)
48
],
49
),
50
printsMessage({
51
level: "INFO",
52
regex: "Skipping SVG conversion .* because output file already exists"
53
}),
54
]);
55
56
// Test 3: SVG without rsvg-convert and no pre-converted PDF
57
// Uses format: latex (not pdf) to generate .tex without compiling
58
// Avoids LaTeX/Inkscape dependencies that would cause test to fail
59
const test3Input = docs("svg-conversion/without-rsvg-no-pdf.qmd");
60
const test3Output = outputForInput(test3Input, "latex");
61
testRender(test3Input, "latex", true, [
62
printsMessage({
63
level: "INFO",
64
regex: "Skipping SVG conversion.*required PDF file does not exist"
65
}),
66
ensureFileRegexMatches(
67
test3Output.outputPath,
68
[
69
/\\usepackage(\[.*?\])?\{svg\}/, // SVG package loaded
70
/\\includesvg(\[.*?\])?\{[^}]*test-no-pdf[^}]*\}/, // includesvg command for our SVG
71
],
72
),
73
]);
74
75