@@ -16,7 +16,7 @@ import axios from 'axios';
1616import { execSync , spawn , spawnSync } from 'child_process' ;
1717import { existsSync , readFileSync , unlinkSync , writeFileSync } from 'fs' ;
1818import { join } from 'path' ;
19- import { afterAll , describe } from 'vitest' ;
19+ import { afterAll , describe , test } from 'vitest' ;
2020import {
2121 assertEnvelopeHeader ,
2222 assertSentryCheckIn ,
@@ -169,7 +169,11 @@ export function createEsmAndCjsTests(
169169 cwd : string ,
170170 scenarioPath : string ,
171171 instrumentPath : string ,
172- callback : ( createTestRunner : ( ) => ReturnType < typeof createRunner > , mode : 'esm' | 'cjs' ) => void ,
172+ callback : (
173+ createTestRunner : ( ) => ReturnType < typeof createRunner > ,
174+ testFn : typeof test | typeof test . fails ,
175+ mode : 'esm' | 'cjs' ,
176+ ) => void ,
173177 options ?: { skipCjs ?: boolean ; skipEsm ?: boolean } ,
174178) : void {
175179 const mjsScenarioPath = join ( cwd , scenarioPath ) ;
@@ -206,16 +210,14 @@ export function createEsmAndCjsTests(
206210 }
207211 } ) ;
208212
209- const scenarios : [ mode : 'esm' | 'cjs' , getRunner : ( ) => ReturnType < typeof createRunner > ] [ ] = [ ] ;
210- if ( ! options ?. skipEsm ) {
211- scenarios . push ( [ 'esm' , ( ) => createRunner ( mjsScenarioPath ) . withFlags ( '--import' , mjsInstrumentPath ) ] ) ;
212- }
213- if ( ! options ?. skipCjs ) {
214- scenarios . push ( [ 'cjs' , ( ) => createRunner ( cjsScenarioPath ) . withFlags ( '--require' , cjsInstrumentPath ) ] ) ;
215- }
213+ describe ( 'esm' , ( ) => {
214+ const testFn = options ?. skipEsm ? test . fails : test ;
215+ callback ( ( ) => createRunner ( mjsScenarioPath ) . withFlags ( '--import' , mjsInstrumentPath ) , testFn , 'esm' ) ;
216+ } ) ;
216217
217- describe . each ( scenarios ) ( '%s' , ( mode , getRunner ) => {
218- callback ( getRunner , mode ) ;
218+ describe ( 'cjs' , ( ) => {
219+ const testFn = options ?. skipCjs ? test . fails : test ;
220+ callback ( ( ) => createRunner ( cjsScenarioPath ) . withFlags ( '--require' , cjsInstrumentPath ) , testFn , 'cjs' ) ;
219221 } ) ;
220222 } ) ;
221223}
@@ -245,7 +247,6 @@ export function createRunner(...paths: string[]) {
245247 let dockerOptions : DockerOptions | undefined ;
246248 let ensureNoErrorOutput = false ;
247249 const logs : string [ ] = [ ] ;
248- const cleanups : VoidFunction [ ] = [ ] ;
249250
250251 if ( testPath . endsWith ( '.ts' ) ) {
251252 flags . push ( '-r' , 'ts-node/register' ) ;
@@ -282,10 +283,6 @@ export function createRunner(...paths: string[]) {
282283 flags . push ( '--import' , instrumentPath ) ;
283284 return this ;
284285 } ,
285- withCleanup : function ( cleanup : VoidFunction ) {
286- cleanups . push ( cleanup ) ;
287- return this ;
288- } ,
289286 withMockSentryServer : function ( ) {
290287 withSentryServer = true ;
291288 return this ;
@@ -308,13 +305,10 @@ export function createRunner(...paths: string[]) {
308305 ensureNoErrorOutput = true ;
309306 return this ;
310307 } ,
311- start : function ( done ?: ( e ?: unknown ) => void ) : StartResult {
312- let resolve : ( value : void ) => void ;
313- let reject : ( reason ?: unknown ) => void ;
314- const completePromise = new Promise < void > ( ( res , rej ) => {
315- resolve = res ;
316- reject = rej ;
317- } ) ;
308+ start : function ( ) : StartResult {
309+ let isComplete = false ;
310+ let completeError : Error | undefined ;
311+
318312 const expectedEnvelopeCount = Math . max ( expectedEnvelopes . length , ( expectedEnvelopeHeaders || [ ] ) . length ) ;
319313
320314 let envelopeCount = 0 ;
@@ -323,15 +317,13 @@ export function createRunner(...paths: string[]) {
323317 let child : ReturnType < typeof spawn > | undefined ;
324318
325319 function complete ( error ?: Error ) : void {
326- cleanups . forEach ( cleanup => cleanup ( ) ) ;
320+ if ( isComplete ) {
321+ return ;
322+ }
327323
324+ isComplete = true ;
325+ completeError = error || undefined ;
328326 child ?. kill ( ) ;
329- done ?.( normalize ( error ) ) ;
330- if ( error ) {
331- reject ( error ) ;
332- } else {
333- resolve ( ) ;
334- }
335327 }
336328
337329 /** Called after each expect callback to check if we're complete */
@@ -526,8 +518,12 @@ export function createRunner(...paths: string[]) {
526518 . catch ( e => complete ( e ) ) ;
527519
528520 return {
529- completed : function ( ) : Promise < void > {
530- return completePromise ;
521+ completed : async function ( ) : Promise < void > {
522+ await waitFor ( ( ) => isComplete ) ;
523+
524+ if ( completeError ) {
525+ throw completeError ;
526+ }
531527 } ,
532528 childHasExited : function ( ) : boolean {
533529 return hasExited ;
0 commit comments