Skip to content

Commit e4ae352

Browse files
authored
test: #5555 - move to node test runner (#440)
* test: forceEsm from tap to node test runner * test: updated test/typescript/basic.ts * test: updated test/commonjs/autohooks-basic.js * test: updated test/commonjs/autohooks-*.js * test: updated test/commonjs/babel-node.js and basic.js * test: updated cyclic * test: updated deep * test: updated dependency * test: updated commonjs/error * test: updated graph-dependency * test: updated commonjs/index-package.js * test: updated commonjs/non-plugin.js * test: updated commonjs/options.js * test: updated commonjs/route-parametrs.js * test: use promises in forceEsm * test: removed assert if error after promises * test: removed nested suites * test: updated issue 369 * test: updated issue 374 * test: updated issue 376 * Revert "test: updated issue 376" This reverts commit 71a6660. * test: updated issue 376 * test: updated issue 388 * test: updated module/autohooks * test: updated module/basic * test: updated module/dependency * test: updated module/route-parameters * test: updated module/index-package * test: updated module/options * test: fixed /route-parameters * test: updated module/esm-import * chore: removed tap from package.json * test: added glob to make windows able to expand patterns * test: try using fast-glob instead of glob * test: use borp instead of fast-glob script * test: readded coverage * test: added check on code coverage * chore: newline
1 parent 2b3a6ec commit e4ae352

35 files changed

+1430
-1448
lines changed

.borp.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
files:
2+
- 'test/issues/*/test.js'
3+
- 'test/commonjs/*.js'
4+
- 'test/module/*.js'

