Skip to content

Commit 999491b

Browse files
committed
Fix test
1 parent 74520a0 commit 999491b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

cli/src/utils/spawnHappyCLI.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { beforeAll, afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
22
import type { SpawnOptions } from 'child_process';
3+
import { join } from 'node:path';
4+
import { projectPath } from '@/projectPath';
35

46
const spawnMock = vi.fn((..._args: any[]) => ({ pid: 12345 } as any));
57

@@ -31,6 +33,10 @@ function getSpawnOptionsOrThrow(): SpawnOptions {
3133
return options;
3234
}
3335

36+
function normalizePath(value: string): string {
37+
return value.replace(/\\/g, '/');
38+
}
39+
3440
describe('spawnHappyCLI windowsHide behavior', () => {
3541
beforeAll(() => {
3642
if (!originalPlatformDescriptor?.configurable) {
@@ -97,17 +103,19 @@ describe('spawnHappyCLI windowsHide behavior', () => {
97103

98104
it('forces Bun child processes to run with the cli project root as cwd', async () => {
99105
const { getHappyCliCommand } = await import('./spawnHappyCLI');
106+
const expectedProjectRoot = projectPath();
107+
const expectedEntrypoint = join(expectedProjectRoot, 'src', 'index.ts');
100108

101109
const command = getHappyCliCommand(['mcp', '--url', 'http://127.0.0.1:1234/']);
102110
const isBunRuntime = Boolean((process.versions as Record<string, string | undefined>).bun);
103111

104112
expect(command.command).toBe(process.execPath);
105113
if (isBunRuntime) {
106114
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));
109117
} 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);
111119
}
112120
});
113121

0 commit comments

Comments
 (0)