File tree Expand file tree Collapse file tree 2 files changed +48
-46
lines changed
node-integration-tests/utils Expand file tree Collapse file tree 2 files changed +48
-46
lines changed Original file line number Diff line number Diff line change 1+ import express from 'express' ;
2+ import type { AddressInfo } from 'net' ;
3+
4+ type HeaderAssertCallback = ( headers : Record < string , string | string [ ] | undefined > ) => void ;
5+
6+ /** Creates a test server that can be used to check headers */
7+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
8+ export function createTestServer ( ) {
9+ const gets : Array < [ string , HeaderAssertCallback , number ] > = [ ] ;
10+ let error : unknown | undefined ;
11+
12+ return {
13+ get : function ( path : string , callback : HeaderAssertCallback , result = 200 ) {
14+ gets . push ( [ path , callback , result ] ) ;
15+ return this ;
16+ } ,
17+ start : async ( ) : Promise < [ string , ( ) => void ] > => {
18+ const app = express ( ) ;
19+
20+ for ( const [ path , callback , result ] of gets ) {
21+ app . get ( path , ( req , res ) => {
22+ try {
23+ callback ( req . headers ) ;
24+ } catch ( e ) {
25+ error = e ;
26+ }
27+
28+ res . status ( result ) . send ( ) ;
29+ } ) ;
30+ }
31+
32+ return new Promise ( resolve => {
33+ const server = app . listen ( 0 , ( ) => {
34+ const address = server . address ( ) as AddressInfo ;
35+ resolve ( [
36+ `http://localhost:${ address . port } ` ,
37+ ( ) => {
38+ server . close ( ) ;
39+ if ( error ) {
40+ throw error ;
41+ }
42+ } ,
43+ ] ) ;
44+ } ) ;
45+ } ) ;
46+ } ,
47+ } ;
48+ }
Original file line number Diff line number Diff line change @@ -37,49 +37,3 @@ export function createBasicSentryServer(onEnvelope: (env: Envelope) => void): Pr
3737 } ) ;
3838 } ) ;
3939}
40-
41- type HeaderAssertCallback = ( headers : Record < string , string | string [ ] | undefined > ) => void ;
42-
43- /** Creates a test server that can be used to check headers */
44- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
45- export function createTestServer ( ) {
46- const gets : Array < [ string , HeaderAssertCallback , number ] > = [ ] ;
47- let error : unknown | undefined ;
48-
49- return {
50- get : function ( path : string , callback : HeaderAssertCallback , result = 200 ) {
51- gets . push ( [ path , callback , result ] ) ;
52- return this ;
53- } ,
54- start : async ( ) : Promise < [ string , ( ) => void ] > => {
55- const app = express ( ) ;
56-
57- for ( const [ path , callback , result ] of gets ) {
58- app . get ( path , ( req , res ) => {
59- try {
60- callback ( req . headers ) ;
61- } catch ( e ) {
62- error = e ;
63- }
64-
65- res . status ( result ) . send ( ) ;
66- } ) ;
67- }
68-
69- return new Promise ( resolve => {
70- const server = app . listen ( 0 , ( ) => {
71- const address = server . address ( ) as AddressInfo ;
72- resolve ( [
73- `http://localhost:${ address . port } ` ,
74- ( ) => {
75- server . close ( ) ;
76- if ( error ) {
77- throw error ;
78- }
79- } ,
80- ] ) ;
81- } ) ;
82- } ) ;
83- } ,
84- } ;
85- }
You can’t perform that action at this time.
0 commit comments