1- // POSIX path contract tests — locks in the cross-platform behavior of the
2- // Node primitives this PR's fixes depend on. If a future Node version
3- // changes any of these, the failing test surfaces the regression before
4- // the framework breaks on Windows again.
5-
1+ // Lock in cross-platform output of Node primitives — a regression here is a future Windows break.
62import { posix } from 'node:path'
73import { pathToFileURL } from 'node:url'
84import { describe , expect , it } from 'vitest'
@@ -41,9 +37,7 @@ describe('pathToFileURL — canonical file:// URL specifier', () => {
4137 } )
4238
4339 it ( 'round-trips through JSON.stringify without backslashes leaking in' , ( ) => {
44- // The motivating defect: emitting `import "${absolutePath}"` puts
45- // backslashes into the generated JS source on Windows. A file:// URL
46- // does not.
40+ // motivating defect: bare absolute path puts backslashes in emitted JS on Windows
4741 const href = pathToFileURL ( '/proj/src/setup.ts' ) . href
4842 const stringified = JSON . stringify ( href )
4943 expect ( stringified . includes ( '\\\\' ) ) . toBe ( false )
@@ -56,9 +50,7 @@ describe('Vite normalizePath — converts on Windows, no-op on POSIX', () => {
5650 } )
5751
5852 it ( 'converts backslashes (Windows-shaped input)' , ( ) => {
59- // normalizePath only converts on Windows hosts. We assert the contract
60- // shape — on Windows: backslashes converted; on POSIX: passthrough
61- // because backslash is a valid filename character.
53+ // Windows converts; POSIX passthrough (backslash is a valid filename char there)
6254 const input = String . raw `C:\proj\src\foo.tsx`
6355 const out = normalizePath ( input )
6456 if ( process . platform === 'win32' ) {
@@ -70,10 +62,7 @@ describe('Vite normalizePath — converts on Windows, no-op on POSIX', () => {
7062} )
7163
7264describe ( 'toServerOutputPath — cross-platform parity' , ( ) => {
73- // toServerOutputPath uses path.posix.join + replace(/\\/g, '/') so the
74- // output must be byte-identical across platforms. The fact that we
75- // converted from Vite's normalizePath to this implementation was driven
76- // by a Linux Docker test failure during initial review.
65+ // posix.join + backslash-replace (not normalizePath) — output must be byte-identical across platforms
7766 const cases : Array < [ string , string , string ] > = [
7867 [ 'foo.js' , 'dist' , 'dist/server/foo.js' ] ,
7968 [ 'subdir/bar.js' , 'dist' , 'dist/server/subdir/bar.js' ] ,
@@ -93,11 +82,7 @@ describe('toServerOutputPath — cross-platform parity', () => {
9382} )
9483
9584describe ( 'seed bug regression — SSR loader path doubling on Windows' , ( ) => {
96- // Direct regression test for the specific shape that hit production:
97- // build.ts:1031 minted `dist\server\assets\time_ssr-XXX.js` (native sep);
98- // oneServe.ts:168 then ran `.includes('dist/server')` on it (forward slash);
99- // the check missed; `join('./','dist/server','dist\\server\\...')` was
100- // called; result was `dist\server\dist\server\...` — passed to await import().
85+ // serverJsPath minted native sep; oneServe `.includes('/server')` missed; prefix doubled, await import() crashed
10186 it ( 'does not double-prefix backslash-shaped server-output input' , ( ) => {
10287 const windowsShapedInput = String . raw `dist\server\assets\time_ssr-COqAsxju.js`
10388 expect ( toServerOutputPath ( windowsShapedInput , 'dist' ) ) . toBe (
0 commit comments