diff --git a/scripts/tests/dev.test.js b/scripts/tests/dev.test.js index a7af625ac8d..cd99e55e045 100644 --- a/scripts/tests/dev.test.js +++ b/scripts/tests/dev.test.js @@ -12,6 +12,8 @@ const { spawnMock, platformMock, existsSyncMock } = vi.hoisted(() => ({ existsSyncMock: vi.fn(() => false), })); +const normalizePath = (filePath) => String(filePath).replaceAll('\\', '/'); + vi.mock('node:child_process', () => ({ spawn: spawnMock, })); @@ -57,7 +59,7 @@ describe('scripts/dev.js launcher', () => { it('spawns Node without a shell on Windows when local tsx cli.mjs exists', async () => { platformMock.mockReturnValue('win32'); existsSyncMock.mockImplementation((filePath) => - String(filePath).endsWith('node_modules/tsx/dist/cli.mjs'), + normalizePath(filePath).endsWith('node_modules/tsx/dist/cli.mjs'), ); Object.defineProperty(process, 'execPath', { configurable: true, @@ -67,29 +69,29 @@ describe('scripts/dev.js launcher', () => { await import('../dev.js?direct-node'); - expect(spawnMock).toHaveBeenCalledWith( - 'C:\\Program Files\\nodejs\\node.exe', - [ - expect.stringContaining('node_modules/tsx/dist/cli.mjs'), - expect.stringContaining('packages/cli/index.ts'), - '--help', - ], - expect.objectContaining({ shell: false }), - ); + const [command, args, options] = spawnMock.mock.calls[0]; + expect(command).toBe('C:\\Program Files\\nodejs\\node.exe'); + expect(args.map(normalizePath)).toEqual([ + expect.stringContaining('node_modules/tsx/dist/cli.mjs'), + expect.stringContaining('packages/cli/index.ts'), + '--help', + ]); + expect(options).toEqual(expect.objectContaining({ shell: false })); }); it('keeps shell fallback for Windows tsx.cmd resolution', async () => { platformMock.mockReturnValue('win32'); existsSyncMock.mockImplementation((filePath) => - String(filePath).endsWith('node_modules/.bin/tsx.cmd'), + normalizePath(filePath).endsWith('node_modules/.bin/tsx.cmd'), ); await import('../dev.js?cmd-fallback'); - expect(spawnMock).toHaveBeenCalledWith( - expect.stringContaining('tsx.cmd'), - [expect.stringContaining('packages/cli/index.ts')], - expect.objectContaining({ shell: true }), - ); + const [command, args, options] = spawnMock.mock.calls[0]; + expect(normalizePath(command)).toContain('tsx.cmd'); + expect(args.map(normalizePath)).toEqual([ + expect.stringContaining('packages/cli/index.ts'), + ]); + expect(options).toEqual(expect.objectContaining({ shell: true })); }); });