Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/unit/dart-sass.test.ts
6449 views
1
/*
2
* dart-sass.test.ts
3
*
4
* Tests for dart-sass functionality.
5
* Validates fix for https://github.com/quarto-dev/quarto-cli/issues/13997
6
*
7
* Copyright (C) 2020-2025 Posit Software, PBC
8
*/
9
10
import { unitTest } from "../test.ts";
11
import { assert } from "testing/asserts";
12
import { isWindows } from "../../src/deno_ral/platform.ts";
13
import { join } from "../../src/deno_ral/path.ts";
14
import { dartCommand, dartSassInstallDir } from "../../src/core/dart-sass.ts";
15
16
// Test that dartCommand handles spaced paths on Windows (issue #13997)
17
// The bug only triggers when BOTH the executable path AND arguments contain spaces.
18
unitTest(
19
"dartCommand - handles spaced paths on Windows (issue #13997)",
20
async () => {
21
// Create directories with spaces for both sass and file arguments
22
const tempBase = Deno.makeTempDirSync({ prefix: "quarto_test_" });
23
const spacedSassDir = join(tempBase, "Program Files", "dart-sass");
24
const spacedProjectDir = join(tempBase, "My Project");
25
const sassInstallDir = dartSassInstallDir();
26
27
try {
28
// Create directories
29
Deno.mkdirSync(join(tempBase, "Program Files"), { recursive: true });
30
Deno.mkdirSync(spacedProjectDir, { recursive: true });
31
32
// Create junction (Windows directory symlink) to actual dart-sass
33
const junctionResult = await new Deno.Command("cmd", {
34
args: ["/c", "mklink", "/J", spacedSassDir, sassInstallDir],
35
}).output();
36
37
if (!junctionResult.success) {
38
const stderr = new TextDecoder().decode(junctionResult.stderr);
39
throw new Error(`Failed to create junction: ${stderr}`);
40
}
41
42
// Create test SCSS file in spaced path (args with spaces)
43
const inputScss = join(spacedProjectDir, "test style.scss");
44
const outputCss = join(spacedProjectDir, "test style.css");
45
Deno.writeTextFileSync(inputScss, "body { color: red; }");
46
47
const spacedSassPath = join(spacedSassDir, "sass.bat");
48
49
// This is the exact bug scenario: spaced exe path + spaced args
50
// Without the fix, this fails with "C:\...\Program" not recognized
51
const result = await dartCommand([inputScss, outputCss], {
52
sassPath: spacedSassPath,
53
});
54
55
// Verify compilation succeeded (no stdout expected for file-to-file compilation)
56
assert(
57
result === undefined || result === "",
58
"Sass compile should succeed (no stdout for file-to-file compilation)",
59
);
60
assert(
61
Deno.statSync(outputCss).isFile,
62
"Output CSS file should be created",
63
);
64
} finally {
65
// Cleanup: remove junction first (rmdir for junctions), then temp directory
66
try {
67
await new Deno.Command("cmd", {
68
args: ["/c", "rmdir", spacedSassDir],
69
}).output();
70
await Deno.remove(tempBase, { recursive: true });
71
} catch (e) {
72
// Best effort cleanup - log for debugging if it fails
73
console.debug("Test cleanup failed:", e);
74
}
75
}
76
},
77
{ ignore: !isWindows },
78
);
79
80