From a5a9a0f016714a4df3100ae4fb055ed98c7c6624 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Wed, 1 Jan 2025 23:19:00 +0100 Subject: [PATCH 01/93] chore: remove tap --- .taprc | 2 - package.json | 3 +- test/content-type.test.js | 50 +- test/dir-list.test.js | 284 +++--- test/static.test.js | 1779 ++++++++++++++++++------------------- 5 files changed, 1047 insertions(+), 1071 deletions(-) delete mode 100644 .taprc diff --git a/.taprc b/.taprc deleted file mode 100644 index eb6eb3e8..00000000 --- a/.taprc +++ /dev/null @@ -1,2 +0,0 @@ -files: - - test/**/*.test.js diff --git a/package.json b/package.json index 9024492b..8b54cfcd 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", - "test:unit": "tap", + "test:unit": "node --test", "example": "node example/server.js" }, "repository": { @@ -76,7 +76,6 @@ "pino": "^9.1.0", "proxyquire": "^2.1.3", "simple-get": "^4.0.1", - "tap": "^18.7.1", "tsd": "^0.31.0" }, "tsd": { diff --git a/test/content-type.test.js b/test/content-type.test.js index 4e012602..05d5c0a0 100644 --- a/test/content-type.test.js +++ b/test/content-type.test.js @@ -3,7 +3,7 @@ /* eslint n/no-deprecated-api: "off" */ const path = require('node:path') -const { test } = require('tap') +const { test } = require('node:test') const simple = require('simple-get') const Fastify = require('fastify') @@ -19,10 +19,10 @@ test('register /content-type', t => { const fastify = Fastify() fastify.register(fastifyStatic, pluginOptions) - t.teardown(fastify.close.bind(fastify)) + t.after(() => fastify.close()) fastify.listen({ port: 0 }, (err) => { - t.error(err) + t.assert.ok(err instanceof Error) fastify.server.unref() @@ -32,8 +32,8 @@ test('register /content-type', t => { method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.html' }, (err, response) => { - t.error(err) - t.equal(response.headers['content-type'], 'text/html; charset=utf-8') + t.assert.ok(err instanceof Error) + t.assert.equal(response.headers['content-type'], 'text/html; charset=utf-8') }) }) @@ -43,8 +43,8 @@ test('register /content-type', t => { method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.css' }, (err, response) => { - t.error(err) - t.equal(response.headers['content-type'], 'text/css; charset=utf-8') + t.assert.ok(err instanceof Error) + t.assert.equal(response.headers['content-type'], 'text/css; charset=utf-8') }) }) @@ -54,8 +54,8 @@ test('register /content-type', t => { method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg' }, (err, response) => { - t.error(err) - t.equal(response.headers['content-type'], 'image/jpeg') + t.assert.ok(err instanceof Error) + t.assert.equal(response.headers['content-type'], 'image/jpeg') }) }) @@ -65,8 +65,8 @@ test('register /content-type', t => { method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/content-type/test.txt' }, (err, response) => { - t.error(err) - t.equal(response.headers['content-type'], 'text/plain; charset=utf-8') + t.assert.ok(err instanceof Error) + t.assert.equal(response.headers['content-type'], 'text/plain; charset=utf-8') }) }) @@ -76,8 +76,8 @@ test('register /content-type', t => { method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/content-type/binary' }, (err, response) => { - t.error(err) - t.equal(response.headers['content-type'], 'application/octet-stream') + t.assert.ok(err instanceof Error) + t.assert.equal(response.headers['content-type'], 'application/octet-stream') }) }) }) @@ -94,10 +94,10 @@ test('register /content-type preCompressed', t => { const fastify = Fastify() fastify.register(fastifyStatic, pluginOptions) - t.teardown(fastify.close.bind(fastify)) + t.after(() => fastify.close()) fastify.listen({ port: 0 }, (err) => { - t.error(err) + t.assert.ok(err instanceof Error) fastify.server.unref() @@ -110,8 +110,8 @@ test('register /content-type preCompressed', t => { 'accept-encoding': 'gzip, deflate, br' } }, (err, response) => { - t.error(err) - t.equal(response.headers['content-type'], 'text/html; charset=utf-8') + t.assert.ok(err instanceof Error) + t.assert.equal(response.headers['content-type'], 'text/html; charset=utf-8') }) }) @@ -124,8 +124,8 @@ test('register /content-type preCompressed', t => { 'accept-encoding': 'gzip, deflate, br' } }, (err, response) => { - t.error(err) - t.equal(response.headers['content-type'], 'text/css; charset=utf-8') + t.assert.ok(err instanceof Error) + t.assert.equal(response.headers['content-type'], 'text/css; charset=utf-8') }) }) @@ -138,8 +138,8 @@ test('register /content-type preCompressed', t => { 'accept-encoding': 'gzip, deflate, br' } }, (err, response) => { - t.error(err) - t.equal(response.headers['content-type'], 'image/jpeg') + t.assert.ok(err instanceof Error) + t.assert.equal(response.headers['content-type'], 'image/jpeg') }) }) @@ -152,8 +152,8 @@ test('register /content-type preCompressed', t => { 'accept-encoding': 'gzip, deflate, br' } }, (err, response) => { - t.error(err) - t.equal(response.headers['content-type'], 'text/plain; charset=utf-8') + t.assert.ok(err instanceof Error) + t.assert.equal(response.headers['content-type'], 'text/plain; charset=utf-8') }) }) @@ -166,8 +166,8 @@ test('register /content-type preCompressed', t => { 'accept-encoding': 'gzip, deflate, br' } }, (err, response) => { - t.error(err) - t.equal(response.headers['content-type'], 'application/octet-stream') + t.assert.ok(err instanceof Error) + t.assert.equal(response.headers['content-type'], 'application/octet-stream') }) }) }) diff --git a/test/dir-list.test.js b/test/dir-list.test.js index 74aacea3..fc83d972 100644 --- a/test/dir-list.test.js +++ b/test/dir-list.test.js @@ -4,7 +4,7 @@ const fs = require('node:fs') const path = require('node:path') -const t = require('tap') +const { test } = require('node:test') const simple = require('simple-get') const Fastify = require('fastify') @@ -18,9 +18,9 @@ const helper = { arrangeModule: function (t, options, mock, f) { const fastify = Fastify() fastify.register(mock, options) - t.teardown(fastify.close.bind(fastify)) + t.after(() => fastify.close()) fastify.listen({ port: 0 }, err => { - t.error(err) + t.assert.ok(err instanceof Error) fastify.server.unref() f('http://localhost:' + fastify.server.address().port) }) @@ -32,47 +32,47 @@ try { fs.mkdirSync(path.join(__dirname, 'static/shallow/empty')) } catch (error) {} -t.test('throws when `root` is an array', t => { +test('throws when `root` is an array', t => { t.plan(2) const err = dirList.validateOptions({ root: ['hello', 'world'], list: true }) - t.type(err, TypeError) - t.equal(err.message, 'multi-root with list option is not supported') + t.assert.ok(err instanceof TypeError) + t.assert.equal(err.message, 'multi-root with list option is not supported') }) -t.test('throws when `list.format` option is invalid', t => { +test('throws when `list.format` option is invalid', t => { t.plan(2) const err = dirList.validateOptions({ list: { format: 'hello' } }) - t.type(err, TypeError) - t.equal(err.message, 'The `list.format` option must be json or html') + t.assert.ok(err instanceof TypeError) + t.assert.equal(err.message, 'The `list.format` option must be json or html') }) -t.test('throws when `list.names option` is not an array', t => { +test('throws when `list.names option` is not an array', t => { t.plan(2) const err = dirList.validateOptions({ list: { names: 'hello' } }) - t.type(err, TypeError) - t.equal(err.message, 'The `list.names` option must be an array') + t.assert.ok(err instanceof TypeError) + t.assert.equal(err.message, 'The `list.names` option must be an array') }) -t.test('throws when `list.jsonFormat` option is invalid', t => { +test('throws when `list.jsonFormat` option is invalid', t => { t.plan(2) const err = dirList.validateOptions({ list: { jsonFormat: 'hello' } }) - t.type(err, TypeError) - t.equal(err.message, 'The `list.jsonFormat` option must be name or extended') + t.assert.ok(err instanceof TypeError) + t.assert.equal(err.message, 'The `list.jsonFormat` option must be name or extended') }) -t.test('throws when `list.format` is html and `list render` is not a function', t => { +test('throws when `list.format` is html and `list render` is not a function', t => { t.plan(2) const err = dirList.validateOptions({ list: { format: 'html', render: 'hello' } }) - t.type(err, TypeError) - t.equal(err.message, 'The `list.render` option must be a function and is required with html format') + t.assert.ok(err instanceof TypeError) + t.assert.equal(err.message, 'The `list.render` option must be a function and is required with html format') }) -t.test('dir list wrong options', t => { +test('dir list wrong options', t => { t.plan(3) const cases = [ @@ -111,13 +111,13 @@ t.test('dir list wrong options', t => { const fastify = Fastify() fastify.register(fastifyStatic, case_.options) fastify.listen({ port: 0 }, err => { - t.equal(err.message, case_.error.message) + t.assert.equal(err.message, case_.error.message) fastify.server.unref() }) } }) -t.test('dir list default options', t => { +test('dir list default options', t => { t.plan(2) const options = { @@ -129,21 +129,21 @@ t.test('dir list default options', t => { const content = { dirs: ['empty'], files: ['sample.jpg'] } helper.arrange(t, options, (url) => { - t.test(route, t => { + test(route, t => { t.plan(3) simple.concat({ method: 'GET', url: url + route }, (err, response, body) => { - t.error(err) - t.equal(response.statusCode, 200) - t.equal(body.toString(), JSON.stringify(content)) + t.assert.ok(err instanceof Error) + t.assert.equal(response.statusCode, 200) + t.assert.equal(body.toString(), JSON.stringify(content)) }) }) }) }) -t.test('dir list, custom options', t => { +test('dir list, custom options', t => { t.plan(2) const options = { @@ -157,21 +157,21 @@ t.test('dir list, custom options', t => { const content = { dirs: ['deep', 'shallow'], files: ['.example', '100%.txt', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] } helper.arrange(t, options, (url) => { - t.test(route, t => { + test(route, t => { t.plan(3) simple.concat({ method: 'GET', url: url + route }, (err, response, body) => { - t.error(err) - t.equal(response.statusCode, 200) - t.equal(body.toString(), JSON.stringify(content)) + t.assert.ok(err instanceof Error) + t.assert.equal(response.statusCode, 200) + t.assert.equal(body.toString(), JSON.stringify(content)) }) }) }) }) -t.test('dir list, custom options with empty array index', t => { +test('dir list, custom options with empty array index', t => { t.plan(2) const options = { @@ -185,21 +185,21 @@ t.test('dir list, custom options with empty array index', t => { const content = { dirs: ['deep', 'shallow'], files: ['.example', '100%.txt', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] } helper.arrange(t, options, (url) => { - t.test(route, t => { + test(route, t => { t.plan(3) simple.concat({ method: 'GET', url: url + route }, (err, response, body) => { - t.error(err) - t.equal(response.statusCode, 200) - t.equal(body.toString(), JSON.stringify(content)) + t.assert.ok(err instanceof Error) + t.assert.equal(response.statusCode, 200) + t.assert.equal(body.toString(), JSON.stringify(content)) }) }) }) }) -t.test('dir list html format', t => { +test('dir list html format', t => { t.plan(3) const options = { @@ -229,15 +229,15 @@ t.test('dir list html format', t => { helper.arrange(t, options, (url) => { for (const route of routes) { - t.test(route, t => { + test(route, t => { t.plan(3) simple.concat({ method: 'GET', url: url + route }, (err, response, body) => { - t.error(err) - t.equal(response.statusCode, 200) - t.equal(body.toString(), ` + t.assert.ok(err instanceof Error) + t.assert.equal(response.statusCode, 200) + t.assert.equal(body.toString(), `