11/* eslint-disable @typescript-eslint/no-unsafe-member-access */
22import * as Sentry from '@sentry/node' ;
3+ import { EnvelopeItemType } from '@sentry/types' ;
34import { logger , parseSemver } from '@sentry/utils' ;
45import axios from 'axios' ;
56import { Express } from 'express' ;
@@ -24,8 +25,8 @@ export type DataCollectorOptions = {
2425 // Whether to stop the server after the requests have been intercepted
2526 endServer ?: boolean ;
2627
27- // Type of the envelopes to capture
28- envelopeType ?: string ;
28+ // Type(s) of the envelopes to capture
29+ envelopeType ?: EnvelopeItemType | EnvelopeItemType [ ] ;
2930} ;
3031
3132/**
@@ -97,11 +98,16 @@ export const getMultipleEnvelopeRequest = async (
9798 config : TestServerConfig ,
9899 options : DataCollectorOptions ,
99100) : Promise < Record < string , unknown > [ ] [ ] > => {
101+ const envelopeTypeArray =
102+ typeof options . envelopeType === 'string'
103+ ? [ options . envelopeType ]
104+ : options . envelopeType || ( [ 'event' ] as EnvelopeItemType [ ] ) ;
105+
100106 const resProm = setupNock (
101107 config . server ,
102108 options . count || 1 ,
103109 typeof options . endServer === 'undefined' ? true : options . endServer ,
104- options . envelopeType || 'event' ,
110+ envelopeTypeArray ,
105111 ) ;
106112
107113 void makeRequest ( options . method || 'get' , config . url ) ;
@@ -112,7 +118,7 @@ const setupNock = async (
112118 server : http . Server ,
113119 count : number ,
114120 endServer : boolean ,
115- envelopeType : string ,
121+ envelopeType : EnvelopeItemType [ ] ,
116122) : Promise < Record < string , unknown > [ ] [ ] > => {
117123 return new Promise ( resolve => {
118124 const envelopes : Record < string , unknown > [ ] [ ] = [ ] ;
@@ -121,17 +127,21 @@ const setupNock = async (
121127 . post ( '/api/1337/envelope/' , body => {
122128 const envelope = parseEnvelope ( body ) ;
123129
124- if ( envelope [ 1 ] . type === envelopeType ) {
130+ if ( envelopeType . includes ( envelope [ 1 ] . type as EnvelopeItemType ) ) {
125131 envelopes . push ( envelope ) ;
126132 } else {
127133 return false ;
128134 }
129135
130136 if ( count === envelopes . length ) {
131137 nock . removeInterceptor ( mock ) ;
132- nock . cleanAll ( ) ;
133138
134139 if ( endServer ) {
140+ // Cleaning nock only before the server is closed,
141+ // not to break tests that use simultaneous requests to the server.
142+ // Ex: Remix scope bleed tests.
143+ nock . cleanAll ( ) ;
144+
135145 server . close ( ( ) => {
136146 resolve ( envelopes ) ;
137147 } ) ;
0 commit comments