1
1
'use strict'
2
2
3
3
const proxyquire = require ( 'proxyquire' )
4
- const tap = require ( 'tap ' )
4
+ const { test } = require ( 'node:test ' )
5
5
const sinon = require ( 'sinon' )
6
6
const util = require ( 'node:util' )
7
7
const exec = util . promisify ( require ( 'node:child_process' ) . exec )
8
8
9
9
const printRoutes = require ( '../print-routes' )
10
10
11
- const test = tap . test
12
11
const { NYC_PROCESS_ID , NODE_V8_COVERAGE } = process . env
13
12
const SHOULD_SKIP = NYC_PROCESS_ID || NODE_V8_COVERAGE
14
13
@@ -22,15 +21,15 @@ test('should print routes', async t => {
22
21
const fastify = await command . printRoutes ( [ './examples/plugin.js' ] )
23
22
24
23
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' ] ] )
27
26
} )
28
27
29
28
// This never exits in CI for some reason
30
29
test ( 'should print routes via cli' , { skip : SHOULD_SKIP } , async t => {
31
30
t . plan ( 1 )
32
31
const { stdout } = await exec ( 'node cli.js print-routes ./examples/plugin.js' , { encoding : 'utf-8' , timeout : 10000 } )
33
- t . same (
32
+ t . assert . deepStrictEqual (
34
33
stdout ,
35
34
'└── / (GET, HEAD, POST)\n\n'
36
35
)
@@ -40,35 +39,37 @@ test('should warn on file not found', t => {
40
39
t . plan ( 1 )
41
40
42
41
const oldStop = printRoutes . stop
43
- t . teardown ( ( ) => { printRoutes . stop = oldStop } )
42
+ t . after ( ( ) => { printRoutes . stop = oldStop } )
44
43
printRoutes . stop = function ( message ) {
45
- t . ok ( / n o t - f o u n d .j s d o e s n ' t e x i s t w i t h i n / . test ( message ) , message )
44
+ t . assert . ok ( / n o t - f o u n d .j s d o e s n ' t e x i s t w i t h i n / . test ( message ) , message )
46
45
}
47
46
48
47
const argv = [ './data/not-found.js' ]
49
48
printRoutes . printRoutes ( argv )
50
49
} )
51
50
52
- test ( 'should throw on package not found' , t => {
51
+ test ( 'should throw on package not found' , ( t , done ) => {
53
52
t . plan ( 1 )
54
53
55
54
const oldStop = printRoutes . stop
56
- t . teardown ( ( ) => { printRoutes . stop = oldStop } )
55
+ t . after ( ( ) => { printRoutes . stop = oldStop } )
57
56
printRoutes . stop = function ( err ) {
58
- t . ok ( / C a n n o t f i n d m o d u l e ' u n k n o w n - p a c k a g e ' / . test ( err . message ) , err . message )
57
+ t . assert . ok ( / C a n n o t f i n d m o d u l e ' u n k n o w n - p a c k a g e ' / . test ( err . message ) , err . message )
58
+ done ( )
59
59
}
60
60
61
61
const argv = [ './test/data/package-not-found.js' ]
62
62
printRoutes . printRoutes ( argv )
63
63
} )
64
64
65
- test ( 'should throw on parsing error' , t => {
65
+ test ( 'should throw on parsing error' , ( t , done ) => {
66
66
t . plan ( 1 )
67
67
68
68
const oldStop = printRoutes . stop
69
- t . teardown ( ( ) => { printRoutes . stop = oldStop } )
69
+ t . after ( ( ) => { printRoutes . stop = oldStop } )
70
70
printRoutes . stop = function ( err ) {
71
- t . equal ( err . constructor , SyntaxError )
71
+ t . assert . strictEqual ( err . constructor , SyntaxError )
72
+ done ( )
72
73
}
73
74
74
75
const argv = [ './test/data/parsing-error.js' ]
@@ -79,24 +80,22 @@ test('should exit without error on help', t => {
79
80
const exit = process . exit
80
81
process . exit = sinon . spy ( )
81
82
82
- t . teardown ( ( ) => {
83
+ t . after ( ( ) => {
83
84
process . exit = exit
84
85
} )
85
86
86
87
const argv = [ '-h' , 'true' ]
87
88
printRoutes . printRoutes ( argv )
88
89
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 )
93
92
} )
94
93
95
94
test ( 'should print routes of server with an async/await plugin' , async t => {
96
95
const nodeMajorVersion = process . versions . node . split ( '.' ) . map ( x => parseInt ( x , 10 ) ) [ 0 ]
97
96
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' )
100
99
}
101
100
102
101
t . plan ( 2 )
@@ -109,8 +108,8 @@ test('should print routes of server with an async/await plugin', async t => {
109
108
const fastify = await command . printRoutes ( argv )
110
109
111
110
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' ] ] )
114
113
} )
115
114
116
115
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 => {
122
121
} )
123
122
await command . cli ( [ './examples/plugin-common-prefix.js' , '--commonPrefix' ] )
124
123
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' ] ] )
127
126
} )
128
127
129
128
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 => {
135
134
} )
136
135
await command . cli ( [ './examples/plugin.js' , '--method' , 'GET' ] )
137
136
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' ] ] )
140
139
} )
141
140
142
141
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 => {
148
147
} )
149
148
await command . cli ( [ './examples/plugin.js' , '--include-hooks' ] )
150
149
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' ] ] )
153
152
} )
0 commit comments