Path: blob/main/tests/smoke/embed/render-embed.test.ts
12926 views
/*1* render-embed.test.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*5*/6import { dirname, extname, join } from "../../../src/deno_ral/path.ts";7import { docs, outputForInput } from "../../utils.ts";8import {9ensureFileRegexMatches,10ensureHtmlElements,11fileExists,12noErrorsOrWarnings,13} from "../../verify.ts";14import { testRender } from "../render/render.ts";1516const format = "html";17const input = docs("embed/embed-qmd.qmd");18const output = outputForInput(input, format);1920// Test qmd embedding21// The notebook preview that is generated22const nbOutput = join(dirname(output.outputPath), "notebook.embed-preview.html");23const nbSupporting = join(dirname(nbOutput), "notebook.embed_files");2425testRender(input, format, false, [26noErrorsOrWarnings,27// Make sure that the preview is generated as expected28fileExists(nbOutput),29fileExists(nbSupporting),30ensureHtmlElements(output.outputPath, [31// Make sure the embeds produce expected output32"#fig-mtcars",33// Make sure notebook links are present34"a.quarto-notebook-link",35".quarto-alternate-notebooks a",36]),37// Ensure the captions look good38ensureFileRegexMatches(output.outputPath, [39/Figure.*1:/,40]),41], {42teardown: () => {43// clean up the notebook that is referenced by `embed-qmd-qmd`44Deno.removeSync(nbOutput);45Deno.removeSync(nbSupporting, { recursive: true });4647return Promise.resolve();48},49});5051// Test ipynb emebedding52// The notebook preview that is generated53const ipynbInput = docs("embed/embed-ipynb.qmd");54const ipynbOutput = outputForInput(ipynbInput, format);5556const ipynbPreviewNb = join(57dirname(ipynbOutput.outputPath),58"penguins-preview.html",59);60const ipynbPreviewSupporting = join(61dirname(ipynbOutput.outputPath),62"penguins_files",63);6465const ipynbPreviewRendered = join(66dirname(ipynbOutput.outputPath),67"penguins.out.ipynb",68);6970testRender(ipynbInput, format, false, [71noErrorsOrWarnings,72// Make sure that the preview is generated as expected73fileExists(ipynbPreviewNb),74fileExists(ipynbPreviewSupporting),75fileExists(ipynbPreviewRendered),76ensureHtmlElements(ipynbOutput.outputPath, [77// Make sure the embeds produce expected output78"#fig-bill-scatter",79`[data-tags='["bill-ratio"]']`,80"#fig-bill-marginal",81"#fig-bill-marginal-1",82"#fig-bill-marginal-2",83"#cell-species-counts",84"#cell-species-counts .sourceCode",85// Make sure notebook links are present86"a.quarto-notebook-link",87".quarto-alternate-notebooks a",88]),89// Ensure the captions look good90ensureFileRegexMatches(ipynbOutput.outputPath, [91/Figure.*1:/,92/Figure.*2:/,93]),94], {95teardown: () => {96// clean up the notebook that is referenced by `embed-qmd-qmd`97Deno.removeSync(ipynbPreviewNb);98Deno.removeSync(ipynbPreviewSupporting, { recursive: true });99Deno.removeSync(ipynbPreviewRendered);100101return Promise.resolve();102},103});104105// Test different echo settings (bug 8472)106const docInput = docs("embed/qmd-embed/index.qmd");107const docOutput = outputForInput(docInput, "html");108testRender(docInput, "html", false, [109noErrorsOrWarnings,110ensureHtmlElements(docOutput.outputPath, [111// Make sure the embeds produce expected output112"#fig-polar",113"#fig-index-plot",114// Make sure notebook links are present115"a.quarto-notebook-link",116".quarto-alternate-notebooks a",117]),118// Ensure the captions look good119ensureFileRegexMatches(docOutput.outputPath, [120/Figure.*1:/,121/Figure.*2:/,122]),123], {124teardown: () => {125// Only qmds should be left in this directory126const dir = join(Deno.cwd(), dirname(docInput));127128const cleanup = ["notebook.embed_files", "notebook.embed-preview.html", "notebook2.embed_files", "notebook2.embed-preview.html"];129cleanup.forEach((path) => {130Deno.removeSync(join(dir, path), {recursive: true});131})132return Promise.resolve();133},134});135136137138