Path: blob/main/tests/smoke/project/project-prepost.test.ts
12925 views
/*1* project-prepost.test.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*5*/6import { docs } from "../../utils.ts";78import { join } from "../../../src/deno_ral/path.ts";9import { existsSync } from "../../../src/deno_ral/fs.ts";10import { testQuartoCmd } from "../../test.ts";11import { fileExists, noErrors, printsMessage, validJsonWithFields, verifyNoPath, verifyPath } from "../../verify.ts";12import { normalizePath, safeRemoveIfExists } from "../../../src/core/path.ts";1314const renderDir = docs("project/prepost/mutate-render-list");15const dir = join(Deno.cwd(), renderDir);16const outDir = join(dir, "_site");1718const sidebarContents = ["sidebar/test1.html", "sidebar/test2.html"]19const sidebarContentsExists = sidebarContents.map((path) => {20return fileExists(join(outDir, path))21});2223testQuartoCmd(24"render",25[renderDir],26[noErrors, ...sidebarContentsExists],27{28teardown: async () => {29if (existsSync(outDir)) {30await Deno.remove(outDir, { recursive: true });31}32},33},34);35363738// Tests that if the pre-render script mutates the output directory39// we throw an error that complains about this.40const mutateRenderDir = docs("project/prepost/invalid-mutate");41const mutateRenderDirAbs = join(Deno.cwd(), mutateRenderDir);42const mutateRenderOutDir = join(mutateRenderDirAbs, "_site");4344testQuartoCmd(45"render",46[mutateRenderDir],47[printsMessage({level: "ERROR", regex: /output-dir may not be mutated/gm})],48{49teardown: async () => {50const mdClean = join(mutateRenderDirAbs, "_metadata.yml");51console.log({mdClean});52if (existsSync(mdClean)) {53await Deno.remove(mdClean);54}55if (existsSync(mutateRenderOutDir)) {56await Deno.remove(mutateRenderOutDir, { recursive: true });57}58},59},60);6162testQuartoCmd(63"render",64[docs("project/prepost/extension")],65[{66name: "i-exist.txt exists",67verify: async () => {68const path = join(docs("project/prepost/extension"), "i-exist.txt");69verifyNoPath(path);70}71}],72{73teardown: async () => {74const path = join(docs("project/prepost/extension"), "i-was-created.txt");75verifyPath(path);76safeRemoveIfExists(path);77const siteDir = join(docs("project/prepost/extension"), "_site");78if (existsSync(siteDir)) {79await Deno.remove(siteDir, { recursive: true });80}81}82});8384testQuartoCmd(85"render",86[docs("project/prepost/issue-10828")],87[],88{89env: {90"QUARTO_USE_FILE_FOR_PROJECT_INPUT_FILES": normalizePath(docs("project/prepost/issue-10828/input-files.txt")),91"QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES": normalizePath(docs("project/prepost/issue-10828/output-files.txt"))92},93teardown: async () => {94const inputPath = normalizePath(docs("project/prepost/issue-10828/input-files.txt"));95const outputPath = normalizePath(docs("project/prepost/issue-10828/output-files.txt"));96verifyPath(inputPath);97safeRemoveIfExists(inputPath);98verifyPath(outputPath);99safeRemoveIfExists(outputPath);100const siteDir = join(docs("project/prepost/issue-10828"), "_site");101if (existsSync(siteDir)) {102await Deno.remove(siteDir, { recursive: true });103}104}105}106)107108// Verify that pre-render scripts receive QUARTO_PROJECT_SCRIPT_PROGRESS109// and QUARTO_PROJECT_SCRIPT_QUIET environment variables110const scriptEnvDir = docs("project/prepost/script-env-vars");111const scriptEnvDirAbs = join(Deno.cwd(), scriptEnvDir);112const envDumpPath = join(scriptEnvDirAbs, "env-dump.json");113const scriptEnvOutDir = join(scriptEnvDirAbs, "_site");114115testQuartoCmd(116"render",117[scriptEnvDir],118[119noErrors,120validJsonWithFields(envDumpPath, {121progress: "1",122quiet: "0",123}),124],125{126teardown: async () => {127safeRemoveIfExists(envDumpPath);128if (existsSync(scriptEnvOutDir)) {129await Deno.remove(scriptEnvOutDir, { recursive: true });130}131},132},133);134135136