@@ -5,15 +5,15 @@ import nock from 'nock';
5
5
import * as path from 'path' ;
6
6
import { getPortPromise } from 'portfinder' ;
7
7
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 => {
9
9
expect ( actual ) . toMatchObject ( {
10
10
event_id : expect . any ( String ) ,
11
11
timestamp : expect . any ( Number ) ,
12
12
...expected ,
13
13
} ) ;
14
14
} ;
15
15
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 => {
17
17
expect ( actual ) . toMatchObject ( {
18
18
event_id : expect . any ( String ) ,
19
19
timestamp : expect . any ( Number ) ,
@@ -24,24 +24,34 @@ const assertSentryTransaction = (actual: Record<string, unknown>, expected: Reco
24
24
} ) ;
25
25
} ;
26
26
27
- const parseEnvelope = ( body : string ) : Array < Record < string , unknown > > => {
27
+ export const parseEnvelope = ( body : string ) : Array < Record < string , unknown > > => {
28
28
return body . split ( '\n' ) . map ( e => JSON . parse ( e ) ) ;
29
29
} ;
30
30
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
+
32
34
return new Promise ( resolve => {
33
35
nock ( 'https://dsn.ingest.sentry.io' )
34
36
. post ( '/api/1337/store/' , body => {
35
- resolve ( body ) ;
37
+ events . push ( body ) ;
38
+
39
+ if ( events . length === count ) {
40
+ resolve ( events ) ;
41
+ }
36
42
return true ;
37
43
} )
44
+ . times ( 7 )
38
45
. reply ( 200 ) ;
39
-
40
46
http . get ( url ) ;
41
47
} ) ;
42
48
} ;
43
49
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 > > > => {
45
55
return new Promise ( resolve => {
46
56
nock ( 'https://dsn.ingest.sentry.io' )
47
57
. post ( '/api/1337/envelope/' , body => {
@@ -55,7 +65,7 @@ const getEnvelopeRequest = async (url: string): Promise<Array<Record<string, unk
55
65
} ) ;
56
66
} ;
57
67
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 > {
59
69
const port = await getPortPromise ( ) ;
60
70
const url = `http://localhost:${ port } /test` ;
61
71
const defaultServerPath = path . resolve ( process . cwd ( ) , 'utils' , 'defaults' , 'server' ) ;
@@ -77,5 +87,3 @@ async function runServer(testDir: string, serverPath?: string, scenarioPath?: st
77
87
78
88
return url ;
79
89
}
80
-
81
- export { assertSentryEvent , assertSentryTransaction , parseEnvelope , getEventRequest , getEnvelopeRequest , runServer } ;
0 commit comments