Skip to content

Commit e0998fa

Browse files
committed
Refactor for clarity
1 parent dae0e92 commit e0998fa

File tree

1 file changed

+31
-56
lines changed

1 file changed

+31
-56
lines changed

tests/smoke/render/render-output-dir.test.ts

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,69 +12,44 @@ import { docs } from "../../utils.ts";
1212
import { isWindows } from "../../../src/deno_ral/platform.ts";
1313
import { fileExists, pathDoNotExists } from "../../verify.ts";
1414
import { testRender } from "./render.ts";
15+
import type { Verify } from "../../test.ts";
1516

1617
if (isWindows) {
1718
const inputDir = docs("render-output-dir/");
1819
const quartoDir = ".quarto";
1920
const outputDir = "output-test-dir";
2021

21-
// Test 1: Default behavior (clean=true) - .quarto should be removed
22-
testRender(
23-
"test.qmd",
24-
"html",
25-
false,
26-
[pathDoNotExists(quartoDir)],
27-
{
28-
cwd: () => inputDir,
29-
setup: async () => {
30-
// Ensure output and quarto dirs are removed before test
31-
if (existsSync(outputDir)) {
32-
safeRemoveSync(outputDir, { recursive: true });
33-
}
34-
if (existsSync(quartoDir)) {
35-
safeRemoveSync(quartoDir, { recursive: true });
36-
}
37-
},
38-
teardown: async () => {
39-
if (existsSync(outputDir)) {
40-
safeRemoveSync(outputDir, { recursive: true });
41-
}
42-
if (existsSync(quartoDir)) {
43-
safeRemoveSync(quartoDir, { recursive: true });
44-
}
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,
4544
},
46-
},
47-
["--output-dir", outputDir],
48-
outputDir,
49-
);
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));
5052

5153
// Test 2: With --no-clean flag - .quarto should be preserved
52-
testRender(
53-
"test.qmd",
54-
"html",
55-
false,
56-
[fileExists(quartoDir)],
57-
{
58-
cwd: () => inputDir,
59-
setup: async () => {
60-
// Ensure output and quarto dirs are removed before test
61-
if (existsSync(outputDir)) {
62-
safeRemoveSync(outputDir, { recursive: true });
63-
}
64-
if (existsSync(quartoDir)) {
65-
safeRemoveSync(quartoDir, { recursive: true });
66-
}
67-
},
68-
teardown: async () => {
69-
if (existsSync(outputDir)) {
70-
safeRemoveSync(outputDir, { recursive: true });
71-
}
72-
if (existsSync(quartoDir)) {
73-
safeRemoveSync(quartoDir, { recursive: true });
74-
}
75-
},
76-
},
77-
["--output-dir", outputDir, "--no-clean"],
78-
outputDir,
79-
);
54+
testOutputDirRender(fileExists(quartoDir), ["--no-clean"]);
8055
}

0 commit comments

Comments
 (0)