Skip to content

Commit

Permalink
fix (test): custom-parser.test.js flaky test (#3627)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkgl0w committed Jan 17, 2022
1 parent 4d87089 commit dd7de59
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions test/custom-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,9 +1314,10 @@ test('contentTypeParser should add a custom parser with RegExp value', t => {
})
})

test('contentTypeParser should add multiple custom parsers with RegExp values', t => {
t.plan(10)
test('contentTypeParser should add multiple custom parsers with RegExp values', async t => {
t.plan(6)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))

fastify.post('/', (req, reply) => {
reply.send(req.body)
Expand All @@ -1340,48 +1341,46 @@ test('contentTypeParser should add multiple custom parsers with RegExp values',
})
})

fastify.listen(0, err => {
t.error(err)
await fastify.ready()

sget({
{
const response = await fastify.inject({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port,
body: '{"hello":"world"}',
path: '/',
payload: '{"hello":"world"}',
headers: {
'Content-Type': 'application/vnd.hello+json'
}
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.same(body.toString(), JSON.stringify({ hello: 'world' }))
})
t.equal(response.statusCode, 200)
t.same(response.payload.toString(), '{"hello":"world"}')
}

sget({
{
const response = await fastify.inject({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port,
body: '{"hello":"world"}',
path: '/',
payload: '{"hello":"world"}',
headers: {
'Content-Type': 'application/test+xml'
}
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.same(body.toString(), 'xml')
})
t.equal(response.statusCode, 200)
t.same(response.payload.toString(), 'xml')
}

sget({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port,
body: 'abcdefg',
headers: {
'Content-Type': 'application/+myExtension'
}
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.same(body.toString(), 'abcdefgmyExtension')
fastify.close()
})
await fastify.inject({
method: 'POST',
path: '/',
payload: 'abcdefg',
headers: {
'Content-Type': 'application/+myExtension'
}
}).then((response) => {
t.equal(response.statusCode, 200)
t.same(response.payload.toString(), 'abcdefgmyExtension')
}).catch((err) => {
t.error(err)
})
})

Expand Down

0 comments on commit dd7de59

Please sign in to comment.