Skip to content

Commit 3e4308b

Browse files
committed
Fix single-file preview handler using project handler with wrong default
The handler selection at line 251 had the same project-truthiness bug as the URL path computation: single-file projects used projectHtmlFileRequestHandler (defaultFile="index.html") instead of htmlFileRequestHandler (defaultFile=basename of output). This caused GET / to return 404 for single-file previews since v1.9. Add isSingleFile guard to handler selection. Also fix test cleanup by letting createMockProjectContext own temp dir creation.
1 parent 3411d67 commit 3e4308b

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

src/command/preview/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export async function preview(
248248
changeHandler.render,
249249
project,
250250
)
251-
: project
251+
: project && !project.isSingleFile
252252
? projectHtmlFileRequestHandler(
253253
project,
254254
normalizePath(file),

tests/unit/preview-initial-path.test.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
import { unitTest } from "../test.ts";
1111
import { assertEquals } from "testing/asserts";
1212
import { join } from "../../src/deno_ral/path.ts";
13-
import { normalizePath } from "../../src/core/path.ts";
1413
import { previewInitialPath } from "../../src/command/preview/preview.ts";
1514
import { createMockProjectContext } from "./project/utils.ts";
1615

1716
// deno-lint-ignore require-await
1817
unitTest("previewInitialPath - single file returns empty path (#14298)", async () => {
19-
const dir = normalizePath(Deno.makeTempDirSync({ prefix: "quarto-test" }));
20-
const outputFile = join(dir, "hello.html");
21-
const project = createMockProjectContext({ dir, isSingleFile: true });
18+
const project = createMockProjectContext({ isSingleFile: true });
19+
const outputFile = join(project.dir, "hello.html");
2220

2321
const result = previewInitialPath(outputFile, project);
2422
assertEquals(result, "", "Single-file preview should use root path, not filename");
@@ -28,9 +26,8 @@ unitTest("previewInitialPath - single file returns empty path (#14298)", async (
2826

2927
// deno-lint-ignore require-await
3028
unitTest("previewInitialPath - project file returns relative path", async () => {
31-
const dir = normalizePath(Deno.makeTempDirSync({ prefix: "quarto-test" }));
32-
const outputFile = join(dir, "chapter.html");
33-
const project = createMockProjectContext({ dir });
29+
const project = createMockProjectContext();
30+
const outputFile = join(project.dir, "chapter.html");
3431

3532
const result = previewInitialPath(outputFile, project);
3633
assertEquals(result, "chapter.html", "Project preview should include relative path");
@@ -40,9 +37,8 @@ unitTest("previewInitialPath - project file returns relative path", async () =>
4037

4138
// deno-lint-ignore require-await
4239
unitTest("previewInitialPath - project subdir returns relative path", async () => {
43-
const dir = normalizePath(Deno.makeTempDirSync({ prefix: "quarto-test" }));
44-
const outputFile = join(dir, "pages", "about.html");
45-
const project = createMockProjectContext({ dir });
40+
const project = createMockProjectContext();
41+
const outputFile = join(project.dir, "pages", "about.html");
4642

4743
const result = previewInitialPath(outputFile, project);
4844
assertEquals(result, "pages/about.html", "Project preview should include subdirectory path");

0 commit comments

Comments
 (0)