Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/plugin-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions tests/plugin-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading