Skip to content

Commit

Permalink
test: #5555 - move to node test runner (#440)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SamSalvatico authored Jan 31, 2025
1 parent 2b3a6ec commit e4ae352
Show file tree
Hide file tree
Showing 35 changed files with 1,430 additions and 1,448 deletions.
4 changes: 4 additions & 0 deletions .borp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
files:
- 'test/issues/*/test.js'
- 'test/commonjs/*.js'
- 'test/module/*.js'
4 changes: 0 additions & 4 deletions .taprc

This file was deleted.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"typescript:native": "node scripts/unit-typescript-native-type-stripping.js",
"typescript:vitest": "vitest run",
"typescript:vitest:dev": "vitest",
"unit": "node scripts/unit.js",
"unit:with-modules": "tap plugin rm @tapjs/typescript && tap plugin list && tap build && tap test/issues/*/test.js test/commonjs/*.js test/module/*.js"
"unit": "borp -C --check-coverage --lines 100 --reporter=@jsumners/line-reporter"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -76,19 +75,19 @@
"devDependencies": {
"@fastify/pre-commit": "^2.1.0",
"@fastify/url-data": "^6.0.0",
"@jsumners/line-reporter": "^1.0.1",
"@swc-node/register": "^1.9.1",
"@swc/core": "^1.5.25",
"@types/jest": "^29.5.12",
"@types/node": "^22.0.0",
"@types/tap": "^18.0.0",
"borp": "^0.19.0",
"esbuild": "^0.24.0",
"esbuild-register": "^3.5.0",
"eslint": "^9.17.0",
"fastify": "^5.0.0",
"fastify-plugin": "^5.0.0",
"jest": "^29.7.0",
"neostandard": "^0.12.0",
"tap": "^19.0.2",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
Expand Down
9 changes: 4 additions & 5 deletions scripts/unit-typescript-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
const { exec } = require('node:child_process')

const args = [
'tap',
'--node-arg=--loader=ts-node/esm',
'--node-arg=--experimental-specifier-resolution=node',
'--disable-coverage',
'--allow-empty-coverage',
'node',
'--loader=ts-node/esm',
'--experimental-specifier-resolution=node',
'--test',
'test/typescript-esm/*.ts'
]

Expand Down
1 change: 1 addition & 0 deletions scripts/unit-typescript-tsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { exec } = require('node:child_process')
const args = [
'node',
'--require=tsm',
'--test',
'test/typescript/basic.ts'
]

Expand Down
9 changes: 0 additions & 9 deletions scripts/unit.js

This file was deleted.

61 changes: 28 additions & 33 deletions test/commonjs/autohooks-basic.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
'use strict'

const t = require('tap')
const { after, before, describe, it } = require('node:test')
const assert = require('node:assert')
const Fastify = require('fastify')

t.plan(13)

const app = Fastify()

app.register(require('./autohooks/basic'))
app.decorateRequest('hooked', '')
describe('Node test suite for autohooks-basic', function () {
const app = Fastify()
before(async function () {
app.register(require('./autohooks/basic'))
app.decorateRequest('hooked', '')
await app.ready()
})

app.ready(function (err) {
t.error(err)
after(async function () {
await app.close()
})

app.inject({
url: '/'
}, function (err, res) {
t.error(err)
it('should respond correctly to /', async function () {
const res = await app.inject({ url: '/' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['root'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] })
})

app.inject({
url: '/child'
}, function (err, res) {
t.error(err)
it('should respond correctly to /child', async function () {
const res = await app.inject({ url: '/child' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['child'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['child'] })
})

app.inject({
url: '/child/grandchild'
}, function (err, res) {
t.error(err)
it('should respond correctly to /child/grandchild', async function () {
const res = await app.inject({ url: '/child/grandchild' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['grandchild'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['grandchild'] })
})

app.inject({
url: '/sibling'
}, function (err, res) {
t.error(err)
it('should respond correctly to /sibling', async function () {
const res = await app.inject({ url: '/sibling' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: '' })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: '' })
})
})
61 changes: 28 additions & 33 deletions test/commonjs/autohooks-cascade.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
'use strict'

const t = require('tap')
const { after, before, describe, it } = require('node:test')
const assert = require('node:assert')
const Fastify = require('fastify')

t.plan(13)

const app = Fastify()

app.register(require('./autohooks/cascade'))
app.decorateRequest('hooked', '')
describe('Node test suite for autohooks-cascade', function () {
const app = Fastify()
before(async function () {
app.register(require('./autohooks/cascade'))
app.decorateRequest('hooked', '')
await app.ready()
})

app.ready(function (err) {
t.error(err)
after(async function () {
await app.close()
})

app.inject({
url: '/'
}, function (err, res) {
t.error(err)
it('should respond correctly to /', async function () {
const res = await app.inject({ url: '/' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['root'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] })
})

app.inject({
url: '/child'
}, function (err, res) {
t.error(err)
it('should respond correctly to /child', async function () {
const res = await app.inject({ url: '/child' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['root', 'child'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root', 'child'] })
})

app.inject({
url: '/child/grandchild'
}, function (err, res) {
t.error(err)
it('should respond correctly to /child/grandchild', async function () {
const res = await app.inject({ url: '/child/grandchild' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['root', 'child', 'grandchild'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root', 'child', 'grandchild'] })
})

app.inject({
url: '/sibling'
}, function (err, res) {
t.error(err)
it('should respond correctly to /sibling', async function () {
const res = await app.inject({ url: '/sibling' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['root'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] })
})
})
61 changes: 28 additions & 33 deletions test/commonjs/autohooks-disabled.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
'use strict'

const t = require('tap')
const { after, before, describe, it } = require('node:test')
const assert = require('node:assert')
const Fastify = require('fastify')

t.plan(13)

const app = Fastify()

app.register(require('./autohooks/disabled'))
app.decorateRequest('hooked', 'disabled')
describe('Node test suite for autohooks-disabled', function () {
const app = Fastify()
before(async function () {
app.register(require('./autohooks/disabled'))
app.decorateRequest('hooked', 'disabled')
await app.ready()
})

app.ready(function (err) {
t.error(err)
after(async function () {
await app.close()
})

app.inject({
url: '/'
}, function (err, res) {
t.error(err)
it('should respond correctly to /', async function () {
const res = await app.inject({ url: '/' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: 'disabled' })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: 'disabled' })
})

app.inject({
url: '/child'
}, function (err, res) {
t.error(err)
it('should respond correctly to /child', async function () {
const res = await app.inject({ url: '/child' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: 'disabled' })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: 'disabled' })
})

app.inject({
url: '/child/grandchild'
}, function (err, res) {
t.error(err)
it('should respond correctly to /child/grandchild', async function () {
const res = await app.inject({ url: '/child/grandchild' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: 'disabled' })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: 'disabled' })
})

app.inject({
url: '/sibling'
}, function (err, res) {
t.error(err)
it('should respond correctly to /sibling', async function () {
const res = await app.inject({ url: '/sibling' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: 'disabled' })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: 'disabled' })
})
})
61 changes: 28 additions & 33 deletions test/commonjs/autohooks-overwrite.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
'use strict'

const t = require('tap')
const { after, before, describe, it } = require('node:test')
const assert = require('node:assert')
const Fastify = require('fastify')

t.plan(13)

const app = Fastify()

app.register(require('./autohooks/overwrite'))
app.decorateRequest('hooked', '')
describe('Node test suite for autohooks-overwrite', function () {
const app = Fastify()
before(async function () {
app.register(require('./autohooks/overwrite'))
app.decorateRequest('hooked', '')
await app.ready()
})

app.ready(function (err) {
t.error(err)
after(async function () {
await app.close()
})

app.inject({
url: '/'
}, function (err, res) {
t.error(err)
it('should respond correctly to /', async function () {
const res = await app.inject({ url: '/' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['root'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] })
})

app.inject({
url: '/child'
}, function (err, res) {
t.error(err)
it('should respond correctly to /child', async function () {
const res = await app.inject({ url: '/child' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['child'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['child'] })
})

app.inject({
url: '/child/grandchild'
}, function (err, res) {
t.error(err)
it('should respond correctly to /child/grandchild', async function () {
const res = await app.inject({ url: '/child/grandchild' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['grandchild'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['grandchild'] })
})

app.inject({
url: '/sibling'
}, function (err, res) {
t.error(err)
it('should respond correctly to /sibling', async function () {
const res = await app.inject({ url: '/sibling' })

t.equal(res.statusCode, 200)
t.same(JSON.parse(res.payload), { hooked: ['root'] })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] })
})
})
Loading

0 comments on commit e4ae352

Please sign in to comment.