diff --git a/src/plugin-command.ts b/src/plugin-command.ts index 12e6101..10b9e0a 100644 --- a/src/plugin-command.ts +++ b/src/plugin-command.ts @@ -82,6 +82,7 @@ export const buildRunnerCommand = ({ if (fileIndex === -1) return { shouldHandle: false, command }; const nodeImportFlag = `--import=${domSetupPath}`; + const bunPreloadFlag = `--preload ${domSetupPath}`; const denoPreloadFlag = `--preload=${domSetupPath}`; const beforeFile: string[] = []; const afterFile: string[] = []; @@ -114,7 +115,11 @@ export const buildRunnerCommand = ({ const extraImports: string[] = []; if (isNodeRuntime(runtime) && !hasTsx) extraImports.push('--import=tsx'); if (support.supportsNodeLikeImport && !hasNodeLikeDomSetup) { - extraImports.push(nodeImportFlag); + if (isBunRuntime(runtime)) { + extraImports.push(bunPreloadFlag); + } else { + extraImports.push(nodeImportFlag); + } } if (support.supportsDenoPreload && !hasDenoDomSetup) { extraImports.push(denoPreloadFlag); diff --git a/tests/plugin-command.test.ts b/tests/plugin-command.test.ts index ac7e0e7..5871a91 100644 --- a/tests/plugin-command.test.ts +++ b/tests/plugin-command.test.ts @@ -32,6 +32,24 @@ test('buildRunnerCommand injects runtime setup flags', async () => { ]); }); +test('buildRunnerCommand injects --preload for Bun (not --import)', async () => { + const result = buildRunnerCommand({ + runtime: 'bun', + command: ['bun', 'tests/example.test.tsx'], + file: 'tests/example.test.tsx', + domSetupPath: '/tmp/dom-setup.ts', + runtimeOptionArgs: [], + extensions: new Set(['.tsx', '.jsx']), + }); + + assert.strictEqual(result.shouldHandle, true); + assert.deepStrictEqual(result.command, [ + 'bun', + '--preload /tmp/dom-setup.ts', + 'tests/example.test.tsx', + ]); +}); + test('buildRunnerCommand leaves unsupported files unchanged', async () => { const command = ['node', 'tests/example.test.ts']; const result = buildRunnerCommand({