@@ -5,15 +5,15 @@ import nock from 'nock';
55import * as path from 'path' ;
66import { getPortPromise } from 'portfinder' ;
77
8- const assertSentryEvent = ( actual : Record < string , unknown > , expected : Record < string , unknown > ) : void => {
8+ export const assertSentryEvent = ( actual : Record < string , unknown > , expected : Record < string , unknown > ) : void => {
99 expect ( actual ) . toMatchObject ( {
1010 event_id : expect . any ( String ) ,
1111 timestamp : expect . any ( Number ) ,
1212 ...expected ,
1313 } ) ;
1414} ;
1515
16- const assertSentryTransaction = ( actual : Record < string , unknown > , expected : Record < string , unknown > ) : void => {
16+ export const assertSentryTransaction = ( actual : Record < string , unknown > , expected : Record < string , unknown > ) : void => {
1717 expect ( actual ) . toMatchObject ( {
1818 event_id : expect . any ( String ) ,
1919 timestamp : expect . any ( Number ) ,
@@ -24,24 +24,34 @@ const assertSentryTransaction = (actual: Record<string, unknown>, expected: Reco
2424 } ) ;
2525} ;
2626
27- const parseEnvelope = ( body : string ) : Array < Record < string , unknown > > => {
27+ export const parseEnvelope = ( body : string ) : Array < Record < string , unknown > > => {
2828 return body . split ( '\n' ) . map ( e => JSON . parse ( e ) ) ;
2929} ;
3030
31- const getEventRequest = async ( url : string ) : Promise < Record < string , unknown > > => {
31+ export const getMultipleEventRequests = async ( url : string , count : number ) : Promise < Array < Record < string , unknown > > > => {
32+ const events : Record < string , unknown > [ ] = [ ] ;
33+
3234 return new Promise ( resolve => {
3335 nock ( 'https://dsn.ingest.sentry.io' )
3436 . post ( '/api/1337/store/' , body => {
35- resolve ( body ) ;
37+ events . push ( body ) ;
38+
39+ if ( events . length === count ) {
40+ resolve ( events ) ;
41+ }
3642 return true ;
3743 } )
44+ . times ( 7 )
3845 . reply ( 200 ) ;
39-
4046 http . get ( url ) ;
4147 } ) ;
4248} ;
4349
44- const getEnvelopeRequest = async ( url : string ) : Promise < Array < Record < string , unknown > > > => {
50+ export const getEventRequest = async ( url : string ) : Promise < Record < string , unknown > > => {
51+ return ( await getMultipleEventRequests ( url , 1 ) ) [ 0 ] ;
52+ } ;
53+
54+ export const getEnvelopeRequest = async ( url : string ) : Promise < Array < Record < string , unknown > > > => {
4555 return new Promise ( resolve => {
4656 nock ( 'https://dsn.ingest.sentry.io' )
4757 . post ( '/api/1337/envelope/' , body => {
@@ -55,7 +65,7 @@ const getEnvelopeRequest = async (url: string): Promise<Array<Record<string, unk
5565 } ) ;
5666} ;
5767
58- async function runServer ( testDir : string , serverPath ?: string , scenarioPath ?: string ) : Promise < string > {
68+ export async function runServer ( testDir : string , serverPath ?: string , scenarioPath ?: string ) : Promise < string > {
5969 const port = await getPortPromise ( ) ;
6070 const url = `http://localhost:${ port } /test` ;
6171 const defaultServerPath = path . resolve ( process . cwd ( ) , 'utils' , 'defaults' , 'server' ) ;
@@ -77,5 +87,3 @@ async function runServer(testDir: string, serverPath?: string, scenarioPath?: st
7787
7888 return url ;
7989}
80-
81- export { assertSentryEvent , assertSentryTransaction , parseEnvelope , getEventRequest , getEnvelopeRequest , runServer } ;
0 commit comments