2
2
3
3
const fs = require ( 'node:fs' )
4
4
const path = require ( 'node:path' )
5
- const t = require ( 'tap ' )
5
+ const { test } = require ( 'node:test ' )
6
6
const fastify = require ( 'fastify' )
7
7
const sanitize = require ( 'sanitize-filename' )
8
8
@@ -16,10 +16,10 @@ function generateFileName (routeOpts) {
16
16
return fileName
17
17
}
18
18
19
- t . test ( 'standalone' , t => {
19
+ test ( 'standalone' , async t => {
20
20
t . plan ( 5 )
21
21
22
- t . teardown ( async ( ) => {
22
+ t . after ( async ( ) => {
23
23
for ( const fileName of generatedFileNames ) {
24
24
try {
25
25
await fs . promises . unlink ( path . join ( __dirname , fileName ) )
@@ -29,10 +29,10 @@ t.test('standalone', t => {
29
29
30
30
t . test ( 'errors' , t => {
31
31
t . plan ( 2 )
32
- t . throws ( ( ) => {
32
+ t . assert . throws ( ( ) => {
33
33
FjsStandaloneCompiler ( )
34
34
} , 'missing restoreFunction' )
35
- t . throws ( ( ) => {
35
+ t . assert . throws ( ( ) => {
36
36
FjsStandaloneCompiler ( { readMode : false } )
37
37
} , 'missing storeFunction' )
38
38
} )
@@ -74,28 +74,28 @@ t.test('standalone', t => {
74
74
const factory = FjsStandaloneCompiler ( {
75
75
readMode : false ,
76
76
storeFunction ( routeOpts , schemaSerializerCode ) {
77
- t . same ( routeOpts , endpointSchema )
78
- t . type ( schemaSerializerCode , 'string' )
77
+ t . assert . deepStrictEqual ( routeOpts , endpointSchema )
78
+ t . assert . ok ( typeof schemaSerializerCode === 'string' )
79
79
fs . writeFileSync ( path . join ( __dirname , '/fjs-generated.js' ) , schemaSerializerCode )
80
80
generatedFileNames . push ( '/fjs-generated.js' )
81
- t . pass ( 'stored the serializer function' )
81
+ t . assert . ok ( 'stored the serializer function' )
82
82
}
83
83
} )
84
84
85
85
const compiler = factory ( schemaMap )
86
86
compiler ( endpointSchema )
87
- t . pass ( 'compiled the endpoint schema' )
87
+ t . assert . ok ( 'compiled the endpoint schema' )
88
88
89
89
t . test ( 'usage standalone code' , t => {
90
90
t . plan ( 3 )
91
91
const standaloneSerializer = require ( './fjs-generated' )
92
- t . ok ( standaloneSerializer )
92
+ t . assert . ok ( standaloneSerializer )
93
93
94
94
const valid = standaloneSerializer ( { hello : 'world' } )
95
- t . same ( valid , JSON . stringify ( { hello : 'world' } ) )
95
+ t . assert . deepStrictEqual ( valid , JSON . stringify ( { hello : 'world' } ) )
96
96
97
97
const invalid = standaloneSerializer ( { hello : [ ] } )
98
- t . same ( invalid , '{"hello":""}' )
98
+ t . assert . deepStrictEqual ( invalid , '{"hello":""}' )
99
99
} )
100
100
} )
101
101
@@ -106,9 +106,9 @@ t.test('standalone', t => {
106
106
readMode : false ,
107
107
storeFunction ( routeOpts , schemaSerializationCode ) {
108
108
const fileName = generateFileName ( routeOpts )
109
- t . ok ( routeOpts )
109
+ t . assert . ok ( routeOpts )
110
110
fs . writeFileSync ( path . join ( __dirname , fileName ) , schemaSerializationCode )
111
- t . pass ( `stored the serializer function ${ fileName } ` )
111
+ t . assert . ok ( `stored the serializer function ${ fileName } ` )
112
112
} ,
113
113
restoreFunction ( ) {
114
114
t . fail ( 'write mode ON' )
@@ -119,16 +119,16 @@ t.test('standalone', t => {
119
119
await app . ready ( )
120
120
} )
121
121
122
- t . test ( 'fastify integration - writeMode forces standalone' , async t => {
122
+ await t . test ( 'fastify integration - writeMode forces standalone' , async t => {
123
123
t . plan ( 4 )
124
124
125
125
const factory = FjsStandaloneCompiler ( {
126
126
readMode : false ,
127
127
storeFunction ( routeOpts , schemaSerializationCode ) {
128
128
const fileName = generateFileName ( routeOpts )
129
- t . ok ( routeOpts )
129
+ t . assert . ok ( routeOpts )
130
130
fs . writeFileSync ( path . join ( __dirname , fileName ) , schemaSerializationCode )
131
- t . pass ( `stored the serializer function ${ fileName } ` )
131
+ t . assert . ok ( `stored the serializer function ${ fileName } ` )
132
132
} ,
133
133
restoreFunction ( ) {
134
134
t . fail ( 'write mode ON' )
@@ -143,7 +143,7 @@ t.test('standalone', t => {
143
143
await app . ready ( )
144
144
} )
145
145
146
- t . test ( 'fastify integration - readMode' , async t => {
146
+ await t . test ( 'fastify integration - readMode' , async t => {
147
147
t . plan ( 6 )
148
148
149
149
const factory = FjsStandaloneCompiler ( {
@@ -153,7 +153,7 @@ t.test('standalone', t => {
153
153
} ,
154
154
restoreFunction ( routeOpts ) {
155
155
const fileName = generateFileName ( routeOpts )
156
- t . pass ( `restore the serializer function ${ fileName } }` )
156
+ t . assert . ok ( `restore the serializer function ${ fileName } }` )
157
157
return require ( path . join ( __dirname , fileName ) )
158
158
}
159
159
} )
@@ -165,15 +165,15 @@ t.test('standalone', t => {
165
165
url : '/foo' ,
166
166
method : 'POST'
167
167
} )
168
- t . equal ( res . statusCode , 200 )
169
- t . equal ( res . payload , JSON . stringify ( { hello : 'world' } ) )
168
+ t . assert . equal ( res . statusCode , 200 )
169
+ t . assert . equal ( res . payload , JSON . stringify ( { hello : 'world' } ) )
170
170
171
171
res = await app . inject ( {
172
172
url : '/bar?lang=it' ,
173
173
method : 'GET'
174
174
} )
175
- t . equal ( res . statusCode , 200 )
176
- t . equal ( res . payload , JSON . stringify ( { lang : 'en' } ) )
175
+ t . assert . equal ( res . statusCode , 200 )
176
+ t . assert . equal ( res . payload , JSON . stringify ( { lang : 'en' } ) )
177
177
} )
178
178
179
179
function buildApp ( factory , serializerOpts ) {
0 commit comments