Skip to content

Commit 0fefb05

Browse files
authored
test: migrated print-plugins.test.js to tap to node:test (#828)
1 parent 4743cfa commit 0fefb05

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

test/print-plugins.test.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
'use strict'
22

33
const proxyquire = require('proxyquire')
4-
const tap = require('tap')
4+
const { test } = require('node:test')
55
const sinon = require('sinon')
66
const util = require('node:util')
77
const exec = util.promisify(require('node:child_process').exec)
88

99
const printPlugins = require('../print-plugins')
1010

11-
const test = tap.test
12-
1311
const { NYC_PROCESS_ID, NODE_V8_COVERAGE } = process.env
1412
const SHOULD_SKIP = NYC_PROCESS_ID || NODE_V8_COVERAGE
1513

@@ -24,54 +22,57 @@ test('should print plugins', { skip: SHOULD_SKIP }, async t => {
2422
const fastify = await command.printPlugins(['./examples/plugin.js'])
2523

2624
await fastify.close()
27-
t.ok(spy.called)
28-
t.same(spy.args[0][0], 'debug')
29-
t.match(spy.args[0][1], /bound root \d+ ms\n bound _after \d+ ms\n function \(fastify, options, next\) { -- fastify\.decorate\('test', true\) \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n/)
25+
t.assert.ok(spy.called)
26+
t.assert.deepStrictEqual(spy.args[0][0], 'debug')
27+
t.assert.match(spy.args[0][1], /root \d+ ms\n bound _after \d+ ms\n function \(fastify, options, next\) { -- fastify\.decorate\('test', true\) \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n/)
3028
})
3129

3230
// This test should be skipped when coverage reporting is used since outputs won't match
3331
test('should plugins routes via cli', { skip: SHOULD_SKIP }, async t => {
3432
t.plan(1)
3533
const { stdout } = await exec('node cli.js print-plugins ./examples/plugin.js', { encoding: 'utf-8', timeout: 10000 })
36-
t.match(
34+
t.assert.match(
3735
stdout,
38-
/bound root \d+ ms\n bound _after \d+ ms\n function \(fastify, options, next\) { -- fastify\.decorate\('test', true\) \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n\n/
36+
/root \d+ ms\n bound _after \d+ ms\n function \(fastify, options, next\) { -- fastify\.decorate\('test', true\) \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n\n/
3937
)
4038
})
4139

42-
test('should warn on file not found', t => {
40+
test('should warn on file not found', (t, done) => {
4341
t.plan(1)
4442

4543
const oldStop = printPlugins.stop
46-
t.teardown(() => { printPlugins.stop = oldStop })
44+
t.after(() => { printPlugins.stop = oldStop })
4745
printPlugins.stop = function (message) {
48-
t.ok(/not-found.js doesn't exist within/.test(message), message)
46+
t.assert.ok(/not-found.js doesn't exist within/.test(message), message)
47+
done()
4948
}
5049

5150
const argv = ['./data/not-found.js']
5251
printPlugins.printPlugins(argv)
5352
})
5453

55-
test('should throw on package not found', t => {
54+
test('should throw on package not found', (t, done) => {
5655
t.plan(1)
5756

5857
const oldStop = printPlugins.stop
59-
t.teardown(() => { printPlugins.stop = oldStop })
58+
t.after(() => { printPlugins.stop = oldStop })
6059
printPlugins.stop = function (err) {
61-
t.ok(/Cannot find module 'unknown-package'/.test(err.message), err.message)
60+
t.assert.ok(/Cannot find module 'unknown-package'/.test(err.message), err.message)
61+
done()
6262
}
6363

6464
const argv = ['./test/data/package-not-found.js']
6565
printPlugins.printPlugins(argv)
6666
})
6767

68-
test('should throw on parsing error', t => {
68+
test('should throw on parsing error', (t, done) => {
6969
t.plan(1)
7070

7171
const oldStop = printPlugins.stop
72-
t.teardown(() => { printPlugins.stop = oldStop })
72+
t.after(() => { printPlugins.stop = oldStop })
7373
printPlugins.stop = function (err) {
74-
t.equal(err.constructor, SyntaxError)
74+
t.assert.strictEqual(err.constructor, SyntaxError)
75+
done()
7576
}
7677

7778
const argv = ['./test/data/parsing-error.js']
@@ -82,25 +83,23 @@ test('should exit without error on help', t => {
8283
const exit = process.exit
8384
process.exit = sinon.spy()
8485

85-
t.teardown(() => {
86+
t.after(() => {
8687
process.exit = exit
8788
})
8889

8990
const argv = ['-h', 'true']
9091
printPlugins.printPlugins(argv)
9192

92-
t.ok(process.exit.called)
93-
t.equal(process.exit.lastCall.args[0], undefined)
94-
95-
t.end()
93+
t.assert.ok(process.exit.called)
94+
t.assert.strictEqual(process.exit.lastCall.args[0], undefined)
9695
})
9796

9897
// This test should be skipped when coverage reporting is used since outputs won't match
9998
test('should print plugins of server with an async/await plugin', { skip: SHOULD_SKIP }, async t => {
10099
const nodeMajorVersion = process.versions.node.split('.').map(x => parseInt(x, 10))[0]
101100
if (nodeMajorVersion < 7) {
102-
t.pass('Skip because Node version < 7')
103-
return t.end()
101+
t.assert.ok('Skip because Node version < 7')
102+
return t.assert.ok('end')
104103
}
105104

106105
t.plan(3)
@@ -113,7 +112,7 @@ test('should print plugins of server with an async/await plugin', { skip: SHOULD
113112
const fastify = await command.printPlugins(argv)
114113

115114
await fastify.close()
116-
t.ok(spy.called)
117-
t.same(spy.args[0][0], 'debug')
118-
t.match(spy.args[0][1], /bound root \d+ ms\n bound _after \d+ ms\n async function \(fastify, options\) { -- fastify\.get\('\/', async function \(req, reply\) { \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n/)
115+
t.assert.ok(spy.called)
116+
t.assert.deepStrictEqual(spy.args[0][0], 'debug')
117+
t.assert.match(spy.args[0][1], /root \d+ ms\n bound _after \d+ ms\n async function \(fastify, options\) { -- fastify\.get\('\/', async function \(req, reply\) { \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n bound _after \d+ ms\n/)
119118
})

0 commit comments

Comments
 (0)