Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migrate from tap to node test and c8 #248

Merged
merged 4 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .taprc

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"scripts": {
"lint": "standard",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "tap",
"test:unit": "c8 --100 node --test",
"test:coverage": "c8 node --test && c8 report --reporter=html",
"test:typescript": "tsd"
},
"repository": {
Expand All @@ -30,10 +31,10 @@
"@fastify/pre-commit": "^2.1.0",
"@fastify/type-provider-typebox": "^5.0.0-pre.fv5.1",
"@types/node": "^22.0.0",
"c8": "^10.1.2",
nimesh0505 marked this conversation as resolved.
Show resolved Hide resolved
"fastify": "^5.0.0-alpha.2",
"proxyquire": "^2.1.3",
"standard": "^17.1.0",
"tap": "^18.7.0",
"tsd": "^0.31.0"
}
}
34 changes: 12 additions & 22 deletions test/bundlers.test.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const fp = require('../plugin')

test('webpack removes require.main.filename', (t) => {
test('webpack removes require.main.filename', t => {
const filename = require.main.filename
const info = console.info
t.teardown(() => {
t.after(() => {
require.main.filename = filename
console.info = info
})

require.main.filename = null

console.info = function (msg) {
t.fail('logged: ' + msg)
t.assert.fail('logged: ' + msg)
}

fp((fastify, opts, next) => {
next()
}, {
fastify: '^5.0.0'
})

t.end()
})

test('support faux modules', (t) => {
const plugin = fp((fastify, opts, next) => {
next()
})

t.equal(plugin.default, plugin)
t.end()
t.assert.strictEqual(plugin.default, plugin)
})

test('support faux modules does not override existing default field in babel module', (t) => {
Expand All @@ -44,8 +41,7 @@ test('support faux modules does not override existing default field in babel mod

const plugin = fp(module)

t.equal(plugin.default, 'Existing default field')
t.end()
t.assert.strictEqual(plugin.default, 'Existing default field')
})

test('support ts named imports', (t) => {
Expand All @@ -55,8 +51,7 @@ test('support ts named imports', (t) => {
name: 'hello'
})

t.equal(plugin.hello, plugin)
t.end()
t.assert.strictEqual(plugin.hello, plugin)
})

test('from kebab-case to camelCase', (t) => {
Expand All @@ -66,8 +61,7 @@ test('from kebab-case to camelCase', (t) => {
name: 'hello-world'
})

t.equal(plugin.helloWorld, plugin)
t.end()
t.assert.strictEqual(plugin.helloWorld, plugin)
})

test('from @-prefixed named imports', (t) => {
Expand All @@ -77,8 +71,7 @@ test('from @-prefixed named imports', (t) => {
name: '@hello/world'
})

t.equal(plugin.helloWorld, plugin)
t.end()
t.assert.strictEqual(plugin.helloWorld, plugin)
})

test('from @-prefixed named kebab-case to camelCase', (t) => {
Expand All @@ -88,8 +81,7 @@ test('from @-prefixed named kebab-case to camelCase', (t) => {
name: '@hello/my-world'
})

t.equal(plugin.helloMyWorld, plugin)
t.end()
t.assert.strictEqual(plugin.helloMyWorld, plugin)
})

test('from kebab-case to camelCase multiple words', (t) => {
Expand All @@ -99,8 +91,7 @@ test('from kebab-case to camelCase multiple words', (t) => {
name: 'hello-long-world'
})

t.equal(plugin.helloLongWorld, plugin)
t.end()
t.assert.strictEqual(plugin.helloLongWorld, plugin)
})

test('from kebab-case to camelCase multiple words does not override', (t) => {
Expand All @@ -115,6 +106,5 @@ test('from kebab-case to camelCase multiple words does not override', (t) => {
name: 'hello-long-world'
})

t.equal(plugin.helloLongWorld, foobar)
t.end()
t.assert.strictEqual(plugin.helloLongWorld, foobar)
})
22 changes: 8 additions & 14 deletions test/checkVersion.test.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,52 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const fp = require('../plugin')

test('checkVersion having require.main.filename', (t) => {
const info = console.info
t.ok(require.main.filename)
t.teardown(() => {
t.assert.ok(require.main.filename)
t.after(() => {
console.info = info
})

console.info = function (msg) {
t.fail('logged: ' + msg)
t.assert.fail('logged: ' + msg)
}

fp((fastify, opts, next) => {
next()
}, {
fastify: '^5.0.0'
})

t.end()
})

test('checkVersion having no require.main.filename but process.argv[1]', (t) => {
const filename = require.main.filename
const info = console.info
t.teardown(() => {
t.after(() => {
require.main.filename = filename
console.info = info
})

require.main.filename = null

console.info = function (msg) {
t.fail('logged: ' + msg)
t.assert.fail('logged: ' + msg)
}

fp((fastify, opts, next) => {
next()
}, {
fastify: '^5.0.0'
})

t.end()
})

test('checkVersion having no require.main.filename and no process.argv[1]', (t) => {
const filename = require.main.filename
const argv = process.argv
const info = console.info
t.teardown(() => {
t.after(() => {
require.main.filename = filename
process.argv = argv
console.info = info
Expand All @@ -60,14 +56,12 @@ test('checkVersion having no require.main.filename and no process.argv[1]', (t)
process.argv[1] = null

console.info = function (msg) {
t.fail('logged: ' + msg)
t.assert.fail('logged: ' + msg)
}

fp((fastify, opts, next) => {
next()
}, {
fastify: '^5.0.0'
})

t.end()
})
10 changes: 4 additions & 6 deletions test/composite.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use strict'

const t = require('tap')
const test = t.test
const { test } = require('node:test')
const fp = require('../plugin')

test('anonymous function should be named composite.test0', t => {
test('anonymous function should be named composite.test0', (t) => {
t.plan(2)

const fn = fp((fastify, opts, next) => {
next()
})

t.equal(fn[Symbol.for('plugin-meta')].name, 'composite.test-auto-0')
t.equal(fn[Symbol.for('fastify.display-name')], 'composite.test-auto-0')
t.assert.strictEqual(fn[Symbol.for('plugin-meta')].name, 'composite.test-auto-0')
t.assert.strictEqual(fn[Symbol.for('fastify.display-name')], 'composite.test-auto-0')
})
8 changes: 3 additions & 5 deletions test/esm/esm.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import t from 'tap'

import { test } from 'node:test'
import fp from '../../plugin.js'

t.test('esm base support', async t => {
test('esm base support', (t) => {
fp((fastify, opts, next) => {
next()
}, {
fastify: '^5.0.0'
})

t.end()
t.assert.ok(true, 'fp function called without throwing an error')
})
13 changes: 7 additions & 6 deletions test/extractPluginName.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const t = require('tap')
const { test } = require('node:test')
const extractPluginName = require('../lib/getPluginName').extractPluginName

const winStack = `Error: anonymous function
Expand Down Expand Up @@ -41,8 +41,9 @@ at TAP.test (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:

const anonymousStack = 'Unable to parse this'

t.plan(3)

t.equal(extractPluginName(winStack), 'hello.test')
t.equal(extractPluginName(nixStack), 'this.is.a.test')
t.equal(extractPluginName(anonymousStack), 'anonymous')
test('extractPluginName tests', (t) => {
t.plan(3)
t.assert.strictEqual(extractPluginName(winStack), 'hello.test')
t.assert.strictEqual(extractPluginName(nixStack), 'this.is.a.test')
t.assert.strictEqual(extractPluginName(anonymousStack), 'anonymous')
})
9 changes: 4 additions & 5 deletions test/mu1tip1e.composite.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use strict'

const t = require('tap')
const test = t.test
const { test } = require('node:test')
const fp = require('../plugin')

test('anonymous function should be named mu1tip1e.composite.test', t => {
test('anonymous function should be named mu1tip1e.composite.test', (t) => {
t.plan(2)

const fn = fp((fastify, opts, next) => {
next()
})

t.equal(fn[Symbol.for('plugin-meta')].name, 'mu1tip1e.composite.test-auto-0')
t.equal(fn[Symbol.for('fastify.display-name')], 'mu1tip1e.composite.test-auto-0')
t.assert.strictEqual(fn[Symbol.for('plugin-meta')].name, 'mu1tip1e.composite.test-auto-0')
t.assert.strictEqual(fn[Symbol.for('fastify.display-name')], 'mu1tip1e.composite.test-auto-0')
})
Loading