.taprc

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

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"typescript:native": "node scripts/unit-typescript-native-type-stripping.js",
2121
"typescript:vitest": "vitest run",
2222
"typescript:vitest:dev": "vitest",
23-
"unit": "node scripts/unit.js",
24-
"unit:with-modules": "tap plugin rm @tapjs/typescript && tap plugin list && tap build && tap test/issues/*/test.js test/commonjs/*.js test/module/*.js"
23+
"unit": "borp -C --check-coverage --lines 100 --reporter=@jsumners/line-reporter"
2524
},
2625
"repository": {
2726
"type": "git",
@@ -76,19 +75,19 @@
7675
"devDependencies": {
7776
"@fastify/pre-commit": "^2.1.0",
7877
"@fastify/url-data": "^6.0.0",
78+
"@jsumners/line-reporter": "^1.0.1",
7979
"@swc-node/register": "^1.9.1",
8080
"@swc/core": "^1.5.25",
8181
"@types/jest": "^29.5.12",
8282
"@types/node": "^22.0.0",
83-
"@types/tap": "^18.0.0",
83+
"borp": "^0.19.0",
8484
"esbuild": "^0.24.0",
8585
"esbuild-register": "^3.5.0",
8686
"eslint": "^9.17.0",
8787
"fastify": "^5.0.0",
8888
"fastify-plugin": "^5.0.0",
8989
"jest": "^29.7.0",
9090
"neostandard": "^0.12.0",
91-
"tap": "^19.0.2",
9291
"ts-jest": "^29.1.4",
9392
"ts-node": "^10.9.2",
9493
"ts-node-dev": "^2.0.0",

scripts/unit-typescript-esm.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
const { exec } = require('node:child_process')
44

55
const args = [
6-
'tap',
7-
'--node-arg=--loader=ts-node/esm',
8-
'--node-arg=--experimental-specifier-resolution=node',
9-
'--disable-coverage',
10-
'--allow-empty-coverage',
6+
'node',
7+
'--loader=ts-node/esm',
8+
'--experimental-specifier-resolution=node',
9+
'--test',
1110
'test/typescript-esm/*.ts'
1211
]
1312

scripts/unit-typescript-tsm.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { exec } = require('node:child_process')
55
const args = [
66
'node',
77
'--require=tsm',
8+
'--test',
89
'test/typescript/basic.ts'
910
]
1011

scripts/unit.js

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

test/commonjs/autohooks-basic.js

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const { after, before, describe, it } = require('node:test')
4+
const assert = require('node:assert')
45
const Fastify = require('fastify')
56

6-
t.plan(13)
7-
8-
const app = Fastify()
9-
10-
app.register(require('./autohooks/basic'))
11-
app.decorateRequest('hooked', '')
7+
describe('Node test suite for autohooks-basic', function () {
8+
const app = Fastify()
9+
before(async function () {
10+
app.register(require('./autohooks/basic'))
11+
app.decorateRequest('hooked', '')
12+
await app.ready()
13+
})
1214

13-
app.ready(function (err) {
14-
t.error(err)
15+
after(async function () {
16+
await app.close()
17+
})
1518

16-
app.inject({
17-
url: '/'
18-
}, function (err, res) {
19-
t.error(err)
19+
it('should respond correctly to /', async function () {
20+
const res = await app.inject({ url: '/' })
2021

21-
t.equal(res.statusCode, 200)
22-
t.same(JSON.parse(res.payload), { hooked: ['root'] })
22+
assert.strictEqual(res.statusCode, 200)
23+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] })
2324
})
2425

25-
app.inject({
26-
url: '/child'
27-
}, function (err, res) {
28-
t.error(err)
26+
it('should respond correctly to /child', async function () {
27+
const res = await app.inject({ url: '/child' })
2928

30-
t.equal(res.statusCode, 200)
31-
t.same(JSON.parse(res.payload), { hooked: ['child'] })
29+
assert.strictEqual(res.statusCode, 200)
30+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['child'] })
3231
})
3332

34-
app.inject({
35-
url: '/child/grandchild'
36-
}, function (err, res) {
37-
t.error(err)
33+
it('should respond correctly to /child/grandchild', async function () {
34+
const res = await app.inject({ url: '/child/grandchild' })
3835

39-
t.equal(res.statusCode, 200)
40-
t.same(JSON.parse(res.payload), { hooked: ['grandchild'] })
36+
assert.strictEqual(res.statusCode, 200)
37+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['grandchild'] })
4138
})
4239

43-
app.inject({
44-
url: '/sibling'
45-
}, function (err, res) {
46-
t.error(err)
40+
it('should respond correctly to /sibling', async function () {
41+
const res = await app.inject({ url: '/sibling' })
4742

48-
t.equal(res.statusCode, 200)
49-
t.same(JSON.parse(res.payload), { hooked: '' })
43+
assert.strictEqual(res.statusCode, 200)
44+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: '' })
5045
})
5146
})

test/commonjs/autohooks-cascade.js

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const { after, before, describe, it } = require('node:test')
4+
const assert = require('node:assert')
45
const Fastify = require('fastify')
56

6-
t.plan(13)
7-
8-
const app = Fastify()
9-
10-
app.register(require('./autohooks/cascade'))
11-
app.decorateRequest('hooked', '')
7+
describe('Node test suite for autohooks-cascade', function () {
8+
const app = Fastify()
9+
before(async function () {
10+
app.register(require('./autohooks/cascade'))
11+
app.decorateRequest('hooked', '')
12+
await app.ready()
13+
})
1214

13-
app.ready(function (err) {
14-
t.error(err)
15+
after(async function () {
16+
await app.close()
17+
})
1518

16-
app.inject({
17-
url: '/'
18-
}, function (err, res) {
19-
t.error(err)
19+
it('should respond correctly to /', async function () {
20+
const res = await app.inject({ url: '/' })
2021

21-
t.equal(res.statusCode, 200)
22-
t.same(JSON.parse(res.payload), { hooked: ['root'] })
22+
assert.strictEqual(res.statusCode, 200)
23+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] })
2324
})
2425

25-
app.inject({
26-
url: '/child'
27-
}, function (err, res) {
28-
t.error(err)
26+
it('should respond correctly to /child', async function () {
27+
const res = await app.inject({ url: '/child' })
2928

30-
t.equal(res.statusCode, 200)
31-
t.same(JSON.parse(res.payload), { hooked: ['root', 'child'] })
29+
assert.strictEqual(res.statusCode, 200)
30+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root', 'child'] })
3231
})
3332

34-
app.inject({
35-
url: '/child/grandchild'
36-
}, function (err, res) {
37-
t.error(err)
33+
it('should respond correctly to /child/grandchild', async function () {
34+
const res = await app.inject({ url: '/child/grandchild' })
3835

39-
t.equal(res.statusCode, 200)
40-
t.same(JSON.parse(res.payload), { hooked: ['root', 'child', 'grandchild'] })
36+
assert.strictEqual(res.statusCode, 200)
37+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root', 'child', 'grandchild'] })
4138
})
4239

43-
app.inject({
44-
url: '/sibling'
45-
}, function (err, res) {
46-
t.error(err)
40+
it('should respond correctly to /sibling', async function () {
41+
const res = await app.inject({ url: '/sibling' })
4742

48-
t.equal(res.statusCode, 200)
49-
t.same(JSON.parse(res.payload), { hooked: ['root'] })
43+
assert.strictEqual(res.statusCode, 200)
44+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] })
5045
})
5146
})
Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const { after, before, describe, it } = require('node:test')
4+
const assert = require('node:assert')
45
const Fastify = require('fastify')
56

6-
t.plan(13)
7-
8-
const app = Fastify()
9-
10-
app.register(require('./autohooks/disabled'))
11-
app.decorateRequest('hooked', 'disabled')
7+
describe('Node test suite for autohooks-disabled', function () {
8+
const app = Fastify()
9+
before(async function () {
10+
app.register(require('./autohooks/disabled'))
11+
app.decorateRequest('hooked', 'disabled')
12+
await app.ready()
13+
})
1214

13-
app.ready(function (err) {
14-
t.error(err)
15+
after(async function () {
16+
await app.close()
17+
})
1518

16-
app.inject({
17-
url: '/'
18-
}, function (err, res) {
19-
t.error(err)
19+
it('should respond correctly to /', async function () {
20+
const res = await app.inject({ url: '/' })
2021

21-
t.equal(res.statusCode, 200)
22-
t.same(JSON.parse(res.payload), { hooked: 'disabled' })
22+
assert.strictEqual(res.statusCode, 200)
23+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: 'disabled' })
2324
})
2425

25-
app.inject({
26-
url: '/child'
27-
}, function (err, res) {
28-
t.error(err)
26+
it('should respond correctly to /child', async function () {
27+
const res = await app.inject({ url: '/child' })
2928

30-
t.equal(res.statusCode, 200)
31-
t.same(JSON.parse(res.payload), { hooked: 'disabled' })
29+
assert.strictEqual(res.statusCode, 200)
30+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: 'disabled' })
3231
})
3332

34-
app.inject({
35-
url: '/child/grandchild'
36-
}, function (err, res) {
37-
t.error(err)
33+
it('should respond correctly to /child/grandchild', async function () {
34+
const res = await app.inject({ url: '/child/grandchild' })
3835

39-
t.equal(res.statusCode, 200)
40-
t.same(JSON.parse(res.payload), { hooked: 'disabled' })
36+
assert.strictEqual(res.statusCode, 200)
37+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: 'disabled' })
4138
})
4239

43-
app.inject({
44-
url: '/sibling'
45-
}, function (err, res) {
46-
t.error(err)
40+
it('should respond correctly to /sibling', async function () {
41+
const res = await app.inject({ url: '/sibling' })
4742

48-
t.equal(res.statusCode, 200)
49-
t.same(JSON.parse(res.payload), { hooked: 'disabled' })
43+
assert.strictEqual(res.statusCode, 200)
44+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: 'disabled' })
5045
})
5146
})
Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const { after, before, describe, it } = require('node:test')
4+
const assert = require('node:assert')
45
const Fastify = require('fastify')
56

6-
t.plan(13)
7-
8-
const app = Fastify()
9-
10-
app.register(require('./autohooks/overwrite'))
11-
app.decorateRequest('hooked', '')
7+
describe('Node test suite for autohooks-overwrite', function () {
8+
const app = Fastify()
9+
before(async function () {
10+
app.register(require('./autohooks/overwrite'))
11+
app.decorateRequest('hooked', '')
12+
await app.ready()
13+
})
1214

13-
app.ready(function (err) {
14-
t.error(err)
15+
after(async function () {
16+
await app.close()
17+
})
1518

16-
app.inject({
17-
url: '/'
18-
}, function (err, res) {
19-
t.error(err)
19+
it('should respond correctly to /', async function () {
20+
const res = await app.inject({ url: '/' })
2021

21-
t.equal(res.statusCode, 200)
22-
t.same(JSON.parse(res.payload), { hooked: ['root'] })
22+
assert.strictEqual(res.statusCode, 200)
23+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] })
2324
})
2425

25-
app.inject({
26-
url: '/child'
27-
}, function (err, res) {
28-
t.error(err)
26+
it('should respond correctly to /child', async function () {
27+
const res = await app.inject({ url: '/child' })
2928

30-
t.equal(res.statusCode, 200)
31-
t.same(JSON.parse(res.payload), { hooked: ['child'] })
29+
assert.strictEqual(res.statusCode, 200)
30+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['child'] })
3231
})
3332

34-
app.inject({
35-
url: '/child/grandchild'
36-
}, function (err, res) {
37-
t.error(err)
33+
it('should respond correctly to /child/grandchild', async function () {
34+
const res = await app.inject({ url: '/child/grandchild' })
3835

39-
t.equal(res.statusCode, 200)
40-
t.same(JSON.parse(res.payload), { hooked: ['grandchild'] })
36+
assert.strictEqual(res.statusCode, 200)
37+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['grandchild'] })
4138
})
4239

43-
app.inject({
44-
url: '/sibling'
45-
}, function (err, res) {
46-
t.error(err)
40+
it('should respond correctly to /sibling', async function () {
41+
const res = await app.inject({ url: '/sibling' })
4742

48-
t.equal(res.statusCode, 200)
49-
t.same(JSON.parse(res.payload), { hooked: ['root'] })
43+
assert.strictEqual(res.statusCode, 200)
44+
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] })
5045
})
5146
})

0 commit comments

Comments
 (0)