Skip to content

Commit f6bcc4f

Browse files
committed
test: fix windows path handling in new tests
1 parent e4d6e74 commit f6bcc4f

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎test/presets/vercel.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { promises as fsp } from "node:fs";
22
import { fileURLToPath } from "node:url";
3-
import { resolve, join, basename } from "pathe";
3+
import { resolve, join, basename, normalize } from "pathe";
44
import { describe, expect, it, afterAll } from "vitest";
55
import { setupTest, startServer, testNitro, fixtureDir } from "../tests";
66

@@ -10,7 +10,11 @@ describe("nitro:preset:vercel", async () => {
1010
handlers: [
1111
{
1212
route: "/slash",
13-
handler: fileURLToPath(new URL("fixtures/slash.ts", import.meta.url)),
13+
// Handler paths are embedded as-is in the generated imports, so
14+
// Windows backslashes must be normalized
15+
handler: normalize(
16+
fileURLToPath(new URL("fixtures/slash.ts", import.meta.url))
17+
),
1418
},
1519
],
1620
prerender: {

‎test/unit/dev-error-sourcemap.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ describe("dev error handler: source maps", () => {
7777
const error = new Error("boom");
7878
error.stack = `Error: boom\n at fn (${brokenBundle}:1:1)`;
7979
await expect(loadStackTrace(error)).resolves.toBeUndefined();
80-
expect(error.stack).toContain(`${brokenBundle}:1:1`);
80+
// The stack parser normalizes frame paths to forward slashes (Windows)
81+
expect(error.stack).toContain(`${brokenBundle.replaceAll("\\", "/")}:1:1`);
8182
});
8283
});

‎test/unit/public-assets.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fileURLToPath } from "node:url";
1+
import { fileURLToPath, pathToFileURL } from "node:url";
22
import { dirname, resolve } from "pathe";
33
import { describe, expect, it } from "vitest";
44
import type { Nitro } from "nitropack/types";
@@ -44,7 +44,8 @@ function loadReadAsset(readFile: () => Promise<unknown>) {
4444
resolve,
4545
dirname,
4646
ASSETS,
47-
"file:///app/server/index.mjs"
47+
// Absolute on every platform (resolves to the current drive on Windows)
48+
pathToFileURL("/app/server/index.mjs").href
4849
) as (id: string) => Promise<unknown>;
4950
}
5051

0 commit comments

Comments
 (0)