15
15
import { SyntheticResult , runSyntheticHandler } from '../../src/index' ;
16
16
import { AssertionError , expect } from 'chai' ;
17
17
import { Request , Response } from 'express' ;
18
+ import { createRequest } from 'node-mocks-http' ;
18
19
import { firstUserErrorStackFrame } from '../../src/handlers' ;
19
20
import ErrorStackParser = require( 'error-stack-parser' ) ;
20
21
@@ -24,13 +25,15 @@ describe('GCM Synthetics Handler', async () => {
24
25
const handler = runSyntheticHandler ( ( ) => true ) ;
25
26
26
27
const runHandler = new Promise ( ( resolve ) => {
28
+ const mockRequest = createRequest ( { } ) ;
29
+
27
30
let mockResponse = {
28
31
send : ( body : any ) => {
29
32
resolve ( body ) ;
30
33
}
31
34
} as Response ;
32
35
33
- handler ( { } as Request , mockResponse ) ;
36
+ handler ( mockRequest , mockResponse ) ;
34
37
} ) ;
35
38
36
39
const syntheticResult = await runHandler as SyntheticResult ;
@@ -53,13 +56,14 @@ describe('GCM Synthetics Handler', async () => {
53
56
} ) ;
54
57
55
58
const runHandler = new Promise ( ( resolve ) => {
59
+ const mockRequest = createRequest ( { } ) ;
56
60
let mockResponse = {
57
61
send : ( body : any ) => {
58
62
resolve ( body ) ;
59
63
}
60
64
} as Response ;
61
65
62
- handler ( { } as Request , mockResponse ) ;
66
+ handler ( mockRequest , mockResponse ) ;
63
67
} ) ;
64
68
65
69
const syntheticResult = await runHandler as SyntheticResult ;
@@ -92,13 +96,14 @@ describe('GCM Synthetics Handler', async () => {
92
96
const handler = runSyntheticHandler ( handlerFunction ) ;
93
97
94
98
const runHandler = new Promise ( ( resolve ) => {
99
+ const mockRequest = createRequest ( { } ) ;
95
100
let mockResponse = {
96
101
send : ( body : any ) => {
97
102
resolve ( body ) ;
98
103
}
99
104
} as Response ;
100
105
101
- handler ( { } as Request , mockResponse ) ;
106
+ handler ( mockRequest , mockResponse ) ;
102
107
} ) ;
103
108
104
109
const syntheticResult = await runHandler as SyntheticResult ;
@@ -153,4 +158,29 @@ describe('GCM Synthetics Handler', async () => {
153
158
' at async MyClass.Function (/user/my/file.js:6:11)' ) ;
154
159
} ) ;
155
160
} ) ;
161
+
162
+ it ( 'has execution id available' , async ( ) => {
163
+ const executionId = 'deadbeefdeadbeefdeadbeefdeadbeef'
164
+ const handler = runSyntheticHandler ( ( args : { executionId : string | undefined } ) => {
165
+ expect ( args . executionId ) . to . equal ( executionId ) ;
166
+ } ) ;
167
+
168
+ const runHandler = new Promise ( ( resolve ) => {
169
+ const mockRequest = createRequest ( {
170
+ headers : { "Synthetic-Execution-Id" : executionId }
171
+ } ) ;
172
+
173
+ let mockResponse = {
174
+ send : ( body : any ) => {
175
+ resolve ( body ) ;
176
+ }
177
+ } as Response ;
178
+
179
+ handler ( mockRequest , mockResponse ) ;
180
+ } ) ;
181
+
182
+ const syntheticResult = await runHandler as SyntheticResult ;
183
+ expect ( syntheticResult ?. synthetic_generic_result_v1 ?. ok ) . to . be . true ;
184
+ expect ( syntheticResult ?. synthetic_generic_result_v1 ?. generic_error ) . to . be . undefined ;
185
+ } ) ;
156
186
} ) ;
0 commit comments