File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,6 +8,22 @@ import Plugin from '../src/index.ts';
88type OnLoadConfig = { filter : RegExp } ;
99type 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+
1127describe ( 'bun-plugin-coffeescript' , ( ) => {
1228 describe ( 'Plugin export' , ( ) => {
1329 test ( 'exports a function' , ( ) => {
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 ( ) => {
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
You can’t perform that action at this time.
0 commit comments