Skip to content

Commit

Permalink
tests: check if context is present
Browse files Browse the repository at this point in the history
  • Loading branch information
DTrombett committed Nov 21, 2024
1 parent 5dbe136 commit 077041e
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion test/interceptors/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { createServer } = require('node:http')
const { once } = require('node:events')

const { Client, interceptors } = require('../..')
const { retry } = interceptors
const { retry, redirect } = interceptors

test('Should retry status code', async t => {
t = tspl(t, { plan: 4 })
Expand Down Expand Up @@ -243,6 +243,41 @@ test('Should retry with defaults', async t => {
t.equal(await response.body.text(), 'hello world!')
})

test('Should pass context from other interceptors', async t => {
t = tspl(t, { plan: 2 })

const server = createServer()
const requestOptions = {
method: 'GET',
path: '/'
}

server.on('request', (req, res) => {
res.writeHead(200)
res.end('hello world!')
})

server.listen(0)

await once(server, 'listening')

const client = new Client(
`http://localhost:${server.address().port}`
).compose(redirect({ maxRedirections: 1 }), retry())

after(async () => {
await client.close()
server.close()

await once(server, 'close')
})

const response = await client.request(requestOptions)

t.equal(response.statusCode, 200)
t.deepStrictEqual(response.context, { history: [] })
})

test('Should handle 206 partial content', async t => {
t = tspl(t, { plan: 5 })

Expand Down

0 comments on commit 077041e

Please sign in to comment.