Skip to content

Commit eebe7d9

Browse files
authored
feat: migrate to node test runner (#64)
1 parent 0b0292a commit eebe7d9

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"scripts": {
99
"lint": "eslint",
1010
"lint:fix": "eslint --fix",
11-
"unit": "tap test/**/*.test.js",
11+
"unit": "c8 --100 node --test",
1212
"test": "npm run unit && npm run test:typescript",
1313
"test:typescript": "tsd"
1414
},
@@ -54,11 +54,11 @@
5454
],
5555
"devDependencies": {
5656
"@fastify/pre-commit": "^2.1.0",
57+
"c8": "^10.1.3",
5758
"eslint": "^9.17.0",
5859
"fastify": "^5.0.0",
5960
"neostandard": "^0.12.0",
6061
"sanitize-filename": "^1.6.3",
61-
"tap": "^18.7.2",
6262
"tsd": "^0.31.0"
6363
},
6464
"pre-commit": [

Diff for: test/duplicate-schema.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const { test } = require('node:test')
44
const FjsCompiler = require('../index')
55

6-
t.test('Use input schema duplicate in the externalSchemas', async t => {
6+
test('Use input schema duplicate in the externalSchemas', async t => {
77
t.plan(1)
88
const externalSchemas = {
99
schema1: {
@@ -22,5 +22,5 @@ t.test('Use input schema duplicate in the externalSchemas', async t => {
2222
compiler({ schema: externalSchemas.schema1 })
2323
compiler({ schema: externalSchemas.schema2 })
2424

25-
t.pass()
25+
t.assert.ok(true)
2626
})

Diff for: test/plugin.test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const { test } = require('node:test')
44
const fastify = require('fastify')
55
const FjsCompiler = require('../index')
66

@@ -27,16 +27,16 @@ const externalSchemas2 = Object.freeze({
2727

2828
const fastifyFjsOptionsDefault = Object.freeze({})
2929

30-
t.test('basic usage', t => {
30+
test('basic usage', t => {
3131
t.plan(1)
3232
const factory = FjsCompiler()
3333
const compiler = factory(externalSchemas1, fastifyFjsOptionsDefault)
3434
const serializeFunc = compiler({ schema: sampleSchema })
3535
const result = serializeFunc({ name: 'hello' })
36-
t.equal(result, '{"name":"hello"}')
36+
t.assert.equal(result, '{"name":"hello"}')
3737
})
3838

39-
t.test('fastify integration', async t => {
39+
test('fastify integration', async t => {
4040
const factory = FjsCompiler()
4141

4242
const app = fastify({
@@ -73,6 +73,6 @@ t.test('fastify integration', async t => {
7373
}
7474
})
7575

76-
t.equal(res.statusCode, 200)
77-
t.same(res.json(), { name: 'serialize me' })
76+
t.assert.equal(res.statusCode, 200)
77+
t.assert.deepStrictEqual(res.json(), { name: 'serialize me' })
7878
})

Diff for: test/standalone.test.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const fs = require('node:fs')
44
const path = require('node:path')
5-
const t = require('tap')
5+
const { test } = require('node:test')
66
const fastify = require('fastify')
77
const 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

Comments
 (0)