22
33const fs = require ( 'node:fs' )
44const path = require ( 'node:path' )
5- const t = require ( 'tap ' )
5+ const { test } = require ( 'node:test ' )
66const fastify = require ( 'fastify' )
77const sanitize = require ( 'sanitize-filename' )
88
@@ -16,10 +16,10 @@ function generateFileName (routeOpts) {
1616 return fileName
1717}
1818
19- t . test ( 'standalone' , t => {
19+ test ( 'standalone' , async t => {
2020 t . plan ( 5 )
2121
22- t . teardown ( async ( ) => {
22+ t . after ( async ( ) => {
2323 for ( const fileName of generatedFileNames ) {
2424 try {
2525 await fs . promises . unlink ( path . join ( __dirname , fileName ) )
@@ -29,10 +29,10 @@ t.test('standalone', t => {
2929
3030 t . test ( 'errors' , t => {
3131 t . plan ( 2 )
32- t . throws ( ( ) => {
32+ t . assert . throws ( ( ) => {
3333 FjsStandaloneCompiler ( )
3434 } , 'missing restoreFunction' )
35- t . throws ( ( ) => {
35+ t . assert . throws ( ( ) => {
3636 FjsStandaloneCompiler ( { readMode : false } )
3737 } , 'missing storeFunction' )
3838 } )
@@ -74,28 +74,28 @@ t.test('standalone', t => {
7474 const factory = FjsStandaloneCompiler ( {
7575 readMode : false ,
7676 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' )
7979 fs . writeFileSync ( path . join ( __dirname , '/fjs-generated.js' ) , schemaSerializerCode )
8080 generatedFileNames . push ( '/fjs-generated.js' )
81- t . pass ( 'stored the serializer function' )
81+ t . assert . ok ( 'stored the serializer function' )
8282 }
8383 } )
8484
8585 const compiler = factory ( schemaMap )
8686 compiler ( endpointSchema )
87- t . pass ( 'compiled the endpoint schema' )
87+ t . assert . ok ( 'compiled the endpoint schema' )
8888
8989 t . test ( 'usage standalone code' , t => {
9090 t . plan ( 3 )
9191 const standaloneSerializer = require ( './fjs-generated' )
92- t . ok ( standaloneSerializer )
92+ t . assert . ok ( standaloneSerializer )
9393
9494 const valid = standaloneSerializer ( { hello : 'world' } )
95- t . same ( valid , JSON . stringify ( { hello : 'world' } ) )
95+ t . assert . deepStrictEqual ( valid , JSON . stringify ( { hello : 'world' } ) )
9696
9797 const invalid = standaloneSerializer ( { hello : [ ] } )
98- t . same ( invalid , '{"hello":""}' )
98+ t . assert . deepStrictEqual ( invalid , '{"hello":""}' )
9999 } )
100100 } )
101101
@@ -106,9 +106,9 @@ t.test('standalone', t => {
106106 readMode : false ,
107107 storeFunction ( routeOpts , schemaSerializationCode ) {
108108 const fileName = generateFileName ( routeOpts )
109- t . ok ( routeOpts )
109+ t . assert . ok ( routeOpts )
110110 fs . writeFileSync ( path . join ( __dirname , fileName ) , schemaSerializationCode )
111- t . pass ( `stored the serializer function ${ fileName } ` )
111+ t . assert . ok ( `stored the serializer function ${ fileName } ` )
112112 } ,
113113 restoreFunction ( ) {
114114 t . fail ( 'write mode ON' )
@@ -119,16 +119,16 @@ t.test('standalone', t => {
119119 await app . ready ( )
120120 } )
121121
122- t . test ( 'fastify integration - writeMode forces standalone' , async t => {
122+ await t . test ( 'fastify integration - writeMode forces standalone' , async t => {
123123 t . plan ( 4 )
124124
125125 const factory = FjsStandaloneCompiler ( {
126126 readMode : false ,
127127 storeFunction ( routeOpts , schemaSerializationCode ) {
128128 const fileName = generateFileName ( routeOpts )
129- t . ok ( routeOpts )
129+ t . assert . ok ( routeOpts )
130130 fs . writeFileSync ( path . join ( __dirname , fileName ) , schemaSerializationCode )
131- t . pass ( `stored the serializer function ${ fileName } ` )
131+ t . assert . ok ( `stored the serializer function ${ fileName } ` )
132132 } ,
133133 restoreFunction ( ) {
134134 t . fail ( 'write mode ON' )
@@ -143,7 +143,7 @@ t.test('standalone', t => {
143143 await app . ready ( )
144144 } )
145145
146- t . test ( 'fastify integration - readMode' , async t => {
146+ await t . test ( 'fastify integration - readMode' , async t => {
147147 t . plan ( 6 )
148148
149149 const factory = FjsStandaloneCompiler ( {
@@ -153,7 +153,7 @@ t.test('standalone', t => {
153153 } ,
154154 restoreFunction ( routeOpts ) {
155155 const fileName = generateFileName ( routeOpts )
156- t . pass ( `restore the serializer function ${ fileName } }` )
156+ t . assert . ok ( `restore the serializer function ${ fileName } }` )
157157 return require ( path . join ( __dirname , fileName ) )
158158 }
159159 } )
@@ -165,15 +165,15 @@ t.test('standalone', t => {
165165 url : '/foo' ,
166166 method : 'POST'
167167 } )
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' } ) )
170170
171171 res = await app . inject ( {
172172 url : '/bar?lang=it' ,
173173 method : 'GET'
174174 } )
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' } ) )
177177 } )
178178
179179 function buildApp ( factory , serializerOpts ) {
0 commit comments