@@ -16,7 +16,7 @@ import axios from 'axios';
16
16
import { execSync , spawn , spawnSync } from 'child_process' ;
17
17
import { existsSync , readFileSync , unlinkSync , writeFileSync } from 'fs' ;
18
18
import { join } from 'path' ;
19
- import { afterAll , describe } from 'vitest' ;
19
+ import { afterAll , describe , test } from 'vitest' ;
20
20
import {
21
21
assertEnvelopeHeader ,
22
22
assertSentryCheckIn ,
@@ -169,7 +169,11 @@ export function createEsmAndCjsTests(
169
169
cwd : string ,
170
170
scenarioPath : string ,
171
171
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 ,
173
177
options ?: { skipCjs ?: boolean ; skipEsm ?: boolean } ,
174
178
) : void {
175
179
const mjsScenarioPath = join ( cwd , scenarioPath ) ;
@@ -206,16 +210,14 @@ export function createEsmAndCjsTests(
206
210
}
207
211
} ) ;
208
212
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
+ } ) ;
216
217
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' ) ;
219
221
} ) ;
220
222
} ) ;
221
223
}
@@ -245,7 +247,6 @@ export function createRunner(...paths: string[]) {
245
247
let dockerOptions : DockerOptions | undefined ;
246
248
let ensureNoErrorOutput = false ;
247
249
const logs : string [ ] = [ ] ;
248
- const cleanups : VoidFunction [ ] = [ ] ;
249
250
250
251
if ( testPath . endsWith ( '.ts' ) ) {
251
252
flags . push ( '-r' , 'ts-node/register' ) ;
@@ -282,10 +283,6 @@ export function createRunner(...paths: string[]) {
282
283
flags . push ( '--import' , instrumentPath ) ;
283
284
return this ;
284
285
} ,
285
- withCleanup : function ( cleanup : VoidFunction ) {
286
- cleanups . push ( cleanup ) ;
287
- return this ;
288
- } ,
289
286
withMockSentryServer : function ( ) {
290
287
withSentryServer = true ;
291
288
return this ;
@@ -308,13 +305,10 @@ export function createRunner(...paths: string[]) {
308
305
ensureNoErrorOutput = true ;
309
306
return this ;
310
307
} ,
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
+
318
312
const expectedEnvelopeCount = Math . max ( expectedEnvelopes . length , ( expectedEnvelopeHeaders || [ ] ) . length ) ;
319
313
320
314
let envelopeCount = 0 ;
@@ -323,15 +317,13 @@ export function createRunner(...paths: string[]) {
323
317
let child : ReturnType < typeof spawn > | undefined ;
324
318
325
319
function complete ( error ?: Error ) : void {
326
- cleanups . forEach ( cleanup => cleanup ( ) ) ;
320
+ if ( isComplete ) {
321
+ return ;
322
+ }
327
323
324
+ isComplete = true ;
325
+ completeError = error || undefined ;
328
326
child ?. kill ( ) ;
329
- done ?.( normalize ( error ) ) ;
330
- if ( error ) {
331
- reject ( error ) ;
332
- } else {
333
- resolve ( ) ;
334
- }
335
327
}
336
328
337
329
/** Called after each expect callback to check if we're complete */
@@ -526,8 +518,12 @@ export function createRunner(...paths: string[]) {
526
518
. catch ( e => complete ( e ) ) ;
527
519
528
520
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
+ }
531
527
} ,
532
528
childHasExited : function ( ) : boolean {
533
529
return hasExited ;
0 commit comments