Skip to content

Commit bc15c21

Browse files
committed
test: refactor tests to be compatible with bun 1.0
1 parent 9477f75 commit bc15c21

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

tests/index.spec.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ import Plugin from '../src/index.ts';
88
type OnLoadConfig = { filter: RegExp };
99
type OnLoadCallback = (args: { path: string }) => Promise<{ contents: string; loader: string }>;
1010

11+
/**
12+
* Helper to test async rejections in Bun 1.0+
13+
* Bun 1.0 doesn't support expect().rejects.toThrow(), so we use try-catch
14+
*/
15+
async function expectToReject(promise: Promise<unknown>): Promise<void> {
16+
let didThrow = false;
17+
18+
try {
19+
await promise;
20+
} catch {
21+
didThrow = true;
22+
}
23+
24+
expect(didThrow).toBe(true);
25+
}
26+
1127
describe('bun-plugin-coffeescript', () => {
1228
describe('Plugin export', () => {
1329
test('exports a function', () => {
@@ -386,7 +402,7 @@ if
386402

387403
// Should throw a compilation error
388404
if (!onLoadCallback) throw new Error('onLoad was not called');
389-
await expect(onLoadCallback({ path: coffeeFile })).rejects.toThrow();
405+
await expectToReject(onLoadCallback({ path: coffeeFile }));
390406
});
391407

392408
test('handles missing file', async () => {
@@ -406,7 +422,7 @@ if
406422

407423
// Should throw a file read error
408424
if (!onLoadCallback) throw new Error('onLoad was not called');
409-
await expect(onLoadCallback({ path: nonExistentFile })).rejects.toThrow();
425+
await expectToReject(onLoadCallback({ path: nonExistentFile }));
410426
});
411427
});
412428

0 commit comments

Comments
 (0)