@@ -45,8 +45,12 @@ const executeResponse: AdapterResponse = {
45
45
const execute : Execute = jest . fn ( async ( ) => executeResponse )
46
46
47
47
describe ( 'server' , ( ) => {
48
+ let serverAddress : string
49
+
48
50
beforeAll ( async ( ) => {
49
- await expose ( { } , execute ) . server ( )
51
+ const serverPort = ( ( await expose ( { } , execute ) . server ( ) ) . server . address ( ) as { port : number } )
52
+ . port
53
+ serverAddress = `http://localhost:${ serverPort } `
50
54
51
55
// wait for metrics listener
52
56
await spies [ 0 ] . mock . results [ 0 ] . value
@@ -60,7 +64,7 @@ describe('server', () => {
60
64
} )
61
65
62
66
it ( 'healthcheck returns OK' , async ( ) => {
63
- const response = await axios . get ( 'http://localhost:8080/ health' )
67
+ const response = await axios . get ( ` ${ serverAddress } / health` )
64
68
expect ( response . data . message ) . toBe ( 'OK' )
65
69
} )
66
70
@@ -70,7 +74,7 @@ describe('server', () => {
70
74
} )
71
75
72
76
it ( 'handles simple request' , async ( ) => {
73
- const response = await axios . post ( 'http://localhost:8080/' , {
77
+ const response = await axios . post ( ` ${ serverAddress } /` , {
74
78
data : {
75
79
number : 123 ,
76
80
} ,
@@ -82,7 +86,7 @@ describe('server', () => {
82
86
await expect (
83
87
async ( ) =>
84
88
await axios . post (
85
- 'http://localhost:8080/' ,
89
+ ` ${ serverAddress } /` ,
86
90
{
87
91
data : {
88
92
number : 123 ,
@@ -99,14 +103,14 @@ describe('server', () => {
99
103
100
104
it ( 'returns OK on smoke endpoint when test payload is default (empty)' , async ( ) => {
101
105
mockTestPayload . isDefault = true
102
- const response = await axios . get ( 'http://localhost:8080/ smoke' )
106
+ const response = await axios . get ( ` ${ serverAddress } / smoke` )
103
107
expect ( response . data ) . toBe ( 'OK' )
104
108
} )
105
109
106
110
it ( 'returns OK on smoke endpoint when all requests are successful' , async ( ) => {
107
111
mockTestPayload . isDefault = false
108
112
mockTestPayload . requests = [ { } , { } ]
109
- const response = await axios . get ( 'http://localhost:8080/ smoke' )
113
+ const response = await axios . get ( ` ${ serverAddress } / smoke` )
110
114
expect ( response . data ) . toBe ( 'OK' )
111
115
} )
112
116
} )
0 commit comments