Skip to content

Commit

Permalink
chore: migrate to node test runner (#185)
Browse files Browse the repository at this point in the history
* chore: migrate to node test runner

* chore: remove tap

* Update .gitignore
  • Loading branch information
ilteoood authored Jan 10, 2025
1 parent cbb113d commit 2c9f030
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
2 changes: 0 additions & 2 deletions .taprc

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
"devDependencies": {
"@fastify/pre-commit": "^2.1.0",
"@types/node": "^22.0.0",
"c8": "^10.1.3",
"eslint": "^9.17.0",
"fastify": "^5.0.0",
"neostandard": "^0.12.0",
"request": "^2.88.0",
"tap": "^20.0.1",
"tsd": "^0.31.1"
},
"dependencies": {
Expand All @@ -24,7 +23,7 @@
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "tap"
"test:unit": "c8 --100 node --test"
},
"repository": {
"type": "git",
Expand Down
40 changes: 18 additions & 22 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')

const fastifyAccepts = require('..')

const request = require('request')
const Fastify = require('fastify')

const testCases = [
Expand Down Expand Up @@ -89,13 +88,13 @@ const testCases = [
}
]

test('accept header', t => {
test('accept header', async t => {
t.plan(testCases.length)

const fastify = Fastify()
fastify.register(fastifyAccepts, { decorateReply: true })

t.teardown(fastify.close.bind(fastify))
t.after(() => fastify.close())

fastify.get('/request', function (req, reply) {
reply.send({
Expand All @@ -116,25 +115,22 @@ test('accept header', t => {
})
})

fastify.listen({ port: 0 }, function () {
const BASE_URL = `http://localhost:${fastify.server.address().port}`

testCases.forEach(function (testCase) {
t.test(testCase.name, (t) => {
t.plan(2)
request({
url: `${BASE_URL}${testCase.url}`,
headers: {
accept: testCase.acceptHeader
},
json: true
}, (err, _response, body) => {
t.ok(!err)
t.strictSame(body, testCase.expected)
})
await fastify.listen({ port: 0 })

const BASE_URL = `http://localhost:${fastify.server.address().port}`

for (const testCase of testCases) {
await t.test(testCase.name, async (t) => {
t.plan(1)

const result = await fetch(`${BASE_URL}${testCase.url}`, {
headers: {
accept: testCase.acceptHeader
},
})
t.assert.deepStrictEqual(await result.json(), testCase.expected)
})
})
}
})

test('no reply decorator', async function (t) {
Expand All @@ -150,6 +146,6 @@ test('no reply decorator', async function (t) {
]

for (const method of methodNames) {
t.equal(fastify.hasReplyDecorator('request' + method, false), false)
t.assert.deepStrictEqual(fastify.hasReplyDecorator('request' + method, false), false)
}
})

0 comments on commit 2c9f030

Please sign in to comment.