Skip to content

Commit

Permalink
fix: add missing preClose hook (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm authored Jun 15, 2023
1 parent 3555df2 commit 0f9b9a0
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface OverviewStructureHooks {
onResponse?: OverviewStructureHook[],
onTimeout?: OverviewStructureHook[],
onReady?: OverviewStructureHook[],
preClose?: OverviewStructureHook[],
onClose?: OverviewStructureHook[],
onRoute?: OverviewStructureHook[],
onRegister?: OverviewStructureHook[],
Expand Down
1 change: 1 addition & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function getEmptyHookRoute () {
function getEmptyHookApplication () {
return {
onReady: [],
preClose: [],
onClose: [],
onRoute: [],
onRegister: []
Expand Down
33 changes: 33 additions & 0 deletions test/application-hooks.test.js
Original file line number Diff line number Diff line change
@@ -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)
})
48 changes: 48 additions & 0 deletions test/fixture/app-hooks.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
4 changes: 4 additions & 0 deletions test/fixture/app-no-source.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -151,6 +152,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -194,6 +196,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -299,6 +302,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down
4 changes: 4 additions & 0 deletions test/fixture/app-source.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -251,6 +252,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -314,6 +316,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -509,6 +512,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down
9 changes: 9 additions & 0 deletions test/fixture/autoload.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -288,6 +289,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -351,6 +353,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -414,6 +417,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -477,6 +481,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -629,6 +634,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -741,6 +747,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -804,6 +811,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down Expand Up @@ -999,6 +1007,7 @@
"onResponse": [],
"onTimeout": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down
1 change: 1 addition & 0 deletions test/fixture/index.00.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
}
],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
Expand Down

0 comments on commit 0f9b9a0

Please sign in to comment.