Skip to content

Commit 4a457ff

Browse files
Fix v2 server test (#3795)
Co-authored-by: app-token-issuer-data-feeds[bot] <134377064+app-token-issuer-data-feeds[bot]@users.noreply.github.com>
1 parent b6654cf commit 4a457ff

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/core/bootstrap/test/unit/server.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ const executeResponse: AdapterResponse = {
4545
const execute: Execute = jest.fn(async () => executeResponse)
4646

4747
describe('server', () => {
48+
let serverAddress: string
49+
4850
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}`
5054

5155
// wait for metrics listener
5256
await spies[0].mock.results[0].value
@@ -60,7 +64,7 @@ describe('server', () => {
6064
})
6165

6266
it('healthcheck returns OK', async () => {
63-
const response = await axios.get('http://localhost:8080/health')
67+
const response = await axios.get(`${serverAddress}/health`)
6468
expect(response.data.message).toBe('OK')
6569
})
6670

@@ -70,7 +74,7 @@ describe('server', () => {
7074
})
7175

7276
it('handles simple request', async () => {
73-
const response = await axios.post('http://localhost:8080/', {
77+
const response = await axios.post(`${serverAddress}/`, {
7478
data: {
7579
number: 123,
7680
},
@@ -82,7 +86,7 @@ describe('server', () => {
8286
await expect(
8387
async () =>
8488
await axios.post(
85-
'http://localhost:8080/',
89+
`${serverAddress}/`,
8690
{
8791
data: {
8892
number: 123,
@@ -99,14 +103,14 @@ describe('server', () => {
99103

100104
it('returns OK on smoke endpoint when test payload is default (empty)', async () => {
101105
mockTestPayload.isDefault = true
102-
const response = await axios.get('http://localhost:8080/smoke')
106+
const response = await axios.get(`${serverAddress}/smoke`)
103107
expect(response.data).toBe('OK')
104108
})
105109

106110
it('returns OK on smoke endpoint when all requests are successful', async () => {
107111
mockTestPayload.isDefault = false
108112
mockTestPayload.requests = [{}, {}]
109-
const response = await axios.get('http://localhost:8080/smoke')
113+
const response = await axios.get(`${serverAddress}/smoke`)
110114
expect(response.data).toBe('OK')
111115
})
112116
})

0 commit comments

Comments
 (0)