Skip to content

Commit c89f327

Browse files
Copilotmetcoder95
andauthored
test: Replace tap tests with node:test (#22)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: metcoder95 <[email protected]>
1 parent 6683ad9 commit c89f327

File tree

4 files changed

+28
-42
lines changed

4 files changed

+28
-42
lines changed

.taprc

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

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
"scripts": {
1313
"lint": "standardx \"**/*.{mjs,js,cjs}\" | snazzy",
1414
"lint:fix": "standardx --fix",
15-
"test": "tap -J test/*.test.{js,mjs}",
16-
"test:coverage": "tap -J test/*.test.{js,mjs} --cov --coverage-report=html --no-browser --no-check-coverage",
17-
"test:verbose": "npm run unit -- -Rspec",
18-
"test:ci": "npm run test:coverage && npm run test:typescript",
15+
"test": "node --test test/*.test.js test/*.test.mjs",
16+
"test:ci": "npm run test && npm run test:typescript",
1917
"test:typescript": "tsd"
2018
},
2119
"repository": {
@@ -38,7 +36,6 @@
3836
"fastify": "^5.0.0",
3937
"snazzy": "^9.0.0",
4038
"standardx": "^7.0.0",
41-
"tap": "^15.1.5",
4239
"tsd": "^0.33.0"
4340
},
4441
"dependencies": {

test/plugin-cjs.test.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
'use strict';
22

33
const { resolve } = require('path');
4-
const { test } = require('tap');
4+
const { test } = require('node:test');
5+
const assert = require('node:assert');
56
const Fastify = require('fastify');
67
const fastifyPiscina = require('../plugin');
78

89
test('It should add decorators - CommonJS', async (t) => {
9-
t.plan(3);
10-
1110
const fastify = Fastify();
1211
await fastify.register(fastifyPiscina, {
1312
filename: resolve(__dirname, 'worker.js')
1413
});
1514

16-
t.teardown(fastify.close.bind(fastify));
15+
t.after(() => fastify.close());
1716

18-
t.ok(fastify.piscina);
19-
t.ok(fastify.piscina.run);
20-
t.ok(fastify.runTask);
17+
assert.ok(fastify.piscina);
18+
assert.ok(fastify.piscina.run);
19+
assert.ok(fastify.runTask);
2120

2221
fastify.get('/', async (request, reply) => {
2322
reply.send({ result: await fastify.runTask({ a: 1, b: 2 }) });
@@ -26,28 +25,25 @@ test('It should add decorators - CommonJS', async (t) => {
2625
await fastify.ready();
2726
});
2827

29-
test('It should throw when trying to register the plugin more than once - CommonJS', (t) => {
30-
t.plan(1);
31-
28+
test('It should throw when trying to register the plugin more than once - CommonJS', async () => {
3229
const fastify = Fastify();
3330
fastify
3431
.register(fastifyPiscina)
3532
.register(fastifyPiscina);
3633

37-
fastify.ready((err) => {
38-
t.equal(err.message, 'fastify-piscina has already been registered');
39-
});
34+
await assert.rejects(
35+
fastify.ready(),
36+
{ message: 'fastify-piscina has already been registered' }
37+
);
4038
});
4139

4240
test('It should be able to use `fastify.runTask()` - CommonJS', async (t) => {
43-
t.plan(1);
44-
4541
const fastify = Fastify();
4642
await fastify.register(fastifyPiscina, {
4743
filename: resolve(__dirname, 'worker.js')
4844
});
4945

50-
t.teardown(fastify.close.bind(fastify));
46+
t.after(() => fastify.close());
5147

5248
fastify.get('/', async (request, reply) => {
5349
reply.send({ result: await fastify.runTask({ a: 1, b: 2 }) });
@@ -60,5 +56,5 @@ test('It should be able to use `fastify.runTask()` - CommonJS', async (t) => {
6056
path: '/'
6157
});
6258
const payload = JSON.parse(response.payload);
63-
t.equal(payload.result, 3);
59+
assert.strictEqual(payload.result, 3);
6460
});

test/plugin-esm.test.mjs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
'use strict';
22

3-
import { test } from 'tap';
3+
import { test } from 'node:test';
4+
import assert from 'node:assert';
45
import Fastify from 'fastify';
56
import fastifyPiscina from '../plugin.js';
67

78
test('It should add decorators - ESM', async (t) => {
8-
t.plan(3);
9-
109
const fastify = Fastify();
1110
await fastify.register(fastifyPiscina, {
1211
filename: new URL('./worker.mjs', import.meta.url).href
1312
});
1413

15-
t.teardown(fastify.close.bind(fastify));
14+
t.after(() => fastify.close());
1615

17-
t.ok(fastify.piscina);
18-
t.ok(fastify.piscina.run);
19-
t.ok(fastify.runTask);
16+
assert.ok(fastify.piscina);
17+
assert.ok(fastify.piscina.run);
18+
assert.ok(fastify.runTask);
2019

2120
fastify.get('/', async (request, reply) => {
2221
reply.send({ result: await fastify.runTask({ a: 1, b: 2 }) });
@@ -25,26 +24,23 @@ test('It should add decorators - ESM', async (t) => {
2524
await fastify.ready();
2625
});
2726

28-
test('It should throw when trying to register the plugin more than once - ESM', (t) => {
29-
t.plan(1);
30-
27+
test('It should throw when trying to register the plugin more than once - ESM', async () => {
3128
const fastify = Fastify();
3229
fastify.register(fastifyPiscina).register(fastifyPiscina);
3330

34-
fastify.ready((err) => {
35-
t.equal(err.message, 'fastify-piscina has already been registered');
36-
});
31+
await assert.rejects(
32+
fastify.ready(),
33+
{ message: 'fastify-piscina has already been registered' }
34+
);
3735
});
3836

3937
test('It should be able to use `fastify.runTask()` - ESM', async (t) => {
40-
t.plan(1);
41-
4238
const fastify = Fastify();
4339
await fastify.register(fastifyPiscina, {
4440
filename: new URL('./worker.mjs', import.meta.url).href
4541
});
4642

47-
t.teardown(fastify.close.bind(fastify));
43+
t.after(() => fastify.close());
4844

4945
fastify.get('/', async (request, reply) => {
5046
reply.send({ result: await fastify.runTask({ a: 1, b: 2 }) });
@@ -57,5 +53,5 @@ test('It should be able to use `fastify.runTask()` - ESM', async (t) => {
5753
path: '/'
5854
});
5955
const payload = JSON.parse(response.payload);
60-
t.equal(payload.result, 1);
56+
assert.strictEqual(payload.result, 1);
6157
});

0 commit comments

Comments
 (0)