Skip to content

Commit 28934ea

Browse files
committed
migrate test suite from tap to node:test
1 parent 97ec7bc commit 28934ea

9 files changed

Lines changed: 166 additions & 158 deletions

.taprc

Lines changed: 0 additions & 4 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"scripts": {
99
"lint": "standard",
1010
"test": "npm run test:unit && npm run test:typescript",
11-
"test:unit": "tap",
11+
"test:unit": "node --test",
12+
"test:coverage": "c8 node --test && c8 report --reporter=html",
1213
"test:typescript": "tsd"
1314
},
1415
"repository": {
@@ -30,6 +31,7 @@
3031
"@fastify/pre-commit": "^2.1.0",
3132
"@fastify/type-provider-typebox": "^5.0.0-pre.fv5.1",
3233
"@types/node": "^22.0.0",
34+
"c8": "^10.1.2",
3335
"fastify": "^5.0.0-alpha.2",
3436
"proxyquire": "^2.1.3",
3537
"standard": "^17.1.0",

test/bundlers.test.js

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44
const fp = require('../plugin')
55

6-
test('webpack removes require.main.filename', (t) => {
6+
test('webpack removes require.main.filename', async (t) => {
77
const filename = require.main.filename
88
const info = console.info
9-
t.teardown(() => {
9+
t.after(() => {
1010
require.main.filename = filename
1111
console.info = info
1212
})
1313

1414
require.main.filename = null
1515

1616
console.info = function (msg) {
17-
t.fail('logged: ' + msg)
17+
t.assert.fail('logged: ' + msg)
1818
}
1919

2020
fp((fastify, opts, next) => {
2121
next()
2222
}, {
2323
fastify: '^5.0.0'
2424
})
25-
26-
t.end()
2725
})
2826

29-
test('support faux modules', (t) => {
27+
test('support faux modules', async(t) => {
3028
const plugin = fp((fastify, opts, next) => {
3129
next()
3230
})
3331

34-
t.equal(plugin.default, plugin)
35-
t.end()
32+
t.assert.strictEqual(plugin.default, plugin)
3633
})
3734

3835
test('support faux modules does not override existing default field in babel module', (t) => {
@@ -44,66 +41,65 @@ test('support faux modules does not override existing default field in babel mod
4441

4542
const plugin = fp(module)
4643

47-
t.equal(plugin.default, 'Existing default field')
48-
t.end()
44+
t.assert.strictEqual(plugin.default, 'Existing default field')
4945
})
5046

51-
test('support ts named imports', (t) => {
47+
test('support ts named imports', async(t) => {
5248
const plugin = fp((fastify, opts, next) => {
5349
next()
5450
}, {
5551
name: 'hello'
5652
})
5753

58-
t.equal(plugin.hello, plugin)
59-
t.end()
54+
t.assert.strictEqual(plugin.hello, plugin)
55+
6056
})
6157

62-
test('from kebab-case to camelCase', (t) => {
58+
test('from kebab-case to camelCase', async(t) => {
6359
const plugin = fp((fastify, opts, next) => {
6460
next()
6561
}, {
6662
name: 'hello-world'
6763
})
6864

69-
t.equal(plugin.helloWorld, plugin)
70-
t.end()
65+
t.assert.strictEqual(plugin.helloWorld, plugin)
66+
7167
})
7268

73-
test('from @-prefixed named imports', (t) => {
69+
test('from @-prefixed named imports', async(t) => {
7470
const plugin = fp((fastify, opts, next) => {
7571
next()
7672
}, {
7773
name: '@hello/world'
7874
})
7975

80-
t.equal(plugin.helloWorld, plugin)
81-
t.end()
76+
t.assert.strictEqual(plugin.helloWorld, plugin)
77+
8278
})
8379

84-
test('from @-prefixed named kebab-case to camelCase', (t) => {
80+
test('from @-prefixed named kebab-case to camelCase', async(t) => {
8581
const plugin = fp((fastify, opts, next) => {
8682
next()
8783
}, {
8884
name: '@hello/my-world'
8985
})
9086

91-
t.equal(plugin.helloMyWorld, plugin)
92-
t.end()
87+
t.assert.strictEqual(plugin.helloMyWorld, plugin)
88+
9389
})
9490

95-
test('from kebab-case to camelCase multiple words', (t) => {
91+
test('from kebab-case to camelCase multiple words', async (t) => {
9692
const plugin = fp((fastify, opts, next) => {
9793
next()
9894
}, {
9995
name: 'hello-long-world'
10096
})
10197

102-
t.equal(plugin.helloLongWorld, plugin)
103-
t.end()
98+
t.assert.strictEqual(plugin.helloLongWorld, plugin)
99+
104100
})
105101

106-
test('from kebab-case to camelCase multiple words does not override', (t) => {
102+
test('from kebab-case to camelCase multiple words does not override', async (t) => {
107103
const fn = (fastify, opts, next) => {
108104
next()
109105
}
@@ -115,6 +111,6 @@ test('from kebab-case to camelCase multiple words does not override', (t) => {
115111
name: 'hello-long-world'
116112
})
117113

118-
t.equal(plugin.helloLongWorld, foobar)
119-
t.end()
114+
t.assert.strictEqual(plugin.helloLongWorld, foobar)
115+
120116
})

test/checkVersion.test.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44
const fp = require('../plugin')
55

66
test('checkVersion having require.main.filename', (t) => {
77
const info = console.info
8-
t.ok(require.main.filename)
9-
t.teardown(() => {
8+
t.assert.ok(require.main.filename)
9+
t.after(() => {
1010
console.info = info
1111
})
1212

1313
console.info = function (msg) {
14-
t.fail('logged: ' + msg)
14+
t.assert.fail('logged: ' + msg)
1515
}
1616

1717
fp((fastify, opts, next) => {
@@ -20,21 +20,20 @@ test('checkVersion having require.main.filename', (t) => {
2020
fastify: '^5.0.0'
2121
})
2222

23-
t.end()
2423
})
2524

2625
test('checkVersion having no require.main.filename but process.argv[1]', (t) => {
2726
const filename = require.main.filename
2827
const info = console.info
29-
t.teardown(() => {
28+
t.after(() => {
3029
require.main.filename = filename
3130
console.info = info
3231
})
3332

3433
require.main.filename = null
3534

3635
console.info = function (msg) {
37-
t.fail('logged: ' + msg)
36+
t.assert.fail('logged: ' + msg)
3837
}
3938

4039
fp((fastify, opts, next) => {
@@ -43,14 +42,13 @@ test('checkVersion having no require.main.filename but process.argv[1]', (t) =>
4342
fastify: '^5.0.0'
4443
})
4544

46-
t.end()
4745
})
4846

4947
test('checkVersion having no require.main.filename and no process.argv[1]', (t) => {
5048
const filename = require.main.filename
5149
const argv = process.argv
5250
const info = console.info
53-
t.teardown(() => {
51+
t.after(() => {
5452
require.main.filename = filename
5553
process.argv = argv
5654
console.info = info
@@ -60,14 +58,12 @@ test('checkVersion having no require.main.filename and no process.argv[1]', (t)
6058
process.argv[1] = null
6159

6260
console.info = function (msg) {
63-
t.fail('logged: ' + msg)
61+
t.assert.fail('logged: ' + msg)
6462
}
6563

6664
fp((fastify, opts, next) => {
6765
next()
6866
}, {
6967
fastify: '^5.0.0'
7068
})
71-
72-
t.end()
7369
})

test/composite.test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
'use strict'
22

3-
const t = require('tap')
4-
const test = t.test
3+
const { test } = require('node:test')
54
const fp = require('../plugin')
65

7-
test('anonymous function should be named composite.test0', t => {
6+
test('anonymous function should be named composite.test0', async (t)=> {
87
t.plan(2)
9-
108
const fn = fp((fastify, opts, next) => {
119
next()
1210
})
1311

14-
t.equal(fn[Symbol.for('plugin-meta')].name, 'composite.test-auto-0')
15-
t.equal(fn[Symbol.for('fastify.display-name')], 'composite.test-auto-0')
12+
t.assert.strictEqual(fn[Symbol.for('plugin-meta')].name, 'composite.test-auto-0')
13+
t.assert.strictEqual(fn[Symbol.for('fastify.display-name')], 'composite.test-auto-0')
1614
})

test/extractPluginName.test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const { test } = require('node:test')
44
const extractPluginName = require('../lib/getPluginName').extractPluginName
55

66
const winStack = `Error: anonymous function
@@ -41,8 +41,9 @@ at TAP.test (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:
4141

4242
const anonymousStack = 'Unable to parse this'
4343

44-
t.plan(3)
45-
46-
t.equal(extractPluginName(winStack), 'hello.test')
47-
t.equal(extractPluginName(nixStack), 'this.is.a.test')
48-
t.equal(extractPluginName(anonymousStack), 'anonymous')
44+
test('extractPluginName tests', async (t) => {
45+
t.plan(3)
46+
t.assert.strictEqual(extractPluginName(winStack), 'hello.test')
47+
t.assert.strictEqual(extractPluginName(nixStack), 'this.is.a.test')
48+
t.assert.strictEqual(extractPluginName(anonymousStack), 'anonymous')
49+
})

test/mu1tip1e.composite.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
'use strict'
22

3-
const t = require('tap')
4-
const test = t.test
3+
const { test } = require('node:test')
54
const fp = require('../plugin')
65

7-
test('anonymous function should be named mu1tip1e.composite.test', t => {
6+
7+
test('anonymous function should be named mu1tip1e.composite.test', async(t) => {
88
t.plan(2)
99

1010
const fn = fp((fastify, opts, next) => {
1111
next()
1212
})
1313

14-
t.equal(fn[Symbol.for('plugin-meta')].name, 'mu1tip1e.composite.test-auto-0')
15-
t.equal(fn[Symbol.for('fastify.display-name')], 'mu1tip1e.composite.test-auto-0')
14+
t.assert.strictEqual(fn[Symbol.for('plugin-meta')].name, 'mu1tip1e.composite.test-auto-0')
15+
t.assert.strictEqual(fn[Symbol.for('fastify.display-name')], 'mu1tip1e.composite.test-auto-0')
1616
})

0 commit comments

Comments
 (0)