From c89dc788affbb5d16d9e83fd735efd163859ebcb Mon Sep 17 00:00:00 2001 From: Kallinikos Milonakis Date: Fri, 28 Aug 2026 21:56:31 +0300 Subject: [PATCH] test: make path assertions platform-agnostic so the suite passes on Windows Five assertions in two suites compared platform-native paths against hard-coded POSIX literals, so they failed on Windows even though the code under test is correct -- it builds those paths with `path.join` / `path.resolve`, which use backslashes there. Expected: "path/to/react-native/scripts/compose-source-maps.js" Received: "path\to\react-native\scripts\compose-source-maps.js" Run the expectations through `path.join` / `path.resolve` instead of comparing raw strings. Both are no-ops on POSIX, so Linux and macOS runs are unchanged. In resolveProjectPath.test.ts the root is resolved as well. Without a drive letter, up-level navigation that reaches the root collapses to a bare backslash, which Windows then reads as the beginning of a UNC share -- the test produced \\shared\utils.js rather than a local path. --- .../common/__tests__/resolveProjectPath.test.ts | 12 +++++++++++- .../plugins/__tests__/HermesBytecodePlugin.test.ts | 7 ++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/repack/src/commands/common/__tests__/resolveProjectPath.test.ts b/packages/repack/src/commands/common/__tests__/resolveProjectPath.test.ts index 89d2e06c2..32e884ef7 100644 --- a/packages/repack/src/commands/common/__tests__/resolveProjectPath.test.ts +++ b/packages/repack/src/commands/common/__tests__/resolveProjectPath.test.ts @@ -1,12 +1,22 @@ +import path from 'node:path'; import { resolveProjectPath } from '../resolveProjectPath.js'; describe('resolveProjectPath', () => { + // The cases below are written with POSIX literals for readability. + // `resolveProjectPath` returns an absolute, platform-native path, so both the + // root and the expectation are run through `path.resolve` to give them a + // drive letter on Windows. Both calls are no-ops on POSIX. + // Resolving the root matters: without a drive, up-level navigation that + // reaches the root collapses to a bare "\\", which Windows then reads as the + // start of a UNC share rather than a local path. const expectResolved = ( input: string, expected: string, root = '/project/root' ) => { - expect(resolveProjectPath(input, root)).toBe(expected); + expect(resolveProjectPath(input, path.resolve(root))).toBe( + path.resolve(expected) + ); }; it('should resolve [projectRoot] prefix correctly', () => { diff --git a/packages/repack/src/plugins/__tests__/HermesBytecodePlugin.test.ts b/packages/repack/src/plugins/__tests__/HermesBytecodePlugin.test.ts index f93c32447..cf616df91 100644 --- a/packages/repack/src/plugins/__tests__/HermesBytecodePlugin.test.ts +++ b/packages/repack/src/plugins/__tests__/HermesBytecodePlugin.test.ts @@ -1,5 +1,6 @@ import fs from 'node:fs'; import os from 'node:os'; +import path from 'node:path'; import { type Compiler, ModuleFilenameHelpers } from '@rspack/core'; import execa from 'execa'; import { HermesBytecodePlugin } from '../HermesBytecodePlugin/index.js'; @@ -108,7 +109,7 @@ describe('HermesBytecodePlugin', () => { expect(execaNodeMock).toHaveBeenCalledTimes(1); expect(execaNodeMock.mock.calls[0][0]).toEqual( - 'path/to/react-native/scripts/compose-source-maps.js' + path.join('path/to/react-native/scripts/compose-source-maps.js') ); }); @@ -156,7 +157,7 @@ describe('HermesBytecodePlugin', () => { const hermesPath = getHermesCLIPath(reactNativePath); expect(hermesPath).toBe( - 'path/to/hermes-compiler/hermesc/osx-bin/hermesc' + path.join('path/to/hermes-compiler/hermesc/osx-bin/hermesc') ); }); @@ -167,7 +168,7 @@ describe('HermesBytecodePlugin', () => { const hermesPath = getHermesCLIPath(reactNativePath); expect(hermesPath).toBe( - 'path/to/react-native/sdks/hermesc/osx-bin/hermesc' + path.join('path/to/react-native/sdks/hermesc/osx-bin/hermesc') ); }); });