Skip to content

Commit ef861a1

Browse files
authoredMar 5, 2025··
test: migrate to node test runner (#367)
1 parent 26deef1 commit ef861a1

7 files changed

+1161
-1263
lines changed
 

‎.taprc

-2
This file was deleted.

‎package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
"lint:fix": "eslint --fix",
1111
"test": "npm run lint && npm run test:unit && npm run test:typescript",
1212
"test:typescript": "tsd",
13-
"test:unit": "tap",
14-
"test:unit:report": "tap --coverage-report=html",
15-
"test:unit:verbose": "tap -Rspec"
13+
"test:unit": "c8 --100 node --test",
14+
"test:unit:report": "c8 -r html --100 node --test"
1615
},
1716
"repository": {
1817
"type": "git",
@@ -71,10 +70,10 @@
7170
"@fastify/cookie": "^11.0.1",
7271
"@fastify/pre-commit": "^2.1.0",
7372
"@types/node": "^22.0.0",
73+
"c8": "^10.1.3",
7474
"eslint": "^9.17.0",
7575
"fastify": "^5.0.0",
7676
"neostandard": "^0.12.0",
77-
"tap": "^18.7.1",
7877
"tsd": "^0.31.0"
7978
},
8079
"publishConfig": {

‎test/helper.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ function generateKeyPairProtected (passphrase) {
3636
return crypto.generateKeyPairSync('rsa', options)
3737
}
3838

39+
function withResolvers () {
40+
let promiseResolve, promiseReject
41+
const promise = new Promise((resolve, reject) => {
42+
promiseResolve = resolve
43+
promiseReject = reject
44+
})
45+
return { promise, resolve: promiseResolve, reject: promiseReject }
46+
}
47+
3948
function generateKeyPairECDSA () {
4049
const options = {
4150
modulusLength: 2048,
@@ -74,5 +83,6 @@ module.exports = {
7483
generateKeyPair,
7584
generateKeyPairProtected,
7685
generateKeyPairECDSA,
77-
generateKeyPairECDSAProtected
86+
generateKeyPairECDSAProtected,
87+
withResolvers
7888
}

‎test/jwt-async.test.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const test = require('tap').test
3+
const { test } = require('node:test')
44
const Fastify = require('fastify')
55
const jwt = require('../jwt')
66
const { createSigner } = require('fast-jwt')
@@ -30,9 +30,8 @@ test('Async key provider should be resolved internally', async function (t) {
3030
jwt: 'supersecret'
3131
}
3232
})
33-
t.ok(response)
34-
t.comment("Should be 'undefined'")
35-
t.match(response.json(), { user: 'test' })
33+
t.assert.ok(response)
34+
t.assert.strictEqual(response.json().user, 'test')
3635
})
3736

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

61-
t.equal(response.statusCode, 401)
60+
t.assert.strictEqual(response.statusCode, 401)
6261
})
6362

6463
test('Async key provider should be resolved internally with cache', async function (t) {
@@ -96,8 +95,8 @@ test('Async key provider should be resolved internally with cache', async functi
9695
method: 'get',
9796
url: '/'
9897
})
99-
t.equal(response.statusCode, 200)
100-
t.match(response.json(), { name: 'John Doe' })
98+
t.assert.strictEqual(response.statusCode, 200)
99+
t.assert.strictEqual(response.json().name, 'John Doe')
101100
})
102101

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

134-
t.equal(response.statusCode, 401)
133+
t.assert.strictEqual(response.statusCode, 401)
135134
})

0 commit comments

Comments
 (0)
Please sign in to comment.