@@ -6,6 +6,19 @@ export async function wrappedTest(
66 testFn : TestSubject ,
77 options : WrappedTestOptions ,
88) : Promise < void > {
9+ // Build Bun test options - pass timeout to Bun's native test runner
10+ // If timeout is 0 or not specified, Bun will use its default 5s timeout
11+ // If we're using custom timeout logic, we need to set a high value for Bun
12+ const bunOptions : { timeout ?: number ; skip ?: boolean } = {
13+ skip : options ?. skip || false ,
14+ } ;
15+
16+ // If a timeout is specified and > 0, pass it to Bun's native timeout
17+ // This makes Bun's timeout and our custom timeout work together
18+ if ( options . timeout && options . timeout > 0 ) {
19+ bunOptions . timeout = options . timeout ;
20+ }
21+
922 return await test ( name , async ( ) => {
1023 // Create wrapped context with step method
1124 const wrappedContext : TestContext = {
@@ -87,7 +100,7 @@ export async function wrappedTest(
87100 } ) ;
88101 let timeoutId : number = - 1 ; // Store the timeout ID
89102 try {
90- if ( options . timeout ) {
103+ if ( options . timeout && options . timeout > 0 ) {
91104 const timeoutPromise = new Promise ( ( _ , reject ) => {
92105 timeoutId = setTimeout ( ( ) => {
93106 reject ( new Error ( "Test timed out" ) ) ;
@@ -98,13 +111,11 @@ export async function wrappedTest(
98111 // No timeout, just await testFn
99112 await options . waitForCallback ? callbackPromise : testFnPromise ;
100113 }
101- } catch ( error ) {
102- throw error ;
103114 } finally {
104- if ( timeoutId ) clearTimeout ( timeoutId ) ;
115+ if ( timeoutId !== - 1 ) clearTimeout ( timeoutId ) ;
105116 // Make sure testFnPromise has completed
106117 await testFnPromise ;
107118 if ( options . waitForCallback ) await callbackPromise ;
108119 }
109- } ) ;
120+ } , bunOptions ) ;
110121}
0 commit comments