mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
fix(test): isolate integration tests from production hub via temp hub globalSetup (#734)
This commit is contained in:
@@ -37,6 +37,7 @@ vi.mock('@/projectPath', () => ({
|
||||
const originalPlatformDescriptor = Object.getOwnPropertyDescriptor(process, 'platform');
|
||||
const originalInvokedCwd = process.env.HAPI_INVOKED_CWD;
|
||||
const originalCliExecutable = process.env.HAPI_CLI_EXECUTABLE;
|
||||
const originalBunExec = process.env.HAPI_BUN_EXEC;
|
||||
|
||||
function setPlatform(value: string) {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
@@ -78,6 +79,11 @@ describe('spawnHappyCLI windowsHide behavior', () => {
|
||||
} else {
|
||||
process.env.HAPI_CLI_EXECUTABLE = originalCliExecutable;
|
||||
}
|
||||
if (originalBunExec === undefined) {
|
||||
delete process.env.HAPI_BUN_EXEC;
|
||||
} else {
|
||||
process.env.HAPI_BUN_EXEC = originalBunExec;
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
@@ -129,6 +135,8 @@ describe('spawnHappyCLI windowsHide behavior', () => {
|
||||
});
|
||||
|
||||
it('forces Bun child processes to run with the cli project root as cwd', async () => {
|
||||
// Clear the test-isolation override so we test the pure runtime behaviour
|
||||
delete process.env.HAPI_BUN_EXEC;
|
||||
const { getHappyCliCommand } = await import('./spawnHappyCLI');
|
||||
|
||||
const command = getHappyCliCommand(['mcp', '--url', 'http://127.0.0.1:1234/']);
|
||||
|
||||
@@ -116,6 +116,16 @@ export function getHappyCliCommand(args: string[]): HappyCliCommand {
|
||||
};
|
||||
}
|
||||
|
||||
// When vitest runs under Node.js, HAPI_BUN_EXEC can point to the bun binary so that
|
||||
// spawned CLI child processes still run under bun (which is required for TypeScript entrypoints).
|
||||
const bunExecOverride = process.env['HAPI_BUN_EXEC']?.trim();
|
||||
if (bunExecOverride && isCrossPlatformAbsolutePath(bunExecOverride) && existsSync(bunExecOverride)) {
|
||||
return {
|
||||
command: bunExecOverride,
|
||||
args: ['--cwd', projectRoot, entrypoint, ...args]
|
||||
};
|
||||
}
|
||||
|
||||
// Node.js fallback: preserve execArgv (for compatibility)
|
||||
return {
|
||||
command: process.execPath,
|
||||
|
||||
Reference in New Issue
Block a user