|
| 1 | +/* |
| 2 | + * smoke-all.test.ts |
| 3 | + * |
| 4 | + * Copyright (C) 2022 by RStudio, PBC |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +import { expandGlobSync } from "fs/mod.ts"; |
| 9 | +import { unitTest } from "../test.ts"; |
| 10 | + |
| 11 | +import { initYamlIntelligenceResourcesFromFilesystem } from "../../src/core/schema/utils.ts"; |
| 12 | +import { |
| 13 | + initState, |
| 14 | + setInitializer, |
| 15 | +} from "../../src/core/lib/yaml-validation/state.ts"; |
| 16 | + |
| 17 | +import { breakQuartoMd } from "../../src/core/lib/break-quarto-md.ts"; |
| 18 | +import { parse } from "encoding/yaml.ts"; |
| 19 | +import { cleanoutput } from "./render/render.ts"; |
| 20 | +import { quarto } from "../../src/quarto.ts"; |
| 21 | + |
| 22 | +async function fullInit() { |
| 23 | + await initYamlIntelligenceResourcesFromFilesystem(); |
| 24 | +} |
| 25 | + |
| 26 | +async function guessFormat(fileName: string): Promise<string[]> { |
| 27 | + const { cells } = await breakQuartoMd(Deno.readTextFileSync(fileName)); |
| 28 | + |
| 29 | + const formats: Set<string> = new Set(); |
| 30 | + |
| 31 | + for (const cell of cells) { |
| 32 | + if (cell.cell_type === "raw") { |
| 33 | + const src = cell.source.value.replaceAll(/^---$/mg, ""); |
| 34 | + const yaml = parse(src); |
| 35 | + if (yaml && typeof yaml === "object") { |
| 36 | + for ( |
| 37 | + const [k, _] of Object.entries( |
| 38 | + // deno-lint-ignore no-explicit-any |
| 39 | + (yaml as Record<string, any>).format || {}, |
| 40 | + ) |
| 41 | + ) { |
| 42 | + formats.add(k); |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + return Array.from(formats); |
| 48 | +} |
| 49 | + |
| 50 | +unitTest("smoke-all", async () => { |
| 51 | + setInitializer(fullInit); |
| 52 | + await initState(); |
| 53 | + |
| 54 | + for ( |
| 55 | + const { path: fileName } of expandGlobSync( |
| 56 | + "docs/smoke-all/**/*.qmd", |
| 57 | + ) |
| 58 | + ) { |
| 59 | + const input = fileName; |
| 60 | + |
| 61 | + const formats = await guessFormat(input); |
| 62 | + |
| 63 | + if (formats.length == 0) { |
| 64 | + formats.push("html"); |
| 65 | + } |
| 66 | + |
| 67 | + for (const format of formats) { |
| 68 | + await quarto(["render", input, "--to", format]); |
| 69 | + cleanoutput(input, format); |
| 70 | + } |
| 71 | + } |
| 72 | +}); |
0 commit comments