@@ -3,29 +3,32 @@ import { spawn } from 'child_process'
33import AgentNotFoundError from '../src/Error/AgentNotFoundError'
44import BadConfigurationError from '../src/Error/BadConfigurationError'
55import Client from '../src/Client'
6- import RedirectResponse from '../src/HttpMessage/RedirectResponse'
76import Request from '../src/HttpMessage/Request'
87import Response from '../src/HttpMessage/Response'
98
109let agent = null
1110let client = null
1211
1312beforeAll ( done => {
14- agent = spawn ( './node_modules/.bin/babel- node' , [ __dirname + '/../src/Resources/fake_agent.js' ] , { detached : true } )
13+ agent = spawn ( 'node' , [ '-r' , 'esm' , __dirname + '/../src/Resources/fake_agent.js' ] , { detached : true } )
1514 agent . stdout . on ( 'data' , ( ) => done ( ) )
1615
1716 client = new Client ( { 'fake_agent' : 'tcp://localhost:3100' } )
1817} )
1918
2019afterAll ( ( ) => {
21- process . kill ( - agent . pid )
20+ try {
21+ process . kill ( - agent . pid )
22+ } catch ( error ) {
23+ // Fake agent already stopped
24+ }
2225} )
2326
2427it ( 'find redirect when rule exist' , async ( ) => {
2528 const request = createRequest ( { path : '/foo' } )
2629 const response = await client . findRedirect ( request )
2730
28- expect ( response ) . toBeInstanceOf ( RedirectResponse )
31+ expect ( response ) . toBeInstanceOf ( Response )
2932 expect ( response . statusCode ) . toBe ( 301 )
3033 expect ( response . location ) . toBe ( '/bar' )
3134} )
@@ -42,13 +45,13 @@ it('find twice redirect when rule exist', async () => {
4245 const request = createRequest ( { path : '/foo' } )
4346 let response = await client . findRedirect ( request )
4447
45- expect ( response ) . toBeInstanceOf ( RedirectResponse )
48+ expect ( response ) . toBeInstanceOf ( Response )
4649 expect ( response . statusCode ) . toBe ( 301 )
4750 expect ( response . location ) . toBe ( '/bar' )
4851
4952 response = await client . findRedirect ( request )
5053
51- expect ( response ) . toBeInstanceOf ( RedirectResponse )
54+ expect ( response ) . toBeInstanceOf ( Response )
5255 expect ( response . statusCode ) . toBe ( 301 )
5356 expect ( response . location ) . toBe ( '/bar' )
5457} )
@@ -107,7 +110,7 @@ it('find redirect in multiple hosts array', async () => {
107110 const request = createRequest ( { path : '/foo' } )
108111 const response = await customClient . findRedirect ( request )
109112
110- expect ( response ) . toBeInstanceOf ( RedirectResponse )
113+ expect ( response ) . toBeInstanceOf ( Response )
111114 expect ( response . statusCode ) . toBe ( 301 )
112115 expect ( response . location ) . toBe ( '/bar' )
113116} )
@@ -119,7 +122,7 @@ it('find nothing when agent goes down', async () => {
119122 return new Promise ( resolve => {
120123 const env = Object . create ( process . env )
121124 env . RIO_PORT = 3101
122- customAgent = spawn ( './node_modules/.bin/babel- node' , [ __dirname + '/../src/Resources/fake_agent.js' ] , { env : env , detached : true } )
125+ customAgent = spawn ( 'node' , [ '-r' , 'esm' , __dirname + '/../src/Resources/fake_agent.js' ] , { env : env , detached : true } )
123126 customAgent . stdout . on ( 'data' , ( ) => resolve ( ) )
124127 customAgent . stderr . on ( 'data' , data => console . log ( data . toString ( ) ) )
125128 } )
@@ -134,11 +137,15 @@ it('find nothing when agent goes down', async () => {
134137 const request = createRequest ( { path : '/foo' } )
135138 let response = await customClient . findRedirect ( request )
136139
137- expect ( response ) . toBeInstanceOf ( RedirectResponse )
140+ expect ( response ) . toBeInstanceOf ( Response )
138141 expect ( response . statusCode ) . toBe ( 301 )
139142 expect ( response . location ) . toBe ( '/bar' )
140143
141- process . kill ( - customAgent . pid )
144+ try {
145+ process . kill ( - customAgent . pid )
146+ } catch ( error ) {
147+ // Fake agent already stopped
148+ }
142149
143150 await expect ( customClient . findRedirect ( request ) ) . resolves . toBeFalsy ( )
144151} )
0 commit comments