Path: blob/main/tests/smoke/render/render-pdf-svg-conversion.test.ts
12925 views
/*1* render-pdf-svg-conversion.test.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*5*/67import { which } from "../../../src/core/path.ts";8import { docs, outputForInput } from "../../utils.ts";9import { ensureFileRegexMatches, ensureLatexFileRegexMatches, printsMessage } from "../../verify.ts";1011import { testRender } from "./render.ts";1213// Check for rsvg-convert availability (static for this test run)14const hasRsvgConvert = await which("rsvg-convert") !== undefined;1516// Test 1: SVG to PDF with rsvg-convert available17// Only runs if rsvg-convert is on PATH18// Verifies that SVG is converted to PDF (not kept as SVG)Skipping SVG conversion for " .. path .. " because output file already exists:19const test1Input = docs("svg-conversion/with-rsvg/index.qmd");20const test1Output = outputForInput(test1Input, "pdf");21testRender(test1Input, "pdf", false, [22ensureLatexFileRegexMatches(23test1Output.outputPath,24[25/\\includegraphics(\[.*?\])?\{[^}]*simple-svg\.pdf[^}]*\}/, // Converted PDF included26],27[28/\\includesvg/, // Should NOT use includesvg (SVG was converted)29],30),31], {32ignore: !hasRsvgConvert,33});3435// Test 2: SVG to PDF without rsvg-convert, with pre-converted PDF36// Should use existing PDF without warnings37const test2Input = docs("svg-conversion/with-rsvg-with-pdf/index.qmd");38const test2Output = outputForInput(test2Input, "pdf");39testRender(test2Input, "pdf", false, [40ensureLatexFileRegexMatches(41test2Output.outputPath,42[43/\\includegraphics(\[.*?\])?\{[^}]*simple-svg\.pdf[^}]*\}/, // Existing PDF included44],45[46/\\includesvg/, // Should NOT use includesvg (PDF was provided)47],48),49printsMessage({50level: "INFO",51regex: "Skipping SVG conversion .* because output file already exists"52}),53]);5455// Test 3: SVG without rsvg-convert and no pre-converted PDF56// Uses format: latex (not pdf) to generate .tex without compiling57// Avoids LaTeX/Inkscape dependencies that would cause test to fail58const test3Input = docs("svg-conversion/without-rsvg-no-pdf.qmd");59const test3Output = outputForInput(test3Input, "latex");60testRender(test3Input, "latex", true, [61printsMessage({62level: "INFO",63regex: "Skipping SVG conversion.*required PDF file does not exist"64}),65ensureFileRegexMatches(66test3Output.outputPath,67[68/\\usepackage(\[.*?\])?\{svg\}/, // SVG package loaded69/\\includesvg(\[.*?\])?\{[^}]*test-no-pdf[^}]*\}/, // includesvg command for our SVG70],71),72]);737475