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 printPlugins = require ( '../print-plugins' )
10
10
11
- const test = tap . test
12
-
13
11
const { NYC_PROCESS_ID , NODE_V8_COVERAGE } = process . env
14
12
const SHOULD_SKIP = NYC_PROCESS_ID || NODE_V8_COVERAGE
15
13
@@ -24,54 +22,57 @@ test('should print plugins', { skip: SHOULD_SKIP }, async t => {
24
22
const fastify = await command . printPlugins ( [ './examples/plugin.js' ] )
25
23
26
24
await fastify . close ( )
27
- t . ok ( spy . called )
28
- t . same ( spy . args [ 0 ] [ 0 ] , 'debug' )
29
- t . match ( spy . args [ 0 ] [ 1 ] , / b o u n d r o o t \d + m s \n ├ ─ ─ b o u n d _ a f t e r \d + m s \n ├ ─ ┬ f u n c t i o n \( f a s t i f y , o p t i o n s , n e x t \) { - - f a s t i f y \. d e c o r a t e \( ' t e s t ' , t r u e \) \d + m s \n │ ├ ─ ─ b o u n d _ a f t e r \d + m s \n │ ├ ─ ─ b o u n d _ a f t e r \d + m s \n │ └ ─ ─ b o u n d _ a f t e r \d + m s \n └ ─ ─ b o u n d _ a f t e r \d + m s \n / )
25
+ t . assert . ok ( spy . called )
26
+ t . assert . deepStrictEqual ( spy . args [ 0 ] [ 0 ] , 'debug' )
27
+ t . assert . match ( spy . args [ 0 ] [ 1 ] , / r o o t \d + m s \n ├ ─ ─ b o u n d _ a f t e r \d + m s \n ├ ─ ┬ f u n c t i o n \( f a s t i f y , o p t i o n s , n e x t \) { - - f a s t i f y \. d e c o r a t e \( ' t e s t ' , t r u e \) \d + m s \n │ ├ ─ ─ b o u n d _ a f t e r \d + m s \n │ ├ ─ ─ b o u n d _ a f t e r \d + m s \n │ └ ─ ─ b o u n d _ a f t e r \d + m s \n └ ─ ─ b o u n d _ a f t e r \d + m s \n / )
30
28
} )
31
29
32
30
// This test should be skipped when coverage reporting is used since outputs won't match
33
31
test ( 'should plugins routes via cli' , { skip : SHOULD_SKIP } , async t => {
34
32
t . plan ( 1 )
35
33
const { stdout } = await exec ( 'node cli.js print-plugins ./examples/plugin.js' , { encoding : 'utf-8' , timeout : 10000 } )
36
- t . match (
34
+ t . assert . match (
37
35
stdout ,
38
- / b o u n d r o o t \d + m s \n ├ ─ ─ b o u n d _ a f t e r \d + m s \n ├ ─ ┬ f u n c t i o n \( f a s t i f y , o p t i o n s , n e x t \) { - - f a s t i f y \. d e c o r a t e \( ' t e s t ' , t r u e \) \d + m s \n │ ├ ─ ─ b o u n d _ a f t e r \d + m s \n │ ├ ─ ─ b o u n d _ a f t e r \d + m s \n │ └ ─ ─ b o u n d _ a f t e r \d + m s \n └ ─ ─ b o u n d _ a f t e r \d + m s \n \n /
36
+ / r o o t \d + m s \n ├ ─ ─ b o u n d _ a f t e r \d + m s \n ├ ─ ┬ f u n c t i o n \( f a s t i f y , o p t i o n s , n e x t \) { - - f a s t i f y \. d e c o r a t e \( ' t e s t ' , t r u e \) \d + m s \n │ ├ ─ ─ b o u n d _ a f t e r \d + m s \n │ ├ ─ ─ b o u n d _ a f t e r \d + m s \n │ └ ─ ─ b o u n d _ a f t e r \d + m s \n └ ─ ─ b o u n d _ a f t e r \d + m s \n \n /
39
37
)
40
38
} )
41
39
42
- test ( 'should warn on file not found' , t => {
40
+ test ( 'should warn on file not found' , ( t , done ) => {
43
41
t . plan ( 1 )
44
42
45
43
const oldStop = printPlugins . stop
46
- t . teardown ( ( ) => { printPlugins . stop = oldStop } )
44
+ t . after ( ( ) => { printPlugins . stop = oldStop } )
47
45
printPlugins . stop = function ( message ) {
48
- 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 )
46
+ 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 )
47
+ done ( )
49
48
}
50
49
51
50
const argv = [ './data/not-found.js' ]
52
51
printPlugins . printPlugins ( argv )
53
52
} )
54
53
55
- test ( 'should throw on package not found' , t => {
54
+ test ( 'should throw on package not found' , ( t , done ) => {
56
55
t . plan ( 1 )
57
56
58
57
const oldStop = printPlugins . stop
59
- t . teardown ( ( ) => { printPlugins . stop = oldStop } )
58
+ t . after ( ( ) => { printPlugins . stop = oldStop } )
60
59
printPlugins . stop = function ( err ) {
61
- 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 )
60
+ 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 )
61
+ done ( )
62
62
}
63
63
64
64
const argv = [ './test/data/package-not-found.js' ]
65
65
printPlugins . printPlugins ( argv )
66
66
} )
67
67
68
- test ( 'should throw on parsing error' , t => {
68
+ test ( 'should throw on parsing error' , ( t , done ) => {
69
69
t . plan ( 1 )
70
70
71
71
const oldStop = printPlugins . stop
72
- t . teardown ( ( ) => { printPlugins . stop = oldStop } )
72
+ t . after ( ( ) => { printPlugins . stop = oldStop } )
73
73
printPlugins . stop = function ( err ) {
74
- t . equal ( err . constructor , SyntaxError )
74
+ t . assert . strictEqual ( err . constructor , SyntaxError )
75
+ done ( )
75
76
}
76
77
77
78
const argv = [ './test/data/parsing-error.js' ]
@@ -82,25 +83,23 @@ test('should exit without error on help', t => {
82
83
const exit = process . exit
83
84
process . exit = sinon . spy ( )
84
85
85
- t . teardown ( ( ) => {
86
+ t . after ( ( ) => {
86
87
process . exit = exit
87
88
} )
88
89
89
90
const argv = [ '-h' , 'true' ]
90
91
printPlugins . printPlugins ( argv )
91
92
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 )
96
95
} )
97
96
98
97
// This test should be skipped when coverage reporting is used since outputs won't match
99
98
test ( 'should print plugins of server with an async/await plugin' , { skip : SHOULD_SKIP } , async t => {
100
99
const nodeMajorVersion = process . versions . node . split ( '.' ) . map ( x => parseInt ( x , 10 ) ) [ 0 ]
101
100
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' )
104
103
}
105
104
106
105
t . plan ( 3 )
@@ -113,7 +112,7 @@ test('should print plugins of server with an async/await plugin', { skip: SHOULD
113
112
const fastify = await command . printPlugins ( argv )
114
113
115
114
await fastify . close ( )
116
- t . ok ( spy . called )
117
- t . same ( spy . args [ 0 ] [ 0 ] , 'debug' )
118
- t . match ( spy . args [ 0 ] [ 1 ] , / b o u n d r o o t \d + m s \n ├ ─ ─ b o u n d _ a f t e r \d + m s \n ├ ─ ┬ a s y n c f u n c t i o n \( f a s t i f y , o p t i o n s \) { - - f a s t i f y \. g e t \( ' \/ ' , a s y n c f u n c t i o n \( r e q , r e p l y \) { \d + m s \n │ ├ ─ ─ b o u n d _ a f t e r \d + m s \n │ └ ─ ─ b o u n d _ a f t e r \d + m s \n └ ─ ─ b o u n d _ a f t e r \d + m s \n / )
115
+ t . assert . ok ( spy . called )
116
+ t . assert . deepStrictEqual ( spy . args [ 0 ] [ 0 ] , 'debug' )
117
+ t . assert . match ( spy . args [ 0 ] [ 1 ] , / r o o t \d + m s \n ├ ─ ─ b o u n d _ a f t e r \d + m s \n ├ ─ ┬ a s y n c f u n c t i o n \( f a s t i f y , o p t i o n s \) { - - f a s t i f y \. g e t \( ' \/ ' , a s y n c f u n c t i o n \( r e q , r e p l y \) { \d + m s \n │ ├ ─ ─ b o u n d _ a f t e r \d + m s \n │ └ ─ ─ b o u n d _ a f t e r \d + m s \n └ ─ ─ b o u n d _ a f t e r \d + m s \n / )
119
118
} )
0 commit comments