From e7cda53d8445aae3cddc57859700a9d18fd304f7 Mon Sep 17 00:00:00 2001
From: asomethings <16171942+asomethings@users.noreply.github.com>
Date: Thu, 12 Sep 2024 23:30:10 +0900
Subject: [PATCH] refactor: migrate from tap to node:test

---
 .taprc                   |  2 --
 package.json             |  4 ++--
 test/funkyPlugin.test.js | 36 ++++++++++++++++++------------------
 test/helpers.js          | 18 +++++++++---------
 4 files changed, 29 insertions(+), 31 deletions(-)
 delete mode 100644 .taprc

diff --git a/.taprc b/.taprc
deleted file mode 100644
index eb6eb3e..0000000
--- a/.taprc
+++ /dev/null
@@ -1,2 +0,0 @@
-files:
-  - test/**/*.test.js
diff --git a/package.json b/package.json
index 31745af..b7dcc89 100644
--- a/package.json
+++ b/package.json
@@ -14,7 +14,7 @@
   "types": "types/index.d.ts",
   "scripts": {
     "test": "npm run test:unit && npm run test:typescript",
-    "test:unit": "tap",
+    "test:unit": "c8 --100 node --test",
     "test:typescript": "tsd",
     "lint": "standard"
   },
@@ -24,10 +24,10 @@
   "devDependencies": {
     "@fastify/pre-commit": "^2.1.0",
     "@types/node": "^20.1.0",
+    "c8": "^10.1.2",
     "fastify": "^5.0.0-alpha.4",
     "fp-ts": "^2.11.2",
     "standard": "^17.0.0",
-    "tap": "^21.0.0",
     "tsd": "^0.31.1"
   },
   "homepage": "https://github.com/fastify/fastify-funky",
diff --git a/test/funkyPlugin.test.js b/test/funkyPlugin.test.js
index 8aa1b8f..28a12f8 100644
--- a/test/funkyPlugin.test.js
+++ b/test/funkyPlugin.test.js
@@ -2,7 +2,7 @@
 
 const fastify = require('fastify')
 const { either, task, taskEither } = require('fp-ts')
-const { test } = require('tap')
+const { test } = require('node:test')
 const {
   initAppGet,
   assertResponseTypeAndBody,
@@ -27,7 +27,7 @@ test('Promise: Correctly handles top-level promise', async (t) => {
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -43,7 +43,7 @@ test('either: correctly parses right part of Either (sync)', async (t) => {
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -60,7 +60,7 @@ test('either: correctly parses right part of Either (async)', async (t) => {
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -77,7 +77,7 @@ test('either: correctly parses left part of Either when resolved (async)', async
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -93,7 +93,7 @@ test('either: correctly parses left part of Either when resolved (sync)', async
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -113,7 +113,7 @@ test('either: supports reply callback with the right part of Either', async (t)
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -129,7 +129,7 @@ test('task: correctly parses Task result (sync)', async (t) => {
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -145,7 +145,7 @@ test('task: correctly parses Task result (promise)', async (t) => {
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -165,7 +165,7 @@ test('task: correctly handles Task throwing', async (t) => {
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -185,7 +185,7 @@ test('task: correctly parses result of a plain parameterless function', async (t
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -205,7 +205,7 @@ test('task: correctly parses result of a plain parameterless function that retur
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -225,7 +225,7 @@ test('task: ignores parameterless function with parameters', async (t) => {
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -241,7 +241,7 @@ test('task: handles empty body correctly', async (t) => {
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -256,7 +256,7 @@ test('text content: correctly handles text response', async (t) => {
 
   const app = fastify().register(fastifyFunky)
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -290,7 +290,7 @@ test('taskEither: correctly parses TaskEither result (Either right)', async (t)
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -306,7 +306,7 @@ test('taskEither: correctly parses TaskEither result (Task)', async (t) => {
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
@@ -322,7 +322,7 @@ test('taskEither: correctly parses TaskEither result (Either left)', async (t) =
 
   const app = await initAppGet(t, route).ready()
 
-  t.teardown(() => {
+  t.after(() => {
     app.close()
   })
 
diff --git a/test/helpers.js b/test/helpers.js
index c5b8052..c0b0836 100644
--- a/test/helpers.js
+++ b/test/helpers.js
@@ -11,7 +11,7 @@ function initAppGet (t, endpoint) {
 
   app.setErrorHandler((error, request, reply) => {
     app.log.error(error)
-    t.strictSame(error.message, 'Invalid state')
+    t.assert.deepStrictEqual(error.message, 'Invalid state')
     reply.status(500).send({ ok: false })
   })
 
@@ -20,8 +20,8 @@ function initAppGet (t, endpoint) {
 
 async function assertResponseTypeAndBody (t, app, endpoint, expectedType, expectedBody) {
   const response = await app.inject().get(endpoint).end()
-  t.strictSame(response.headers['content-type'], expectedType)
-  t.strictSame(response.body, expectedBody)
+  t.assert.deepStrictEqual(response.headers['content-type'], expectedType)
+  t.assert.deepStrictEqual(response.body, expectedBody)
 }
 
 function assertCorrectResponse (t, app) {
@@ -30,8 +30,8 @@ function assertCorrectResponse (t, app) {
     .get('/')
     .end()
     .then((response) => {
-      t.strictSame(response.statusCode, 200)
-      t.strictSame(response.json().user, { id: 1 })
+      t.assert.deepStrictEqual(response.statusCode, 200)
+      t.assert.deepStrictEqual(response.json().user, { id: 1 })
     })
 }
 
@@ -41,8 +41,8 @@ function assertCorrectResponseBody (t, app, expectedBody, expectedCode = 200) {
     .get('/')
     .end()
     .then((response) => {
-      t.strictSame(response.statusCode, expectedCode)
-      t.strictSame(response.body, expectedBody)
+      t.assert.deepStrictEqual(response.statusCode, expectedCode)
+      t.assert.deepStrictEqual(response.body, expectedBody)
     })
 }
 
@@ -52,8 +52,8 @@ function assertErrorResponse (t, app) {
     .get('/')
     .end()
     .then((response) => {
-      t.strictSame(response.statusCode, 500)
-      t.strictSame(response.json(), {
+      t.assert.deepStrictEqual(response.statusCode, 500)
+      t.assert.deepStrictEqual(response.json(), {
         ok: false
       })
     })