Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/unit/preview-initial-path.test.ts
12924 views
1
/*
2
* preview-initial-path.test.ts
3
*
4
* Tests that previewInitialPath computes the correct browse URL path
5
* for different project types. Regression test for #14298.
6
*
7
* Copyright (C) 2026 Posit Software, PBC
8
*/
9
10
import { unitTest } from "../test.ts";
11
import { assertEquals } from "testing/asserts";
12
import { join } from "../../src/deno_ral/path.ts";
13
import { previewInitialPath } from "../../src/command/preview/preview.ts";
14
import { createMockProjectContext } from "./project/utils.ts";
15
16
// deno-lint-ignore require-await
17
unitTest("previewInitialPath - single file returns empty path (#14298)", async () => {
18
const project = createMockProjectContext({ isSingleFile: true });
19
const outputFile = join(project.dir, "hello.html");
20
21
const result = previewInitialPath(outputFile, project);
22
assertEquals(result, "", "Single-file preview should use root path, not filename");
23
24
project.cleanup();
25
});
26
27
// deno-lint-ignore require-await
28
unitTest("previewInitialPath - project file returns relative path", async () => {
29
const project = createMockProjectContext();
30
const outputFile = join(project.dir, "chapter.html");
31
32
const result = previewInitialPath(outputFile, project);
33
assertEquals(result, "chapter.html", "Project preview should include relative path");
34
35
project.cleanup();
36
});
37
38
// deno-lint-ignore require-await
39
unitTest("previewInitialPath - project subdir returns relative path", async () => {
40
const project = createMockProjectContext();
41
const outputFile = join(project.dir, "pages", "about.html");
42
43
const result = previewInitialPath(outputFile, project);
44
assertEquals(result, "pages/about.html", "Project preview should include subdirectory path");
45
46
project.cleanup();
47
});
48
49
// deno-lint-ignore require-await
50
unitTest("previewInitialPath - undefined project returns empty path", async () => {
51
const result = previewInitialPath("/tmp/hello.html", undefined);
52
assertEquals(result, "", "No project should use root path");
53
});
54
55