From 0f9b9a0f98c319c08a14d4941c16596793726b03 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Thu, 15 Jun 2023 08:23:03 +0200 Subject: [PATCH] fix: add missing preClose hook (#72) --- index.d.ts | 1 + lib/utils.js | 1 + test/application-hooks.test.js | 33 +++++++++++++++++++++++ test/fixture/app-hooks.json | 48 +++++++++++++++++++++++++++++++++ test/fixture/app-no-source.json | 4 +++ test/fixture/app-source.json | 4 +++ test/fixture/autoload.json | 9 +++++++ test/fixture/index.00.json | 1 + 8 files changed, 101 insertions(+) create mode 100644 test/application-hooks.test.js create mode 100644 test/fixture/app-hooks.json diff --git a/index.d.ts b/index.d.ts index 51a4c18..46c3009 100644 --- a/index.d.ts +++ b/index.d.ts @@ -61,6 +61,7 @@ interface OverviewStructureHooks { onResponse?: OverviewStructureHook[], onTimeout?: OverviewStructureHook[], onReady?: OverviewStructureHook[], + preClose?: OverviewStructureHook[], onClose?: OverviewStructureHook[], onRoute?: OverviewStructureHook[], onRegister?: OverviewStructureHook[], diff --git a/lib/utils.js b/lib/utils.js index c1ea1af..eb22908 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -88,6 +88,7 @@ function getEmptyHookRoute () { function getEmptyHookApplication () { return { onReady: [], + preClose: [], onClose: [], onRoute: [], onRegister: [] diff --git a/test/application-hooks.test.js b/test/application-hooks.test.js new file mode 100644 index 0000000..c75f991 --- /dev/null +++ b/test/application-hooks.test.js @@ -0,0 +1,33 @@ +'use strict' + +const { test } = require('tap') +const fastify = require('fastify') +const plugin = require('../index') + +test('should track all the application hooks', { + skip: process.platform === 'win32' +}, async t => { + const app = fastify() + await app.register(plugin) + + app.addHook('onReady', function onReady (done) { + done() + }) + app.addHook('onReady', async function onReadyAsync () { }) + + app.addHook('onClose', function onClose (app, done) { + done() + }) + app.addHook('onClose', async function onCloseAsync (app) { }) + + app.addHook('onRoute', function onRoute (routeOptions) { }) + app.addHook('onRegister', function onRegister (app, opts) { }) + + app.addHook('preClose', function preClose (done) { done() }) + app.addHook('preClose', async function preCloseAsync () { }) + + await app.ready() + const structure = app.overview({ hideEmpty: true }) + + t.same(structure.hooks, require('./fixture/app-hooks.json').hooks) +}) diff --git a/test/fixture/app-hooks.json b/test/fixture/app-hooks.json new file mode 100644 index 0000000..bac6949 --- /dev/null +++ b/test/fixture/app-hooks.json @@ -0,0 +1,48 @@ +{ + "id": 0.4471669761794044, + "name": "fastify -> fastify-overview", + "hooks": { + "onReady": [ + { + "name": "onReady", + "hash": "56f76968f76bf621e0bb3d8ae253f66cd5b33e19" + }, + { + "name": "onReadyAsync", + "hash": "52b0efdc93f5d94bb37724cf135973e4e7e743eb" + } + ], + "preClose": [ + { + "name": "preClose", + "hash": "2e546a99fd59296c5ba6c9d686988a109e4290c4" + }, + { + "name": "preCloseAsync", + "hash": "d06031e55a63f56a2c5be39ccedd6881c38b51f9" + } + ], + "onClose": [ + { + "name": "onClose", + "hash": "c4ea7807be0111815311279108e558cef9b5868d" + }, + { + "name": "onCloseAsync", + "hash": "fdcdc0114406d43e9ee47df5530add31828d210b" + } + ], + "onRoute": [ + { + "name": "onRoute", + "hash": "ea96ec1308642abff965550ed4e9108a2a620e15" + } + ], + "onRegister": [ + { + "name": "onRegister", + "hash": "fb94ad3ed9a554519eb3ea0354856627538b1c5c" + } + ] + } +} \ No newline at end of file diff --git a/test/fixture/app-no-source.json b/test/fixture/app-no-source.json index f3f6b47..e05cd15 100644 --- a/test/fixture/app-no-source.json +++ b/test/fixture/app-no-source.json @@ -79,6 +79,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -151,6 +152,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -194,6 +196,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -299,6 +302,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] diff --git a/test/fixture/app-source.json b/test/fixture/app-source.json index bec4fb0..a188bc7 100644 --- a/test/fixture/app-source.json +++ b/test/fixture/app-source.json @@ -139,6 +139,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -251,6 +252,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -314,6 +316,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -509,6 +512,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] diff --git a/test/fixture/autoload.json b/test/fixture/autoload.json index 829fa21..28e48d8 100644 --- a/test/fixture/autoload.json +++ b/test/fixture/autoload.json @@ -141,6 +141,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -288,6 +289,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -351,6 +353,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -414,6 +417,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -477,6 +481,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -629,6 +634,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -741,6 +747,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -804,6 +811,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] @@ -999,6 +1007,7 @@ "onResponse": [], "onTimeout": [], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": [] diff --git a/test/fixture/index.00.json b/test/fixture/index.00.json index 8576588..51ffcab 100644 --- a/test/fixture/index.00.json +++ b/test/fixture/index.00.json @@ -54,6 +54,7 @@ } ], "onReady": [], + "preClose": [], "onClose": [], "onRoute": [], "onRegister": []