Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (test): custom-parser.test.js flaky test #3627

Merged
merged 3 commits into from
Jan 17, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 42 additions & 41 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,48 @@ test('contentTypeParser should add multiple custom parsers with RegExp values',
})
})

fastify.listen(0, err => {
t.error(err)
await fastify.listen()
darkgl0w marked this conversation as resolved.
Show resolved Hide resolved

sget({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port,
body: '{"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' }))
})
await fastify.inject({
method: 'POST',
path: '/',
payload: '{"hello":"world"}',
headers: {
'Content-Type': 'application/vnd.hello+json'
}
}).then((response) => {
t.equal(response.statusCode, 200)
t.same(response.payload.toString(), JSON.stringify({ hello: 'world' }))
}).catch((err) => {
t.error(err)
})
darkgl0w marked this conversation as resolved.
Show resolved Hide resolved

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

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