Path: blob/main/tests/smoke/render/render-r.test.ts
12925 views
/*1* render-r.test.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*5*/67import { docs, fileLoader, inTempDirectory } from "../../utils.ts";8import { join } from "../../../src/deno_ral/path.ts";9import { ensureHtmlElements, ensureHtmlSelectorSatisfies, fileExists } from "../../verify.ts";10import { testRender } from "./render.ts";1112inTempDirectory((dir) => {13const tempInput = join(dir, "test.Rmd");14Deno.copyFileSync(docs("test.Rmd"), tempInput);15const thisPlotPath = join(dir, "test_files/figure-html");1617testRender(tempInput, "html", false, [18fileExists(thisPlotPath),19], {20teardown: () => {21return Deno.remove(dir, { recursive: true });22},23});24});2526inTempDirectory((dir) => {27const tempInput = join(dir, "test.Rmd");28Deno.copyFileSync(docs("test.Rmd"), tempInput);2930const thisPlotPath = join(dir, "test_files/figure-html");31testRender(tempInput, "html", false, [32fileExists(thisPlotPath),33], {34teardown: () => {35return Deno.remove(dir, { recursive: true });36},37}, ["--execute-params", "docs/params.yml"]);38});3940const knitrOptions = fileLoader()("test-knitr-options.qmd", "html");41testRender(knitrOptions.input, "html", false, [42ensureHtmlSelectorSatisfies(43knitrOptions.output.outputPath,44"#comment-empty code",45(nodeList) => {46return /\n\[1\] 3/.test(nodeList[0].textContent);47},48),49ensureHtmlSelectorSatisfies(50knitrOptions.output.outputPath,51"#comment-change code",52(nodeList) => {53return /\n\$ \[1\] 3/.test(nodeList[0].textContent);54},55),56ensureHtmlSelectorSatisfies(57knitrOptions.output.outputPath,58"#prompt code.sourceCode",59(nodeList) => {60return Array.from(nodeList).every((e) => /^>/.test(e.textContent));61},62),63ensureHtmlSelectorSatisfies(64knitrOptions.output.outputPath,65"#no-prompt code.sourceCode",66(nodeList) => {67return Array.from(nodeList).every((e) => /^[^>]/.test(e.textContent));68},69),70]);7172const sqlEngine = fileLoader()("test-knitr-sql.qmd", "html");73testRender(sqlEngine.input, "html", false);747576const toSpin = fileLoader()("knitr-spin.R", "html");77testRender(toSpin.input, "html", false, [78ensureHtmlElements(79toSpin.output.outputPath, ["#block img"]80),81ensureHtmlSelectorSatisfies(82toSpin.output.outputPath,83"#inline code",84(nodeList) => {85return /^3\.14+/.test(nodeList[0].textContent);86},87),88]);8990