Skip to content

Commit 753a567

Browse files
authored
chore: migrate from tap to node:test and c8 using borp (#182)
1 parent aa3f9f1 commit 753a567

File tree

8 files changed

+726
-755
lines changed

8 files changed

+726
-755
lines changed

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
"load-data": "docker exec -it fastify-postgres psql -c 'CREATE TABLE users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);' -U postgres -d postgres",
1313
"postgres": "docker run -p 5432:5432 --name fastify-postgres -e POSTGRES_PASSWORD=postgres -d postgres:11-alpine",
1414
"test": "npm run test:unit && npm run test:typescript",
15-
"test:unit": "tap test/*.test.js",
16-
"test:report": "standard && tap --coverage-report=html test/*.test.js",
17-
"test:typescript": "tsd",
18-
"test:verbose": "standard && tap test/*.test.js -Rspec"
15+
"test:unit": "c8 --100 node --test",
16+
"test:report": "standard && c8 --reporter html node --test",
17+
"test:typescript": "tsd"
1918
},
2019
"repository": {
2120
"type": "git",
@@ -41,11 +40,11 @@
4140
"devDependencies": {
4241
"@tsconfig/node10": "^1.0.9",
4342
"@types/pg": "^8.11.4",
43+
"c8": "^10.1.2",
4444
"fastify": "^5.0.0",
4545
"pg": "^8.11.3",
4646
"pg-native": "^3.0.1",
4747
"standard": "^17.1.0",
48-
"tap": "^18.7.1",
4948
"tsd": "^0.31.1",
5049
"typescript": "~5.6.3"
5150
},

test/add-handler.test.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44
const addHandler = require('../lib/add-handler')
55

6-
test('The addHandler lib should return the right handlers structure', t => {
7-
t.test('When the existingHandler argument is undefined', t => {
6+
test('The addHandler lib should return the right handlers structure', async t => {
7+
await t.test('When the existingHandler argument is undefined', t => {
88
t.plan(1)
99

1010
const handlers = addHandler(
1111
undefined,
1212
'test'
1313
)
1414

15-
t.same(handlers, ['test'])
15+
t.assert.deepStrictEqual(handlers, ['test'])
1616
})
1717

18-
t.test('When the existingHandler argument is an array', t => {
18+
await t.test('When the existingHandler argument is an array', t => {
1919
t.plan(1)
2020

2121
const handlers = addHandler(
2222
['test'],
2323
'again'
2424
)
2525

26-
t.same(handlers, ['test', 'again'])
26+
t.assert.deepStrictEqual(handlers, ['test', 'again'])
2727
})
2828

29-
t.test('When the existingHandler argument is a function', t => {
29+
await t.test('When the existingHandler argument is a function', t => {
3030
t.plan(2)
3131

3232
const stub = () => 'test'
@@ -36,9 +36,7 @@ test('The addHandler lib should return the right handlers structure', t => {
3636
'again'
3737
)
3838

39-
t.same(handlers[0](), 'test')
40-
t.same(handlers[1], 'again')
39+
t.assert.deepStrictEqual(handlers[0](), 'test')
40+
t.assert.deepStrictEqual(handlers[1], 'again')
4141
})
42-
43-
t.end()
4442
})

test/initialization-log.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const { test } = require('node:test')
2+
const Fastify = require('fastify')
3+
const pg = require('pg')
4+
const fastifyPostgres = require('../index')
5+
const { connectionString } = require('./helpers')
6+
7+
test('Initalization log tests', async (t) => {
8+
const realConsole = global.console
9+
const ctx = {}
10+
11+
test.beforeEach(() => {
12+
ctx.fastify = require('fastify')()
13+
ctx.pg = {
14+
...require('pg'),
15+
native: null
16+
}
17+
ctx.native = pg.native
18+
})
19+
20+
test.afterEach(() => {
21+
// Really would just remove the module from the
22+
// cache.
23+
ctx.pg.native = ctx.native
24+
global.console = realConsole
25+
})
26+
27+
await t.test('Should print warning when native module not installed', async (t) => {
28+
t.plan(2)
29+
30+
global.console.warn = (msg) => t.assert.strictEqual(msg, "pg-native not installed, can't use native option - fallback to pg module")
31+
32+
const fastify = Fastify()
33+
t.after(() => {
34+
fastify.close()
35+
})
36+
37+
await ctx.fastify.register(fastifyPostgres, {
38+
connectionString,
39+
native: true,
40+
pg: ctx.pg
41+
})
42+
43+
const ready = await ctx.fastify.ready()
44+
t.assert.ok(ready)
45+
})
46+
})

0 commit comments

Comments
 (0)