|
| 1 | +/* |
| 2 | +* render-output-dir.test.ts |
| 3 | +* |
| 4 | +* Test for Windows file locking issue with --output-dir flag |
| 5 | +* Regression test for: https://github.com/quarto-dev/quarto-cli/issues/13625 |
| 6 | +* |
| 7 | +* Copyright (C) 2020-2025 Posit Software, PBC |
| 8 | +* |
| 9 | +*/ |
| 10 | +import { existsSync, safeRemoveSync } from "../../../src/deno_ral/fs.ts"; |
| 11 | +import { docs } from "../../utils.ts"; |
| 12 | +import { isWindows } from "../../../src/deno_ral/platform.ts"; |
| 13 | +import { fileExists, pathDoNotExists } from "../../verify.ts"; |
| 14 | +import { testRender } from "./render.ts"; |
| 15 | +import type { Verify } from "../../test.ts"; |
| 16 | + |
| 17 | + |
| 18 | +const inputDir = docs("render-output-dir/"); |
| 19 | +const quartoDir = ".quarto"; |
| 20 | +const outputDir = "output-test-dir"; |
| 21 | + |
| 22 | +const cleanupDirs = async () => { |
| 23 | + if (existsSync(outputDir)) { |
| 24 | + safeRemoveSync(outputDir, { recursive: true }); |
| 25 | + } |
| 26 | + if (existsSync(quartoDir)) { |
| 27 | + safeRemoveSync(quartoDir, { recursive: true }); |
| 28 | + } |
| 29 | +}; |
| 30 | + |
| 31 | +const testOutputDirRender = ( |
| 32 | + quartoVerify: Verify, |
| 33 | + extraArgs: string[] = [], |
| 34 | +) => { |
| 35 | + testRender( |
| 36 | + "test.qmd", |
| 37 | + "html", |
| 38 | + false, |
| 39 | + [quartoVerify], |
| 40 | + { |
| 41 | + cwd: () => inputDir, |
| 42 | + setup: cleanupDirs, |
| 43 | + teardown: cleanupDirs, |
| 44 | + }, |
| 45 | + ["--output-dir", outputDir, ...extraArgs], |
| 46 | + outputDir, |
| 47 | + ); |
| 48 | +}; |
| 49 | + |
| 50 | +// Test 1: Default behavior (clean=true) - .quarto should be removed |
| 51 | +testOutputDirRender(pathDoNotExists(quartoDir)); |
| 52 | + |
| 53 | +// Test 2: With --no-clean flag - .quarto should be preserved |
| 54 | +testOutputDirRender(fileExists(quartoDir), ["--no-clean"]); |
0 commit comments