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

test: migrate to node test runner #367

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
2 changes: 0 additions & 2 deletions .taprc

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint:fix": "eslint --fix",
"test": "npm run lint && npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "tap",
"test:unit": "c8 --100 node --test",
"test:unit:report": "tap --coverage-report=html",
"test:unit:verbose": "tap -Rspec"
},
Expand Down Expand Up @@ -71,10 +71,10 @@
"@fastify/cookie": "^11.0.1",
"@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",
"tap": "^18.7.1",
"tsd": "^0.31.0"
},
"publishConfig": {
Expand Down
12 changes: 11 additions & 1 deletion test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ function generateKeyPairProtected (passphrase) {
return crypto.generateKeyPairSync('rsa', options)
}

function withResolvers () {
let promiseResolve, promiseReject
const promise = new Promise((resolve, reject) => {
promiseResolve = resolve
promiseReject = reject
})
return { promise, resolve: promiseResolve, reject: promiseReject }
}

function generateKeyPairECDSA () {
const options = {
modulusLength: 2048,
Expand Down Expand Up @@ -74,5 +83,6 @@ module.exports = {
generateKeyPair,
generateKeyPairProtected,
generateKeyPairECDSA,
generateKeyPairECDSAProtected
generateKeyPairECDSAProtected,
withResolvers
}
15 changes: 7 additions & 8 deletions test/jwt-async.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const test = require('tap').test
const { test } = require('node:test')
const Fastify = require('fastify')
const jwt = require('../jwt')
const { createSigner } = require('fast-jwt')
Expand Down Expand Up @@ -30,9 +30,8 @@ test('Async key provider should be resolved internally', async function (t) {
jwt: 'supersecret'
}
})
t.ok(response)
t.comment("Should be 'undefined'")
t.match(response.json(), { user: 'test' })
t.assert.ok(response)
t.assert.deepStrictEqual(response.json().user, 'test')
})

test('Async key provider errors should be resolved internally', async function (t) {
Expand All @@ -58,7 +57,7 @@ test('Async key provider errors should be resolved internally', async function (
url: '/'
})

t.equal(response.statusCode, 401)
t.assert.deepStrictEqual(response.statusCode, 401)
})

test('Async key provider should be resolved internally with cache', async function (t) {
Expand Down Expand Up @@ -96,8 +95,8 @@ test('Async key provider should be resolved internally with cache', async functi
method: 'get',
url: '/'
})
t.equal(response.statusCode, 200)
t.match(response.json(), { name: 'John Doe' })
t.assert.deepStrictEqual(response.statusCode, 200)
t.assert.deepStrictEqual(response.json().name, 'John Doe')
})

test('Async key provider errors should be resolved internally with cache', async function (t) {
Expand Down Expand Up @@ -131,5 +130,5 @@ test('Async key provider errors should be resolved internally with cache', async
url: '/'
})

t.equal(response.statusCode, 401)
t.assert.deepStrictEqual(response.statusCode, 401)
})
Loading