Skip to content

Commit 4743cfa

Browse files
authored
test: migrated print-routes.test.js to tap to node:test (#829)
1 parent b0ec85b commit 4743cfa

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

test/print-routes.test.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +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 printRoutes = require('../print-routes')
1010

11-
const test = tap.test
1211
const { NYC_PROCESS_ID, NODE_V8_COVERAGE } = process.env
1312
const SHOULD_SKIP = NYC_PROCESS_ID || NODE_V8_COVERAGE
1413

@@ -22,15 +21,15 @@ test('should print routes', async t => {
2221
const fastify = await command.printRoutes(['./examples/plugin.js'])
2322

2423
await fastify.close()
25-
t.ok(spy.called)
26-
t.same(spy.args, [['debug', '└── / (GET, HEAD, POST)\n']])
24+
t.assert.ok(spy.called)
25+
t.assert.deepStrictEqual(spy.args, [['debug', '└── / (GET, HEAD, POST)\n']])
2726
})
2827

2928
// This never exits in CI for some reason
3029
test('should print routes via cli', { skip: SHOULD_SKIP }, async t => {
3130
t.plan(1)
3231
const { stdout } = await exec('node cli.js print-routes ./examples/plugin.js', { encoding: 'utf-8', timeout: 10000 })
33-
t.same(
32+
t.assert.deepStrictEqual(
3433
stdout,
3534
'└── / (GET, HEAD, POST)\n\n'
3635
)
@@ -40,35 +39,37 @@ test('should warn on file not found', t => {
4039
t.plan(1)
4140

4241
const oldStop = printRoutes.stop
43-
t.teardown(() => { printRoutes.stop = oldStop })
42+
t.after(() => { printRoutes.stop = oldStop })
4443
printRoutes.stop = function (message) {
45-
t.ok(/not-found.js doesn't exist within/.test(message), message)
44+
t.assert.ok(/not-found.js doesn't exist within/.test(message), message)
4645
}
4746

4847
const argv = ['./data/not-found.js']
4948
printRoutes.printRoutes(argv)
5049
})
5150

52-
test('should throw on package not found', t => {
51+
test('should throw on package not found', (t, done) => {
5352
t.plan(1)
5453

5554
const oldStop = printRoutes.stop
56-
t.teardown(() => { printRoutes.stop = oldStop })
55+
t.after(() => { printRoutes.stop = oldStop })
5756
printRoutes.stop = function (err) {
58-
t.ok(/Cannot find module 'unknown-package'/.test(err.message), err.message)
57+
t.assert.ok(/Cannot find module 'unknown-package'/.test(err.message), err.message)
58+
done()
5959
}
6060

6161
const argv = ['./test/data/package-not-found.js']
6262
printRoutes.printRoutes(argv)
6363
})
6464

65-
test('should throw on parsing error', t => {
65+
test('should throw on parsing error', (t, done) => {
6666
t.plan(1)
6767

6868
const oldStop = printRoutes.stop
69-
t.teardown(() => { printRoutes.stop = oldStop })
69+
t.after(() => { printRoutes.stop = oldStop })
7070
printRoutes.stop = function (err) {
71-
t.equal(err.constructor, SyntaxError)
71+
t.assert.strictEqual(err.constructor, SyntaxError)
72+
done()
7273
}
7374

7475
const argv = ['./test/data/parsing-error.js']
@@ -79,24 +80,22 @@ test('should exit without error on help', t => {
7980
const exit = process.exit
8081
process.exit = sinon.spy()
8182

82-
t.teardown(() => {
83+
t.after(() => {
8384
process.exit = exit
8485
})
8586

8687
const argv = ['-h', 'true']
8788
printRoutes.printRoutes(argv)
8889

89-
t.ok(process.exit.called)
90-
t.equal(process.exit.lastCall.args[0], undefined)
91-
92-
t.end()
90+
t.assert.ok(process.exit.called)
91+
t.assert.strictEqual(process.exit.lastCall.args[0], undefined)
9392
})
9493

9594
test('should print routes of server with an async/await plugin', async t => {
9695
const nodeMajorVersion = process.versions.node.split('.').map(x => parseInt(x, 10))[0]
9796
if (nodeMajorVersion < 7) {
98-
t.pass('Skip because Node version < 7')
99-
return t.end()
97+
t.assert.ok('Skip because Node version < 7')
98+
return t.assert.ok('end')
10099
}
101100

102101
t.plan(2)
@@ -109,8 +108,8 @@ test('should print routes of server with an async/await plugin', async t => {
109108
const fastify = await command.printRoutes(argv)
110109

111110
await fastify.close()
112-
t.ok(spy.called)
113-
t.same(spy.args, [['debug', '└── / (GET, HEAD)\n']])
111+
t.assert.ok(spy.called)
112+
t.assert.deepStrictEqual(spy.args, [['debug', '└── / (GET, HEAD)\n']])
114113
})
115114

116115
test('should print uncimpressed routes with --common-refix flag', async t => {
@@ -122,8 +121,8 @@ test('should print uncimpressed routes with --common-refix flag', async t => {
122121
})
123122
await command.cli(['./examples/plugin-common-prefix.js', '--commonPrefix'])
124123

125-
t.ok(spy.called)
126-
t.same(spy.args, [['debug', '└── /\n └── hel\n ├── lo-world (GET, HEAD)\n └── p (POST)\n']])
124+
t.assert.ok(spy.called)
125+
t.assert.deepStrictEqual(spy.args, [['debug', '└── /\n └── hel\n ├── lo-world (GET, HEAD)\n └── p (POST)\n']])
127126
})
128127

129128
test('should print debug safe GET routes with --method GET flag', async t => {
@@ -135,8 +134,8 @@ test('should print debug safe GET routes with --method GET flag', async t => {
135134
})
136135
await command.cli(['./examples/plugin.js', '--method', 'GET'])
137136

138-
t.ok(spy.called)
139-
t.same(spy.args, [['debug', '└── / (GET)\n']])
137+
t.assert.ok(spy.called)
138+
t.assert.deepStrictEqual(spy.args, [['debug', '└── / (GET)\n']])
140139
})
141140

142141
test('should print routes with hooks with --include-hooks flag', async t => {
@@ -148,6 +147,6 @@ test('should print routes with hooks with --include-hooks flag', async t => {
148147
})
149148
await command.cli(['./examples/plugin.js', '--include-hooks'])
150149

151-
t.ok(spy.called)
152-
t.same(spy.args, [['debug', '└── / (GET, POST)\n / (HEAD)\n • (onSend) ["headRouteOnSendHandler()"]\n']])
150+
t.assert.ok(spy.called)
151+
t.assert.deepStrictEqual(spy.args, [['debug', '└── / (GET, POST)\n / (HEAD)\n • (onSend) ["headRouteOnSendHandler()"]\n']])
153152
})

0 commit comments

Comments
 (0)