Skip to content

Commit 150564a

Browse files
authored
test: moved everything to node test runner (#214)
1 parent 194a5a7 commit 150564a

5 files changed

Lines changed: 92 additions & 124 deletions

File tree

jest.config.json

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
"types": "types/index.d.ts",
1515
"scripts": {
1616
"test": "npm run test:unit && npm run test:typescript",
17-
"test:coverage": "tap test-tap/*.test.js",
18-
"test:jest": "jest --config=jest.config.json",
19-
"test:tap": "tap",
20-
"test:unit": "npm run test:jest && npm run test:tap",
17+
"test:unit": "c8 --100 node --test",
2118
"test:typescript": "tsd",
2219
"lint": "eslint \"test/**/*.js\" \"test-tap/**/*.js\" index.js",
2320
"prettier": "prettier --write \"{lib,test,test-tap}/**/*.js\" index.js \"types/**/*.ts\""
@@ -28,14 +25,13 @@
2825
"devDependencies": {
2926
"@fastify/pre-commit": "^2.1.0",
3027
"@types/node": "^22.0.0",
28+
"c8": "^10.1.3",
3129
"eslint": "^9.6.0",
3230
"eslint-config-prettier": "^10.0.1",
3331
"eslint-plugin-prettier": "^5.1.3",
3432
"fastify": "^5.0.0",
35-
"jest": "^29.7.0",
3633
"prettier": "^3.2.5",
3734
"superagent": "^10.0.0",
38-
"tap": "^20.0.1",
3935
"tsd": "^0.31.1"
4036
},
4137
"homepage": "http://github.com/fastify/fastify-request-context",

test-tap/requestContextPlugin.e2e.test.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ const {
99
} = require('../test/internal/appInitializer')
1010
const { fastifyRequestContext } = require('..')
1111
const { TestService } = require('../test/internal/testService')
12-
const t = require('tap')
12+
const { test, afterEach } = require('node:test')
1313
const { CustomResource, AsyncHookContainer } = require('../test/internal/watcherService')
1414
const { executionAsyncId } = require('node:async_hooks')
15-
const test = t.test
1615

1716
let app
18-
t.afterEach(() => {
17+
afterEach(() => {
1918
return app.close()
2019
})
2120

@@ -59,7 +58,7 @@ test('correctly preserves values set in prevalidation phase within single POST r
5958
const response1Promise = request('POST', url)
6059
.send({ requestId: 1 })
6160
.then((response) => {
62-
t.equal(response.body.storedValue, 'testValue1')
61+
t.assert.deepStrictEqual(response.body.storedValue, 'testValue1')
6362
responseCounter++
6463
if (responseCounter === 2) {
6564
resolveResponsePromise()
@@ -69,7 +68,7 @@ test('correctly preserves values set in prevalidation phase within single POST r
6968
const response2Promise = request('POST', url)
7069
.send({ requestId: 2 })
7170
.then((response) => {
72-
t.equal(response.body.storedValue, 'testValue2')
71+
t.assert.deepStrictEqual(response.body.storedValue, 'testValue2')
7372
responseCounter++
7473
if (responseCounter === 2) {
7574
resolveResponsePromise()
@@ -101,10 +100,10 @@ test('correctly preserves values set in multiple phases within single POST reque
101100
const preValidationValue = req.requestContext.get('preValidation')
102101
const preHandlerValue = req.requestContext.get('preHandler')
103102

104-
t.equal(onRequestValue, undefined)
105-
t.equal(preParsingValue, undefined)
106-
t.type(preValidationValue, 'number')
107-
t.type(preHandlerValue, 'number')
103+
t.assert.deepStrictEqual(onRequestValue, undefined)
104+
t.assert.deepStrictEqual(preParsingValue, undefined)
105+
t.assert.ok(typeof preValidationValue === 'number')
106+
t.assert.ok(typeof preHandlerValue === 'number')
108107

109108
const requestId = `testValue${preHandlerValue}`
110109

@@ -138,7 +137,7 @@ test('correctly preserves values set in multiple phases within single POST reque
138137
const response1Promise = request('POST', url)
139138
.send({ requestId: 1 })
140139
.then((response) => {
141-
t.equal(response.body.storedValue, 'testValue1')
140+
t.assert.deepStrictEqual(response.body.storedValue, 'testValue1')
142141
responseCounter++
143142
if (responseCounter === 2) {
144143
resolveResponsePromise()
@@ -148,7 +147,7 @@ test('correctly preserves values set in multiple phases within single POST reque
148147
const response2Promise = request('POST', url)
149148
.send({ requestId: 2 })
150149
.then((response) => {
151-
t.equal(response.body.storedValue, 'testValue2')
150+
t.assert.deepStrictEqual(response.body.storedValue, 'testValue2')
152151
responseCounter++
153152
if (responseCounter === 2) {
154153
resolveResponsePromise()
@@ -175,10 +174,10 @@ test('correctly preserves values set in multiple phases within single POST reque
175174
const preValidationValue = req.requestContext.get('preValidation')
176175
const preHandlerValue = req.requestContext.get('preHandler')
177176

178-
t.equal(onRequestValue, 'dummy')
179-
t.equal(preParsingValue, 'dummy')
180-
t.type(preValidationValue, 'number')
181-
t.type(preHandlerValue, 'number')
177+
t.assert.deepStrictEqual(onRequestValue, 'dummy')
178+
t.assert.deepStrictEqual(preParsingValue, 'dummy')
179+
t.assert.ok(typeof preValidationValue === 'number')
180+
t.assert.ok(typeof preHandlerValue === 'number')
182181

183182
const requestId = `testValue${preHandlerValue}`
184183
return Promise.resolve({ storedValue: requestId })
@@ -192,9 +191,9 @@ test('correctly preserves values set in multiple phases within single POST reque
192191
return request('POST', url)
193192
.send({ requestId: 1 })
194193
.then((response) => {
195-
t.equal(response.body.storedValue, 'testValue1')
196-
t.equal(response.body.preSerialization1, 'dummy')
197-
t.equal(response.body.preSerialization2, 1)
194+
t.assert.deepStrictEqual(response.body.storedValue, 'testValue1')
195+
t.assert.deepStrictEqual(response.body.preSerialization1, 'dummy')
196+
t.assert.deepStrictEqual(response.body.preSerialization2, 1)
198197
})
199198
})
200199
})
@@ -220,10 +219,10 @@ test('does not affect new request context when mutating context data using no de
220219
return request('GET', url)
221220
.query({ action: 'setvalue' })
222221
.then((response1) => {
223-
t.equal(response1.body.userId, 'abc')
222+
t.assert.deepStrictEqual(response1.body.userId, 'abc')
224223

225224
return request('GET', url).then((response2) => {
226-
t.notOk(response2.body.userId)
225+
t.assert.ok(!response2.body.userId)
227226
})
228227
})
229228
})
@@ -252,10 +251,10 @@ test('does not affect new request context when mutating context data using defau
252251
return request('GET', url)
253252
.query({ action: 'setvalue' })
254253
.then((response1) => {
255-
t.equal(response1.body.userId, 'abc')
254+
t.assert.deepStrictEqual(response1.body.userId, 'abc')
256255

257256
return request('GET', url).then((response2) => {
258-
t.equal(response2.body.userId, 'bar')
257+
t.assert.deepStrictEqual(response2.body.userId, 'bar')
259258
})
260259
})
261260
})
@@ -284,10 +283,10 @@ test('does not affect new request context when mutating context data using defau
284283
return request('GET', url)
285284
.query({ action: 'setvalue' })
286285
.then((response1) => {
287-
t.equal(response1.body.userId, 'bob')
286+
t.assert.deepStrictEqual(response1.body.userId, 'bob')
288287

289288
return request('GET', url).then((response2) => {
290-
t.equal(response2.body.userId, 'system')
289+
t.assert.deepStrictEqual(response2.body.userId, 'system')
291290
})
292291
})
293292
})
@@ -309,7 +308,7 @@ test('ensure request instance is properly exposed to default values factory', (t
309308
const url = `${address}:${port}`
310309

311310
return request('GET', url).then((response1) => {
312-
t.equal(response1.body.userId, 'http')
311+
t.assert.deepStrictEqual(response1.body.userId, 'http')
313312
})
314313
})
315314
})
@@ -329,10 +328,10 @@ test('does not throw when accessing context object outside of context', (t) => {
329328
const { address, port } = app.server.address()
330329
const url = `${address}:${port}`
331330

332-
t.equal(app.requestContext.get('user'), undefined)
331+
t.assert.deepStrictEqual(app.requestContext.get('user'), undefined)
333332

334333
return request('GET', url).then((response1) => {
335-
t.equal(response1.body.userId, 'system')
334+
t.assert.deepStrictEqual(response1.body.userId, 'system')
336335
})
337336
})
338337
})
@@ -352,7 +351,7 @@ test('passing a custom resource factory function when create as AsyncResource',
352351

353352
const route = (req) => {
354353
const store = container.getStore(executionAsyncId())
355-
t.equal(store.traceId, '1111-2222-3333')
354+
t.assert.deepStrictEqual(store.traceId, '1111-2222-3333')
356355
return Promise.resolve({ userId: req.requestContext.get('user').id })
357356
}
358357

@@ -363,7 +362,7 @@ test('passing a custom resource factory function when create as AsyncResource',
363362
const url = `${address}:${port}`
364363

365364
return request('GET', url).then((response1) => {
366-
t.equal(response1.body.userId, 'system')
365+
t.assert.deepStrictEqual(response1.body.userId, 'system')
367366
})
368367
})
369368
})

0 commit comments

Comments
 (0)