Skip to content

Commit 8bb43d5

Browse files
technicallybrantleyclaudewpfleger96
authored
fix(desktop): make the test loader work on Windows (#2758)
The resolve hook hands nextResolve absolute filesystem paths. Node's ESM resolver requires URLs or relative specifiers: POSIX absolute paths happen to be coerced, but a Windows path like C:\... parses as a URL with protocol 'c:', so every desktop unit-test run on Windows dies immediately with ERR_UNSUPPORTED_ESM_URL_SCHEME - on a clean tree, before any test executes. CI never sees it (Linux runners). Convert absolute paths to file:// URLs (pathToFileURL) at the three nextResolve call sites. On POSIX the resulting URL is identical to what node coerced before; on Windows the loader now works. With this change the full desktop suite (318 files, 3487 tests) passes on Windows 11 / node 24.14.1. Independently reported by another Windows contributor in #2634's testing notes. Claude-Session: https://claude.ai/code/session_01YFkHsUe1UUBBuvL81Zoe3n --------- Signed-off-by: technicallybrantley <[email protected]> Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Will Pfleger <[email protected]>
1 parent 545bb46 commit 8bb43d5

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

‎desktop/test-loader-hooks.mjs‎

Lines changed: 18 additions & 4 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 fs from "node:fs";
33
import path from "node:path";
44
import ts from "typescript";
@@ -13,6 +13,17 @@ const repoRoot = path.resolve(
1313
"..",
1414
);
1515

16+
// `nextResolve` requires specifiers to be URLs or relative paths. Passing an
17+
// absolute filesystem path happens to work on POSIX (node coerces it), but on
18+
// Windows an absolute path like `C:\...` parses as a URL with protocol `c:`
19+
// and every test run dies with ERR_UNSUPPORTED_ESM_URL_SCHEME. Hand absolute
20+
// paths to node as proper file:// URLs on all platforms.
21+
function toFileSpecifier(candidatePath) {
22+
return path.isAbsolute(candidatePath)
23+
? pathToFileURL(candidatePath).href
24+
: candidatePath;
25+
}
26+
1627
function resolveSourcePath(basePath) {
1728
// Existence decides, not path.extname — a dotted basename like
1829
// `ProfileAvatarEditor.utils` (→ .utils.ts on disk) looks like an
@@ -76,7 +87,7 @@ export function resolve(specifier, context, nextResolve) {
7687
}
7788
if (specifier === "@features-manifest") {
7889
const resolved = path.join(repoRoot, "preview-features.json");
79-
return nextResolve(resolved, context);
90+
return nextResolve(toFileSpecifier(resolved), context);
8091
}
8192
if (specifier.startsWith("@/")) {
8293
const stripped = specifier.slice(2);
@@ -86,7 +97,10 @@ export function resolve(specifier, context, nextResolve) {
8697
// Otherwise paths like `@/.../foo.mjs` would be coerced into `foo.mjs.ts`
8798
// and fail to resolve.
8899
const resolved = resolveSourcePath(`${srcRoot}/${stripped}`);
89-
return nextResolve(resolved ?? `${srcRoot}/${stripped}`, context);
100+
return nextResolve(
101+
toFileSpecifier(resolved ?? `${srcRoot}/${stripped}`),
102+
context,
103+
);
90104
}
91105
// Resolve extensionless relative TS imports (e.g. `./parseImeta`) — the app's
92106
// bundler adds the extension, but node's ESM resolver does not. Without this,
@@ -103,7 +117,7 @@ export function resolve(specifier, context, nextResolve) {
103117
path.resolve(path.dirname(parentPath), specifier),
104118
);
105119
if (resolved) {
106-
return nextResolve(resolved, context);
120+
return nextResolve(toFileSpecifier(resolved), context);
107121
}
108122
return nextResolve(specifier, context);
109123
}

0 commit comments

Comments
 (0)