From ae80cd24c9ec12803279f0db8184d45ca00a9ccb Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sat, 7 Dec 2024 09:44:40 +0100 Subject: [PATCH 1/6] BREAKING CHANGE: node test runner --- .github/workflows/ci.yml | 2 +- package.json | 5 +- test/application-hooks.test.js | 4 +- test/decorator.test.js | 50 +++++----- test/expose-routes.test.js | 173 ++++++++++++++++++--------------- test/index.test.js | 74 +++++++------- test/routes.test.js | 50 +++++----- test/source-code.test.js | 46 ++++----- 8 files changed, 208 insertions(+), 196 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b567af..3eedecf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,6 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5 with: lint: true \ No newline at end of file diff --git a/package.json b/package.json index 5680f20..c8986b9 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "lint": "standard && npm run lint:typescript", "lint:fix": "standard --fix && npm run lint:typescript -- --fix", "lint:typescript": "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin *.ts test/**/*.ts", - "test": "tap test/**/*.test.js && npm run test:typescript", + "test": "node --test && npm run test:typescript", "test:typescript": "tsd" }, "repository": { @@ -28,7 +28,7 @@ "url": "https://github.com/Eomm/fastify-overview/issues" }, "engines": { - "node": ">=14" + "node": ">=20" }, "homepage": "https://github.com/Eomm/fastify-overview#readme", "devDependencies": { @@ -38,7 +38,6 @@ "@typescript-eslint/parser": "^6.0.0", "fastify": "^4.23.0", "standard": "^17.0.0", - "tap": "^16.0.1", "tsd": "^0.31.0" }, "dependencies": { diff --git a/test/application-hooks.test.js b/test/application-hooks.test.js index c75f991..ac5ee6b 100644 --- a/test/application-hooks.test.js +++ b/test/application-hooks.test.js @@ -1,6 +1,6 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') const fastify = require('fastify') const plugin = require('../index') @@ -29,5 +29,5 @@ test('should track all the application hooks', { await app.ready() const structure = app.overview({ hideEmpty: true }) - t.same(structure.hooks, require('./fixture/app-hooks.json').hooks) + t.assert.deepStrictEqual(structure.hooks, require('./fixture/app-hooks.json').hooks) }) diff --git a/test/decorator.test.js b/test/decorator.test.js index dd658aa..2aa5ce8 100644 --- a/test/decorator.test.js +++ b/test/decorator.test.js @@ -1,6 +1,6 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') const fastify = require('fastify') const plugin = require('../index') @@ -40,28 +40,28 @@ test('decorator', async t => { await app.ready() const root = app.overview() - t.equal(root.children.length, 2) - t.equal(root.children[0].name, 'register1') - t.equal(root.children[1].name, 'sibling') - t.same(root.decorators.decorate, [{ name: 'root-func', type: 'function' }, { name: 'root-symbol', type: 'symbol' }]) - t.same(root.decorators.decorateRequest, [{ name: 'root-req', type: 'function' }, { name: 'root-req-two', type: 'function' }, { name: 'root-req-boolean', type: 'boolean' }]) - t.same(root.decorators.decorateReply, [{ name: 'root-reply', type: 'function' }, { name: 'root-reply-array', type: 'array' }]) + t.assert.deepEqual(root.children.length, 2) + t.assert.deepEqual(root.children[0].name, 'register1') + t.assert.deepEqual(root.children[1].name, 'sibling') + t.assert.deepStrictEqual(root.decorators.decorate, [{ name: 'root-func', type: 'function' }, { name: 'root-symbol', type: 'symbol' }]) + t.assert.deepStrictEqual(root.decorators.decorateRequest, [{ name: 'root-req', type: 'function' }, { name: 'root-req-two', type: 'function' }, { name: 'root-req-boolean', type: 'boolean' }]) + t.assert.deepStrictEqual(root.decorators.decorateReply, [{ name: 'root-reply', type: 'function' }, { name: 'root-reply-array', type: 'array' }]) const reg1 = root.children[0] - t.same(reg1.decorators.decorate, [{ name: 'child-1-bigint', type: 'bigint' }, { name: 'child-1-undefined', type: 'undefined' }]) - t.same(reg1.decorators.decorateRequest, [{ name: 'child-1', type: 'number' }]) - t.same(reg1.decorators.decorateReply, []) - t.equal(reg1.children.length, 2) + t.assert.deepStrictEqual(reg1.decorators.decorate, [{ name: 'child-1-bigint', type: 'bigint' }, { name: 'child-1-undefined', type: 'undefined' }]) + t.assert.deepStrictEqual(reg1.decorators.decorateRequest, [{ name: 'child-1', type: 'number' }]) + t.assert.deepStrictEqual(reg1.decorators.decorateReply, []) + t.assert.deepEqual(reg1.children.length, 2) const reg2 = reg1.children[0] - t.same(reg2.decorators.decorate, []) - t.same(reg2.decorators.decorateRequest, []) - t.same(reg2.decorators.decorateReply, [{ name: 'sub', type: 'number' }]) + t.assert.deepStrictEqual(reg2.decorators.decorate, []) + t.assert.deepStrictEqual(reg2.decorators.decorateRequest, []) + t.assert.deepStrictEqual(reg2.decorators.decorateReply, [{ name: 'sub', type: 'number' }]) const reg3 = reg1.children[1] - t.same(reg3.decorators.decorate, [{ name: 'sub-instance', type: 'number' }]) - t.same(reg3.decorators.decorateRequest, [{ name: 'sub-object', type: 'object' }]) - t.same(reg3.decorators.decorateReply, [{ name: 'sub', type: 'number' }]) + t.assert.deepStrictEqual(reg3.decorators.decorate, [{ name: 'sub-instance', type: 'number' }]) + t.assert.deepStrictEqual(reg3.decorators.decorateRequest, [{ name: 'sub-object', type: 'object' }]) + t.assert.deepStrictEqual(reg3.decorators.decorateReply, [{ name: 'sub', type: 'number' }]) }) test('onDecorateDefinition', async t => { @@ -105,14 +105,14 @@ test('onDecorateDefinition', async t => { const root = app.overview() - t.equal(root.children.length, 1) - t.same(root.decorators.decorate, [{ name: 'emptyObj', type: 'object', recursive: [] }, { name: 'obj1', type: 'object', recursive: [{ name: 'run', type: 'function' }] }]) - t.same(root.decorators.decorateReply, [{ name: 'obj2', type: 'object', recursive: [{ name: 'test', type: 'string' }] }]) - t.same(root.decorators.decorateRequest, [{ name: 'emptyObj', type: 'object', recursive: [] }]) + t.assert.deepEqual(root.children.length, 1) + t.assert.deepStrictEqual(root.decorators.decorate, [{ name: 'emptyObj', type: 'object', recursive: [] }, { name: 'obj1', type: 'object', recursive: [{ name: 'run', type: 'function' }] }]) + t.assert.deepStrictEqual(root.decorators.decorateReply, [{ name: 'obj2', type: 'object', recursive: [{ name: 'test', type: 'string' }] }]) + t.assert.deepStrictEqual(root.decorators.decorateRequest, [{ name: 'emptyObj', type: 'object', recursive: [] }]) - t.equal(root.children[0].name, 'child1') + t.assert.deepEqual(root.children[0].name, 'child1') const child1 = root.children[0] - t.same(child1.decorators.decorate, [{ name: 'encapsulatedObj', type: 'object', recursive: [{ name: 'a', type: 'function' }, { name: 'b', type: 'string' }, { name: 'c', type: 'boolean' }, { name: 'd', type: 'number' }] }]) - t.equal(child1.decorators.decorateRequest.length, 0) - t.equal(child1.decorators.decorateReply.length, 0) + t.assert.deepStrictEqual(child1.decorators.decorate, [{ name: 'encapsulatedObj', type: 'object', recursive: [{ name: 'a', type: 'function' }, { name: 'b', type: 'string' }, { name: 'c', type: 'boolean' }, { name: 'd', type: 'number' }] }]) + t.assert.deepEqual(child1.decorators.decorateRequest.length, 0) + t.assert.deepEqual(child1.decorators.decorateReply.length, 0) }) diff --git a/test/expose-routes.test.js b/test/expose-routes.test.js index a100098..4f3fd73 100644 --- a/test/expose-routes.test.js +++ b/test/expose-routes.test.js @@ -1,6 +1,6 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') const fastify = require('fastify') const plugin = require('../index') @@ -9,52 +9,56 @@ test('expose the route to the the json', async t => { await app.register(plugin, { exposeRoute: true }) const response = await app.inject('/json-overview') - t.hasStrict(response.json(), { - name: 'fastify -> fastify-overview', - children: [], - routes: [ - { - method: 'GET', - url: '/json-overview', - prefix: '', - hooks: { - onRequest: [], - preParsing: [], - preValidation: [], - preHandler: [], - preSerialization: [], - onError: [], - onSend: [], - onResponse: [], - onTimeout: [] - } + const responseContent = response.json() + + t.assert.deepStrictEqual(responseContent.name, 'fastify -> fastify-overview') + t.assert.deepStrictEqual(responseContent.children, []) + t.assert.deepEqual(responseContent.routes, [ + { + method: 'GET', + url: '/json-overview', + prefix: '', + hooks: { + onRequest: [], + onRequestAbort: [], + preParsing: [], + preValidation: [], + preHandler: [], + preSerialization: [], + onError: [], + onSend: [], + onResponse: [], + onTimeout: [] } - ], - decorators: { - decorate: [], - decorateRequest: [], - decorateReply: [] - }, - hooks: { - onRequest: [], - preParsing: [], - preValidation: [], - preHandler: [], - preSerialization: [], - onError: [], - onSend: [], - onResponse: [], - onTimeout: [], - onReady: [], - onClose: [], - onRoute: [], - onRegister: [] } + ]) + t.assert.deepStrictEqual(responseContent.decorators, { + decorate: [], + decorateRequest: [], + decorateReply: [] + }) + t.assert.deepEqual(responseContent.hooks, { + onClose: [], + onError: [], + onListen: [], + onReady: [], + onRegister: [], + onRequest: [], + onRequestAbort: [], + onResponse: [], + onRoute: [], + onSend: [], + onTimeout: [], + preClose: [], + preHandler: [], + preParsing: [], + preSerialization: [], + preValidation: [] }) }) test('expose the route within more options', async t => { - t.plan(2) + t.plan(6) const app = fastify() await app.register(plugin, { @@ -62,53 +66,60 @@ test('expose the route within more options', async t => { exposeRouteOptions: { url: '/foo', preHandler: function hook (request, reply, done) { - t.pass('preHandler hook called') + t.assert.ok(true, 'preHandler hook registered') done(null) } } }) const response = await app.inject('/foo') - t.hasStrict(response.json(), { - name: 'fastify -> fastify-overview', - children: [], - routes: [ - { - method: 'GET', - url: '/foo', - prefix: '', - hooks: { - onRequest: [], - preParsing: [], - preValidation: [], - preHandler: [], - preSerialization: [], - onError: [], - onSend: [], - onResponse: [], - onTimeout: [] - } + const responseContent = response.json() + + t.assert.deepStrictEqual(responseContent.name, 'fastify -> fastify-overview') + t.assert.deepStrictEqual(responseContent.children, []) + t.assert.deepEqual(responseContent.routes, [ + { + method: 'GET', + url: '/foo', + prefix: '', + hooks: { + onError: [], + onRequest: [], + onRequestAbort: [], + onResponse: [], + onSend: [], + onTimeout: [], + preHandler: [{ + name: 'hook', + hash: '1994f633554c479b3ffceeebdb7328ddf56d0234' + }], + preParsing: [], + preSerialization: [], + preValidation: [] } - ], - decorators: { - decorate: [], - decorateRequest: [], - decorateReply: [] - }, - hooks: { - onRequest: [], - preParsing: [], - preValidation: [], - preHandler: [], - preSerialization: [], - onError: [], - onSend: [], - onResponse: [], - onTimeout: [], - onReady: [], - onClose: [], - onRoute: [], - onRegister: [] } + ]) + t.assert.deepStrictEqual(responseContent.decorators, { + decorate: [], + decorateRequest: [], + decorateReply: [] + }) + t.assert.deepStrictEqual(responseContent.hooks, { + onRequest: [], + preParsing: [], + preValidation: [], + preHandler: [], + preSerialization: [], + onError: [], + onSend: [], + onResponse: [], + onTimeout: [], + onReady: [], + onClose: [], + onRoute: [], + onRegister: [], + onListen: [], + onRequestAbort: [], + preClose: [] }) }) diff --git a/test/index.test.js b/test/index.test.js index d94ef19..d3c4bef 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,6 +1,6 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') const fastify = require('fastify') const plugin = require('../index') const { handleRoutes } = require('../lib/utils') @@ -33,21 +33,21 @@ test('basic test', async t => { try { app.overview() - t.fail('it must throw') + t.assert.fail('it must throw') } catch (error) { - t.match(error.message, 'must be in ready status') + t.assert.match(error.message, /must be in ready status/) } await app.ready() const structure = app.overview() - t.type(structure.id, 'number') - t.equal(structure.children.length, 3) - t.same(structure.decorators.decorate, [ + t.assert.ok(typeof structure.id === 'number') + t.assert.deepEqual(structure.children.length, 3) + t.assert.deepStrictEqual(structure.decorators.decorate, [ { name: 'test', type: 'function' }, { name: 'testObject', type: 'object' }, { name: 'testArray', type: 'array' } ]) - t.same(structure.hooks, require('./fixture/index.00.json')) + t.assert.deepStrictEqual(structure.hooks, require('./fixture/index.00.json')) }) test('register', async t => { @@ -74,26 +74,26 @@ test('register', async t => { await app.ready() const root = app.overview() - t.equal(root.children.length, 1) - t.equal(root.children[0].name, 'register1') - t.same(root.decorators.decorate, [{ name: 'foo-bar', type: 'function' }]) - t.equal(root.hooks.onRequest.length, 0) - t.equal(root.hooks.preParsing.length, 0) - t.equal(root.hooks.preValidation.length, 0) - t.equal(root.hooks.preHandler.length, 0) - t.equal(root.hooks.preSerialization.length, 0) - t.equal(root.hooks.onError.length, 0) - t.equal(root.hooks.onSend.length, 1) - t.equal(root.hooks.onResponse.length, 0) - t.equal(root.hooks.onTimeout.length, 0) + t.assert.deepEqual(root.children.length, 1) + t.assert.deepEqual(root.children[0].name, 'register1') + t.assert.deepStrictEqual(root.decorators.decorate, [{ name: 'foo-bar', type: 'function' }]) + t.assert.deepEqual(root.hooks.onRequest.length, 0) + t.assert.deepEqual(root.hooks.preParsing.length, 0) + t.assert.deepEqual(root.hooks.preValidation.length, 0) + t.assert.deepEqual(root.hooks.preHandler.length, 0) + t.assert.deepEqual(root.hooks.preSerialization.length, 0) + t.assert.deepEqual(root.hooks.onError.length, 0) + t.assert.deepEqual(root.hooks.onSend.length, 1) + t.assert.deepEqual(root.hooks.onResponse.length, 0) + t.assert.deepEqual(root.hooks.onTimeout.length, 0) const reg1 = root.children[0] - t.type(reg1.id, 'number') - t.equal(reg1.children.length, 3) - t.equal(reg1.children[0].name, 'register2') - t.equal(reg1.children[1].name, 'register3') - t.equal(reg1.children[2].name, 'register4') - t.equal(reg1.hooks.onRequest.length, 1) + t.assert.ok(typeof reg1.id === 'number') + t.assert.deepEqual(reg1.children.length, 3) + t.assert.deepEqual(reg1.children[0].name, 'register2') + t.assert.deepEqual(reg1.children[1].name, 'register3') + t.assert.deepEqual(reg1.children[2].name, 'register4') + t.assert.deepEqual(reg1.hooks.onRequest.length, 1) }) test('hide empty', async t => { @@ -119,7 +119,7 @@ test('hide empty', async t => { await app.ready() const structure = app.overview({ hideEmpty: true }) - t.strictSame(structure.decorators, { + t.assert.deepStrictEqual(structure.decorators, { decorate: [ { name: 'emptyObject', type: 'object' }, { name: 'emptyArray', type: 'array' } @@ -129,21 +129,21 @@ test('hide empty', async t => { ] }) - t.strictSame(structure.hooks, { + t.assert.deepStrictEqual(structure.hooks, { onRequest: [{ name: 'hook1', hash: '31d31d981f412085927efb5e9f36be8ba905516a' }], preParsing: [{ name: 'hook2', hash: '07f8fc52f2a92adc80881b4c11ee61ab56ea42d1' }], preValidation: [{ name: 'hook3', hash: '92b002434cd5d8481e7e5562b51df679e2f8d586' }], onError: [{ name: 'hookSix', hash: '9398f5df01879094095221d86a544179e62cee12' }] }) - t.equal(structure.children.length, 2) + t.assert.deepEqual(structure.children.length, 2) delete structure.children[0].id - t.same(structure.children[0], { + t.assert.deepStrictEqual(structure.children[0], { name: 'function (instance, opts, next) { next() }' }, 'should have only the name') - t.strictSame(structure.children[1].children[0].decorators, { + t.assert.deepStrictEqual(structure.children[1].children[0].decorators, { decorateReply: [ { name: 'oneRep', type: 'object' } ] @@ -185,7 +185,7 @@ test('filter routes with hide', async t => { } }) - t.same(root.routes, [ + t.assert.deepStrictEqual(root.routes, [ { method: 'GET', prefix: '', @@ -203,11 +203,11 @@ test('filter routes with hide', async t => { } ]) - t.same( + t.assert.deepStrictEqual( Object.keys(root.children[0]), ['id', 'name', 'children'], 'should not have routes key' ) - t.equal(root.children[0].children[0].routes.length, 1) + t.assert.deepEqual(root.children[0].children[0].routes.length, 1) }) test('filter routes without hide', async t => { @@ -245,7 +245,7 @@ test('filter routes without hide', async t => { } }) - t.same(root.routes, [ + t.assert.deepStrictEqual(root.routes, [ { method: 'GET', prefix: '', @@ -299,8 +299,8 @@ test('filter routes without hide', async t => { } ]) - t.equal(root.children[0].routes.length, 0) - t.equal(root.children[0].children[0].routes.length, 1) + t.assert.deepEqual(root.children[0].routes.length, 0) + t.assert.deepEqual(root.children[0].children[0].routes.length, 1) }) test('empty routes with no opts', async t => { @@ -309,5 +309,5 @@ test('empty routes with no opts', async t => { const result = handleRoutes(value, opts) - t.equal(result, undefined) + t.assert.deepEqual(result, undefined) }) diff --git a/test/routes.test.js b/test/routes.test.js index 765c631..ea5696e 100644 --- a/test/routes.test.js +++ b/test/routes.test.js @@ -1,6 +1,6 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') const fastify = require('fastify') const plugin = require('../index') @@ -79,24 +79,24 @@ test('routes', async t => { await app.ready() const root = app.overview() - t.equal(root.children.length, 3) - t.equal(root.children[0].name, 'register1') - t.equal(root.children[1].name, 'sibling') - t.equal(root.children[2].name, 'routes') - t.equal(root.routes.length, 9) - t.same(root.routes, require('./fixture/routes.00.json')) + t.assert.deepEqual(root.children.length, 3) + t.assert.deepEqual(root.children[0].name, 'register1') + t.assert.deepEqual(root.children[1].name, 'sibling') + t.assert.deepEqual(root.children[2].name, 'routes') + t.assert.deepEqual(root.routes.length, 9) + t.assert.deepStrictEqual(root.routes, require('./fixture/routes.00.json')) const reg1 = root.children[0] - t.same(reg1.routes.length, 7) - t.same(reg1.routes, require('./fixture/routes.01.json')) + t.assert.deepStrictEqual(reg1.routes.length, 7) + t.assert.deepStrictEqual(reg1.routes, require('./fixture/routes.01.json')) const reg2 = reg1.children[0] - t.same(reg2.routes.length, 2) - t.same(reg2.routes, require('./fixture/routes.02.json')) + t.assert.deepStrictEqual(reg2.routes.length, 2) + t.assert.deepStrictEqual(reg2.routes, require('./fixture/routes.02.json')) const reg3 = root.children[2] - t.same(reg3.routes.length, 9) - t.same(reg3.routes, require('./fixture/routes.03.json')) + t.assert.deepStrictEqual(reg3.routes.length, 9) + t.assert.deepStrictEqual(reg3.routes, require('./fixture/routes.03.json')) }) test('custom onRouteDefinition', async t => { @@ -138,17 +138,17 @@ test('custom onRouteDefinition', async t => { const root = app.overview() - t.equal(root.children.length, 1) - t.equal(root.routes.length, 2) - t.same(root.routes, require('./fixture/routes.04.json')) + t.assert.deepEqual(root.children.length, 1) + t.assert.deepEqual(root.routes.length, 2) + t.assert.deepEqual(root.routes, require('./fixture/routes.04.json')) - t.equal(root.children[0].routes.length, 1) - t.equal(root.children[0].children.length, 1) - t.same(root.children[0].routes, require('./fixture/routes.05.json')) + t.assert.deepEqual(root.children[0].routes.length, 1) + t.assert.deepEqual(root.children[0].children.length, 1) + t.assert.deepEqual(root.children[0].routes, require('./fixture/routes.05.json')) - t.equal(root.children[0].children[0].routes.length, 1) - t.equal(root.children[0].children[0].children.length, 0) - t.same(root.children[0].children[0].routes, require('./fixture/routes.06.json')) + t.assert.deepEqual(root.children[0].children[0].routes.length, 1) + t.assert.deepEqual(root.children[0].children[0].children.length, 0) + t.assert.deepEqual(root.children[0].children[0].routes, require('./fixture/routes.06.json')) }) test('custom onRouteDefinition with overriding', async t => { @@ -170,7 +170,7 @@ test('custom onRouteDefinition with overriding', async t => { const root = app.overview() - t.equal(root.children.length, 0) - t.equal(root.routes.length, 2) - t.same(root.routes, require('./fixture/routes.07.json')) + t.assert.deepEqual(root.children.length, 0) + t.assert.deepEqual(root.routes.length, 2) + t.assert.deepStrictEqual(root.routes, require('./fixture/routes.07.json')) }) diff --git a/test/source-code.test.js b/test/source-code.test.js index c28ee28..9621b2d 100644 --- a/test/source-code.test.js +++ b/test/source-code.test.js @@ -1,6 +1,6 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') const os = require('os') const buildApp = require('./sources/app') @@ -21,29 +21,29 @@ test('simple app', async t => { .replace(removeLocalPath, '') .replace(removeRelativePath, '') .replace(removeRandomId, '42') - t.same(JSON.parse(result), require('./fixture/app-source.json'), { skip: isWindows }) + t.assert.deepStrictEqual(JSON.parse(result), require('./fixture/app-source.json'), { skip: isWindows }) - t.equal(root.hooks.preHandler.length, 1) - t.match(root.hooks.preHandler[0].source, { - stackIndex: 0, - fileName: /test\/sources\/app\.js$/, - lineNumber: 17, - columnNumber: 7, - functionName: 'buildTheSourceApp', - typeName: null, - methodName: null - }, { skip: isWindows }) + if (!isWindows) { + t.assert.deepStrictEqual(root.hooks.preHandler.length, 1) + t.assert.deepStrictEqual(root.hooks.preHandler[0].source.stackIndex, 0) + t.assert.match(root.hooks.preHandler[0].source.fileName, /test\/sources\/app\.js$/) + t.assert.deepStrictEqual(root.hooks.preHandler[0].source.lineNumber, 17) + t.assert.deepStrictEqual(root.hooks.preHandler[0].source.columnNumber, 7) + t.assert.deepStrictEqual(root.hooks.preHandler[0].source.functionName, 'buildTheSourceApp') + t.assert.deepStrictEqual(root.hooks.preHandler[0].source.typeName, null) + t.assert.deepStrictEqual(root.hooks.preHandler[0].source.methodName, null) + } - t.equal(root.children.length, 2) - t.equal(root.children[0].name, 'register1') - t.equal(root.children[1].name, 'sibling') - t.equal(root.routes.length, 4) + t.assert.deepStrictEqual(root.children.length, 2) + t.assert.deepStrictEqual(root.children[0].name, 'register1') + t.assert.deepStrictEqual(root.children[1].name, 'sibling') + t.assert.deepStrictEqual(root.routes.length, 4) const reg1 = root.children[0] - t.same(reg1.routes.length, 3) + t.assert.deepStrictEqual(reg1.routes.length, 3) const reg2 = reg1.children[0] - t.same(reg2.routes.length, 2) + t.assert.deepStrictEqual(reg2.routes.length, 2) }) test('coverage: simple app', async t => { @@ -54,10 +54,10 @@ test('coverage: simple app', async t => { const structure = JSON.stringify(root, null, 2) const removeRandomId = /(?<="id": ).*(?=,)/gmi const result = structure.replace(removeRandomId, '42') - t.same(JSON.parse(result), require('./fixture/app-no-source.json'), { skip: isWindows }) + t.assert.deepStrictEqual(JSON.parse(result), require('./fixture/app-no-source.json'), { skip: isWindows }) - t.equal(root.hooks.preHandler.length, 1) - t.notOk(root.hooks.preHandler[0].source) + t.assert.deepStrictEqual(root.hooks.preHandler.length, 1) + t.assert.ok(!root.hooks.preHandler[0].source) }) test('autoload', async t => { @@ -75,5 +75,7 @@ test('autoload', async t => { .replace(removeRelativePath, '') .replace(removeLocalName, '') .replace(removeRandomId, '42') - t.same(JSON.parse(result), require('./fixture/autoload.json'), { skip: isWindows }) + if (!isWindows) { + t.assert.deepStrictEqual(JSON.parse(result), require('./fixture/autoload.json')) + } }) From f6f440113f13cac948804a31791d36dcca87c657 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sat, 7 Dec 2024 10:33:00 +0100 Subject: [PATCH 2/6] BREAKING CHANGE: migrate to v5 --- index.js | 2 +- package.json | 18 ++--- test/decorator.test.js | 24 +++--- test/fixture/routes.00.json | 3 +- test/fixture/routes.03.json | 155 ------------------------------------ test/fixture/routes.04.json | 7 +- test/fixture/routes.06.json | 7 +- test/index.test.js | 8 +- test/routes.test.js | 40 ++++------ 9 files changed, 52 insertions(+), 212 deletions(-) delete mode 100644 test/fixture/routes.03.json diff --git a/index.js b/index.js index c1c4596..3abc360 100644 --- a/index.js +++ b/index.js @@ -192,7 +192,7 @@ function getJsonOverview (request, reply) { const plugin = fp(fastifyOverview, { name: 'fastify-overview', - fastify: '^4.23.x' + fastify: '5.x' }) module.exports = plugin diff --git a/package.json b/package.json index c8986b9..30dae60 100644 --- a/package.json +++ b/package.json @@ -32,17 +32,17 @@ }, "homepage": "https://github.com/Eomm/fastify-overview#readme", "devDependencies": { - "@fastify/autoload": "^5.0.0", - "@types/node": "^20.1.0", - "@typescript-eslint/eslint-plugin": "^6.2.1", - "@typescript-eslint/parser": "^6.0.0", - "fastify": "^4.23.0", - "standard": "^17.0.0", - "tsd": "^0.31.0" + "@fastify/autoload": "^6.0.2", + "@types/node": "^22.10.1", + "@typescript-eslint/eslint-plugin": "^8.17.0", + "@typescript-eslint/parser": "^8.17.0", + "fastify": "^5.1.0", + "standard": "^17.1.2", + "tsd": "^0.31.2" }, "dependencies": { - "fastify-plugin": "^4.0.0", - "object-hash": "^2.2.0" + "fastify-plugin": "^5.0.1", + "object-hash": "^3.0.0" }, "tsd": { "directory": "test/types" diff --git a/test/decorator.test.js b/test/decorator.test.js index 2aa5ce8..9634fb5 100644 --- a/test/decorator.test.js +++ b/test/decorator.test.js @@ -14,7 +14,7 @@ test('decorator', async t => { app.decorateReply('root-reply', function () {}) app.decorate('root-symbol', Symbol('testSymbol')) - app.decorateReply('root-reply-array', []) + app.decorateReply('root-reply-array', () => ({ getter: [] })) app.decorateRequest('root-req-boolean', true) app.register(function register1 (instance, opts, next) { @@ -28,7 +28,7 @@ test('decorator', async t => { instance.register(function register3 (sub, opts, next) { sub.decorate('sub-instance', 50) sub.decorateReply('sub', 50) - sub.decorateRequest('sub-object', {}) + sub.decorateRequest('sub-object', () => ({ getter: {} })) next() }) next() @@ -45,7 +45,7 @@ test('decorator', async t => { t.assert.deepEqual(root.children[1].name, 'sibling') t.assert.deepStrictEqual(root.decorators.decorate, [{ name: 'root-func', type: 'function' }, { name: 'root-symbol', type: 'symbol' }]) t.assert.deepStrictEqual(root.decorators.decorateRequest, [{ name: 'root-req', type: 'function' }, { name: 'root-req-two', type: 'function' }, { name: 'root-req-boolean', type: 'boolean' }]) - t.assert.deepStrictEqual(root.decorators.decorateReply, [{ name: 'root-reply', type: 'function' }, { name: 'root-reply-array', type: 'array' }]) + t.assert.deepStrictEqual(root.decorators.decorateReply, [{ name: 'root-reply', type: 'function' }, { name: 'root-reply-array', type: 'function' }]) const reg1 = root.children[0] t.assert.deepStrictEqual(reg1.decorators.decorate, [{ name: 'child-1-bigint', type: 'bigint' }, { name: 'child-1-undefined', type: 'undefined' }]) @@ -60,7 +60,7 @@ test('decorator', async t => { const reg3 = reg1.children[1] t.assert.deepStrictEqual(reg3.decorators.decorate, [{ name: 'sub-instance', type: 'number' }]) - t.assert.deepStrictEqual(reg3.decorators.decorateRequest, [{ name: 'sub-object', type: 'object' }]) + t.assert.deepStrictEqual(reg3.decorators.decorateRequest, [{ name: 'sub-object', type: 'function' }]) t.assert.deepStrictEqual(reg3.decorators.decorateReply, [{ name: 'sub', type: 'number' }]) }) @@ -83,14 +83,14 @@ test('onDecorateDefinition', async t => { } }) - app.decorate('emptyObj', {}) + app.decorate('emptyObj', () => ({ getter: {} })) app.decorate('obj1', { run: () => {} }) - app.decorateRequest('emptyObj', {}) - app.decorateReply('obj2', { - test: 'str' - }) + app.decorateRequest('emptyObj', () => ({ getter: {} })) + app.decorateReply('obj2', () => ({ + getter: { test: 'str' } + })) app.register(async function child1 (instance) { instance.decorate('encapsulatedObj', { @@ -106,9 +106,9 @@ test('onDecorateDefinition', async t => { const root = app.overview() t.assert.deepEqual(root.children.length, 1) - t.assert.deepStrictEqual(root.decorators.decorate, [{ name: 'emptyObj', type: 'object', recursive: [] }, { name: 'obj1', type: 'object', recursive: [{ name: 'run', type: 'function' }] }]) - t.assert.deepStrictEqual(root.decorators.decorateReply, [{ name: 'obj2', type: 'object', recursive: [{ name: 'test', type: 'string' }] }]) - t.assert.deepStrictEqual(root.decorators.decorateRequest, [{ name: 'emptyObj', type: 'object', recursive: [] }]) + t.assert.deepStrictEqual(root.decorators.decorate, [{ name: 'emptyObj', type: 'function' }, { name: 'obj1', type: 'object', recursive: [{ name: 'run', type: 'function' }] }]) + t.assert.deepStrictEqual(root.decorators.decorateReply, [{ name: 'obj2', type: 'function' }]) + t.assert.deepStrictEqual(root.decorators.decorateRequest, [{ name: 'emptyObj', type: 'function' }]) t.assert.deepEqual(root.children[0].name, 'child1') const child1 = root.children[0] diff --git a/test/fixture/routes.00.json b/test/fixture/routes.00.json index 6c7a75d..9c88a0e 100644 --- a/test/fixture/routes.00.json +++ b/test/fixture/routes.00.json @@ -138,8 +138,7 @@ { "method":[ "GET", - "POST", - "PROPPATCH" + "POST" ], "url":"/array", "prefix":"", diff --git a/test/fixture/routes.03.json b/test/fixture/routes.03.json deleted file mode 100644 index 510d627..0000000 --- a/test/fixture/routes.03.json +++ /dev/null @@ -1,155 +0,0 @@ -[ - { - "method": "PROPFIND", - "url": "/api/test", - "prefix": "/api", - "hooks": { - "onRequest": [], - "preParsing": [], - "preValidation": [], - "preHandler": [], - "preSerialization": [], - "onError": [], - "onSend": [], - "onResponse": [], - "onTimeout": [], - "onRequestAbort": [] - } - }, - { - "method": "PROPPATCH", - "url": "/api/test", - "prefix": "/api", - "hooks": { - "onRequest": [], - "preParsing": [], - "preValidation": [], - "preHandler": [], - "preSerialization": [], - "onError": [], - "onSend": [], - "onResponse": [], - "onTimeout": [], - "onRequestAbort": [] - } - }, - { - "method": "MKCOL", - "url": "/api/test", - "prefix": "/api", - "hooks": { - "onRequest": [], - "preParsing": [], - "preValidation": [], - "preHandler": [], - "preSerialization": [], - "onError": [], - "onSend": [], - "onResponse": [], - "onTimeout": [], - "onRequestAbort": [] - } - }, - { - "method": "COPY", - "url": "/api/test", - "prefix": "/api", - "hooks": { - "onRequest": [], - "preParsing": [], - "preValidation": [], - "preHandler": [], - "preSerialization": [], - "onError": [], - "onSend": [], - "onResponse": [], - "onTimeout": [], - "onRequestAbort": [] - } - }, - { - "method": "MOVE", - "url": "/api/test", - "prefix": "/api", - "hooks": { - "onRequest": [], - "preParsing": [], - "preValidation": [], - "preHandler": [], - "preSerialization": [], - "onError": [], - "onSend": [], - "onResponse": [], - "onTimeout": [], - "onRequestAbort": [] - } - }, - { - "method": "LOCK", - "url": "/api/test", - "prefix": "/api", - "hooks": { - "onRequest": [], - "preParsing": [], - "preValidation": [], - "preHandler": [], - "preSerialization": [], - "onError": [], - "onSend": [], - "onResponse": [], - "onTimeout": [], - "onRequestAbort": [] - } - }, - { - "method": "UNLOCK", - "url": "/api/test", - "prefix": "/api", - "hooks": { - "onRequest": [], - "preParsing": [], - "preValidation": [], - "preHandler": [], - "preSerialization": [], - "onError": [], - "onSend": [], - "onResponse": [], - "onTimeout": [], - "onRequestAbort": [] - } - }, - { - "method": "TRACE", - "url": "/api/test", - "prefix": "/api", - "hooks": { - "onRequest": [], - "preParsing": [], - "preValidation": [], - "preHandler": [], - "preSerialization": [], - "onError": [], - "onSend": [], - "onResponse": [], - "onTimeout": [], - "onRequestAbort": [] - } - }, - { - "method": "SEARCH", - "url": "/api/test", - "prefix": "/api", - "hooks": { - "onRequest": [], - "preParsing": [], - "preValidation": [], - "preHandler": [], - "preSerialization": [], - "onError": [], - "onSend": [], - "onResponse": [], - "onTimeout": [], - "onRequestAbort": [] - } - } -] diff --git a/test/fixture/routes.04.json b/test/fixture/routes.04.json index f5b0e09..b06ef26 100644 --- a/test/fixture/routes.04.json +++ b/test/fixture/routes.04.json @@ -22,8 +22,11 @@ "url":"/post", "prefix":"", "bodySchema": { - "test": { - "type": "string" + "type": "object", + "properties": { + "test": { + "type": "string" + } } }, "hooks":{ diff --git a/test/fixture/routes.06.json b/test/fixture/routes.06.json index ecb234c..fa57ca3 100644 --- a/test/fixture/routes.06.json +++ b/test/fixture/routes.06.json @@ -4,8 +4,11 @@ "url":"/api/patch/:param", "prefix":"/api", "bodySchema": { - "text": { - "type": "boolean" + "type": "object", + "properties": { + "text": { + "type": "boolean" + } } }, "hooks":{ diff --git a/test/index.test.js b/test/index.test.js index d3c4bef..5bc2166 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -102,7 +102,7 @@ test('hide empty', async t => { app.decorate('emptyObject', {}) app.decorate('emptyArray', []) - app.decorateRequest('oneReqDecor', []) + app.decorateRequest('oneReqDecor', () => ({ getter: [] })) app.addHook('onRequest', function hook1 () {}) app.addHook('preParsing', function hook2 () {}) @@ -112,7 +112,7 @@ test('hide empty', async t => { app.register(function (instance, opts, next) { next() }) app.register(async function (instance, opts) { instance.register(async function (instance, opts) { - instance.decorateReply('oneRep', {}) + instance.decorateReply('oneRep', () => ({ getter: {} })) }) }) @@ -125,7 +125,7 @@ test('hide empty', async t => { { name: 'emptyArray', type: 'array' } ], decorateRequest: [ - { name: 'oneReqDecor', type: 'array' } + { name: 'oneReqDecor', type: 'function' } ] }) @@ -145,7 +145,7 @@ test('hide empty', async t => { t.assert.deepStrictEqual(structure.children[1].children[0].decorators, { decorateReply: [ - { name: 'oneRep', type: 'object' } + { name: 'oneRep', type: 'function' } ] }) }) diff --git a/test/routes.test.js b/test/routes.test.js index ea5696e..444271c 100644 --- a/test/routes.test.js +++ b/test/routes.test.js @@ -28,7 +28,7 @@ test('routes', async t => { handler: noop }) app.route({ - method: ['GET', 'POST', 'PROPPATCH'], + method: ['GET', 'POST'], url: '/array', handler () {} }) @@ -64,25 +64,13 @@ test('routes', async t => { app.register(function sibling (instance, opts, next) { next() }) - app.register(function routes (instance, opts, next) { - ['propfind', 'proppatch', 'mkcol', 'copy', 'move', 'lock', 'unlock', 'trace', 'search'].forEach(method => { - instance.route({ - method, - url: '/test', - handler () {} - }) - }) - - next() - }, { prefix: '/api' }) await app.ready() const root = app.overview() - t.assert.deepEqual(root.children.length, 3) + t.assert.deepEqual(root.children.length, 2) t.assert.deepEqual(root.children[0].name, 'register1') t.assert.deepEqual(root.children[1].name, 'sibling') - t.assert.deepEqual(root.children[2].name, 'routes') t.assert.deepEqual(root.routes.length, 9) t.assert.deepStrictEqual(root.routes, require('./fixture/routes.00.json')) @@ -93,10 +81,6 @@ test('routes', async t => { const reg2 = reg1.children[0] t.assert.deepStrictEqual(reg2.routes.length, 2) t.assert.deepStrictEqual(reg2.routes, require('./fixture/routes.02.json')) - - const reg3 = root.children[2] - t.assert.deepStrictEqual(reg3.routes.length, 9) - t.assert.deepStrictEqual(reg3.routes, require('./fixture/routes.03.json')) }) test('custom onRouteDefinition', async t => { @@ -111,22 +95,28 @@ test('custom onRouteDefinition', async t => { }) app.get('/get', noop) - app.post('/post', { schema: { body: { test: { type: 'string' } } } }, noop) + app.post('/post', { schema: { body: { type: 'object', properties: { test: { type: 'string' } } } } }, noop) app.register(async (instance) => { - instance.put('/plugin', { schema: { querystring: { size: { type: 'integer' } } } }, noop) + instance.put('/plugin', { schema: { querystring: { type: 'object', properties: { size: { type: 'integer' } } } } }, noop) instance.register(async function (instance2) { instance2.patch('/patch/:param', { schema: { params: { - param: { - type: 'string' + type: 'object', + properties: { + param: { + type: 'string' + } } }, body: { - text: { - type: 'boolean' + type: 'object', + properties: { + text: { + type: 'boolean' + } } } } @@ -164,7 +154,7 @@ test('custom onRouteDefinition with overriding', async t => { }) app.get('/get', noop) - app.post('/post', { schema: { body: { test: { type: 'string' } } } }, noop) + app.post('/post', { schema: { body: { type: 'object', properties: { test: { type: 'string' } } } } }, noop) await app.ready() From f71091a02c31bea851727c65f617bcf5535882a4 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 8 Dec 2024 23:15:40 +0100 Subject: [PATCH 3/6] BREAKING CHANGE: removed avvio's dependency --- index.js | 3 -- test/fixture/app-source.json | 32 +------------- test/fixture/autoload.json | 82 +----------------------------------- 3 files changed, 2 insertions(+), 115 deletions(-) diff --git a/index.js b/index.js index 3abc360..6398787 100644 --- a/index.js +++ b/index.js @@ -86,9 +86,6 @@ function fastifyOverview (fastify, options, next) { instance[kTrackerMe] = trackingToken const trackStructure = getPluginNode(trackingToken, instance.pluginName) - if (opts.addSource && this) { - trackStructure.source = this._current.find(loadPipe => loadPipe.func[kSourceRegister] !== undefined).func[kSourceRegister] - } contextMap.set(trackingToken, trackStructure) instance[kStructure] = trackStructure diff --git a/test/fixture/app-source.json b/test/fixture/app-source.json index 86b2cf5..44d8f7f 100644 --- a/test/fixture/app-source.json +++ b/test/fixture/app-source.json @@ -147,16 +147,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/app.js", - "relativeFileName": "test/sources/app.js", - "lineNumber": 30, - "columnNumber": 14, - "functionName": "register1", - "typeName": null, - "methodName": null } } ], @@ -265,16 +255,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/app.js", - "relativeFileName": "test/sources/app.js", - "lineNumber": 26, - "columnNumber": 7, - "functionName": "buildTheSourceApp", - "typeName": null, - "methodName": null } }, { @@ -332,16 +312,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/app.js", - "relativeFileName": "test/sources/app.js", - "lineNumber": 43, - "columnNumber": 7, - "functionName": "buildTheSourceApp", - "typeName": null, - "methodName": null } } ], @@ -538,4 +508,4 @@ "onRoute": [], "onRegister": [] } -} +} \ No newline at end of file diff --git a/test/fixture/autoload.json b/test/fixture/autoload.json index c2a6950..1b83d61 100644 --- a/test/fixture/autoload.json +++ b/test/fixture/autoload.json @@ -151,16 +151,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/autoload/file-one.js", - "relativeFileName": "test/sources/autoload/file-one.js", - "lineNumber": 27, - "columnNumber": 12, - "functionName": "fileOne", - "typeName": null, - "methodName": null } } ], @@ -305,16 +295,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/autoload.js", - "relativeFileName": "test/sources/autoload.js", - "lineNumber": 16, - "columnNumber": 7, - "functionName": "buildTheSourceApp", - "typeName": null, - "methodName": null } }, { @@ -372,16 +352,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/autoload.js", - "relativeFileName": "test/sources/autoload.js", - "lineNumber": 16, - "columnNumber": 7, - "functionName": "buildTheSourceApp", - "typeName": null, - "methodName": null } }, { @@ -439,16 +409,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/autoload.js", - "relativeFileName": "test/sources/autoload.js", - "lineNumber": 16, - "columnNumber": 7, - "functionName": "buildTheSourceApp", - "typeName": null, - "methodName": null } }, { @@ -506,16 +466,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/autoload.js", - "relativeFileName": "test/sources/autoload.js", - "lineNumber": 16, - "columnNumber": 7, - "functionName": "buildTheSourceApp", - "typeName": null, - "methodName": null } }, { @@ -663,16 +613,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/autoload.js", - "relativeFileName": "test/sources/autoload.js", - "lineNumber": 37, - "columnNumber": 14, - "functionName": "register1", - "typeName": null, - "methodName": null } } ], @@ -781,16 +721,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/autoload.js", - "relativeFileName": "test/sources/autoload.js", - "lineNumber": 33, - "columnNumber": 7, - "functionName": "buildTheSourceApp", - "typeName": null, - "methodName": null } }, { @@ -848,16 +778,6 @@ "onClose": [], "onRoute": [], "onRegister": [] - }, - "source": { - "stackIndex": 0, - "fileName": "test/sources/autoload.js", - "relativeFileName": "test/sources/autoload.js", - "lineNumber": 50, - "columnNumber": 7, - "functionName": "buildTheSourceApp", - "typeName": null, - "methodName": null } } ], @@ -1054,4 +974,4 @@ "onRoute": [], "onRegister": [] } -} +} \ No newline at end of file From f40ee0ad525096faf10a87b2f307419a46968e88 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Mon, 9 Dec 2024 21:32:51 +0100 Subject: [PATCH 4/6] fix: isWindows skips --- test/source-code.test.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/source-code.test.js b/test/source-code.test.js index 9621b2d..625d862 100644 --- a/test/source-code.test.js +++ b/test/source-code.test.js @@ -21,10 +21,11 @@ test('simple app', async t => { .replace(removeLocalPath, '') .replace(removeRelativePath, '') .replace(removeRandomId, '42') - t.assert.deepStrictEqual(JSON.parse(result), require('./fixture/app-source.json'), { skip: isWindows }) + + t.assert.deepStrictEqual(root.hooks.preHandler.length, 1) if (!isWindows) { - t.assert.deepStrictEqual(root.hooks.preHandler.length, 1) + t.assert.deepStrictEqual(JSON.parse(result), require('./fixture/app-source.json')) t.assert.deepStrictEqual(root.hooks.preHandler[0].source.stackIndex, 0) t.assert.match(root.hooks.preHandler[0].source.fileName, /test\/sources\/app\.js$/) t.assert.deepStrictEqual(root.hooks.preHandler[0].source.lineNumber, 17) @@ -54,7 +55,10 @@ test('coverage: simple app', async t => { const structure = JSON.stringify(root, null, 2) const removeRandomId = /(?<="id": ).*(?=,)/gmi const result = structure.replace(removeRandomId, '42') - t.assert.deepStrictEqual(JSON.parse(result), require('./fixture/app-no-source.json'), { skip: isWindows }) + + if (!isWindows) { + t.assert.deepStrictEqual(JSON.parse(result), require('./fixture/app-no-source.json')) + } t.assert.deepStrictEqual(root.hooks.preHandler.length, 1) t.assert.ok(!root.hooks.preHandler[0].source) From 94afe19fcea0f073f4cd27a1e8402d9901dec73a Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Sat, 14 Dec 2024 09:06:25 +0100 Subject: [PATCH 5/6] Update test/expose-routes.test.js --- test/expose-routes.test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/expose-routes.test.js b/test/expose-routes.test.js index 4f3fd73..2aecb3b 100644 --- a/test/expose-routes.test.js +++ b/test/expose-routes.test.js @@ -89,10 +89,7 @@ test('expose the route within more options', async t => { onResponse: [], onSend: [], onTimeout: [], - preHandler: [{ - name: 'hook', - hash: '1994f633554c479b3ffceeebdb7328ddf56d0234' - }], + preHandler: [], preParsing: [], preSerialization: [], preValidation: [] From f7fdc6567092a18115f652c613e7a0ee21e5bac6 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Fri, 27 Dec 2024 14:48:04 +0100 Subject: [PATCH 6/6] fix test --- test/expose-routes.test.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/test/expose-routes.test.js b/test/expose-routes.test.js index 2aecb3b..14d5522 100644 --- a/test/expose-routes.test.js +++ b/test/expose-routes.test.js @@ -58,7 +58,7 @@ test('expose the route to the the json', async t => { }) test('expose the route within more options', async t => { - t.plan(6) + t.plan(7) const app = fastify() await app.register(plugin, { @@ -77,25 +77,25 @@ test('expose the route within more options', async t => { t.assert.deepStrictEqual(responseContent.name, 'fastify -> fastify-overview') t.assert.deepStrictEqual(responseContent.children, []) - t.assert.deepEqual(responseContent.routes, [ - { - method: 'GET', - url: '/foo', - prefix: '', - hooks: { - onError: [], - onRequest: [], - onRequestAbort: [], - onResponse: [], - onSend: [], - onTimeout: [], - preHandler: [], - preParsing: [], - preSerialization: [], - preValidation: [] - } + t.assert.strictEqual(responseContent.routes.length, 1) + delete responseContent.routes[0].hooks.preHandler[0].hash + t.assert.deepStrictEqual(responseContent.routes[0], { + method: 'GET', + url: '/foo', + prefix: '', + hooks: { + onError: [], + onRequest: [], + onRequestAbort: [], + onResponse: [], + onSend: [], + onTimeout: [], + preHandler: [{ name: 'hook' }], + preParsing: [], + preSerialization: [], + preValidation: [] } - ]) + }) t.assert.deepStrictEqual(responseContent.decorators, { decorate: [], decorateRequest: [],