|
1 | 1 | import { beforeAll, afterAll, beforeEach, describe, expect, it, vi } from 'vitest'; |
2 | 2 | import type { SpawnOptions } from 'child_process'; |
| 3 | +import { join } from 'node:path'; |
| 4 | +import { projectPath } from '@/projectPath'; |
3 | 5 |
|
4 | 6 | const spawnMock = vi.fn((..._args: any[]) => ({ pid: 12345 } as any)); |
5 | 7 |
|
@@ -31,6 +33,10 @@ function getSpawnOptionsOrThrow(): SpawnOptions { |
31 | 33 | return options; |
32 | 34 | } |
33 | 35 |
|
| 36 | +function normalizePath(value: string): string { |
| 37 | + return value.replace(/\\/g, '/'); |
| 38 | +} |
| 39 | + |
34 | 40 | describe('spawnHappyCLI windowsHide behavior', () => { |
35 | 41 | beforeAll(() => { |
36 | 42 | if (!originalPlatformDescriptor?.configurable) { |
@@ -97,17 +103,19 @@ describe('spawnHappyCLI windowsHide behavior', () => { |
97 | 103 |
|
98 | 104 | it('forces Bun child processes to run with the cli project root as cwd', async () => { |
99 | 105 | const { getHappyCliCommand } = await import('./spawnHappyCLI'); |
| 106 | + const expectedProjectRoot = projectPath(); |
| 107 | + const expectedEntrypoint = join(expectedProjectRoot, 'src', 'index.ts'); |
100 | 108 |
|
101 | 109 | const command = getHappyCliCommand(['mcp', '--url', 'http://127.0.0.1:1234/']); |
102 | 110 | const isBunRuntime = Boolean((process.versions as Record<string, string | undefined>).bun); |
103 | 111 |
|
104 | 112 | expect(command.command).toBe(process.execPath); |
105 | 113 | if (isBunRuntime) { |
106 | 114 | expect(command.args[0]).toBe('--cwd'); |
107 | | - expect(command.args[1].replace(/\\/g, '/')).toMatch(/\/hapi\/cli$/); |
108 | | - expect(command.args[2].replace(/\\/g, '/')).toMatch(/\/hapi\/cli\/src\/index\.ts$/); |
| 115 | + expect(normalizePath(command.args[1])).toBe(normalizePath(expectedProjectRoot)); |
| 116 | + expect(normalizePath(command.args[2])).toBe(normalizePath(expectedEntrypoint)); |
109 | 117 | } else { |
110 | | - expect(command.args.some((arg) => arg.replace(/\\/g, '/').endsWith('/hapi/cli/src/index.ts'))).toBe(true); |
| 118 | + expect(command.args.some((arg) => normalizePath(arg) === normalizePath(expectedEntrypoint))).toBe(true); |
111 | 119 | } |
112 | 120 | }); |
113 | 121 |
|
|
0 commit comments