Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions scripts/tests/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}));
Expand Down Expand Up @@ -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,
Expand All @@ -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 }));
});
});
Loading