From f32a8f201a5cefb8c63e1b048d3425423e155a21 Mon Sep 17 00:00:00 2001 From: Francesco Maida Date: Wed, 25 Feb 2026 17:11:50 +0100 Subject: [PATCH 1/3] fix: fixes hideEmpty not returning routes when no filter is provided --- lib/utils.js | 3 +++ test/index.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/utils.js b/lib/utils.js index b42473b..e4ca65d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -135,4 +135,7 @@ function handleRoutes (value, opts) { if (opts.hideEmpty && value.length === 0) { return undefined } + if (value.length) { + return value + } } diff --git a/test/index.test.js b/test/index.test.js index 5bc2166..262cd85 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -150,6 +150,30 @@ test('hide empty', async t => { }) }) +test('hide empty with no routes filter', async t => { + const app = fastify({ exposeHeadRoutes: false }) + await app.register(plugin) + + app.get('/get', function noop () {}) + app.get('/post', function noop () {}) + + await app.ready() + const root = app.overview({ hideEmpty: true }) + + t.assert.deepStrictEqual(root.routes, [ + { + method: 'GET', + prefix: '', + url: '/get' + }, + { + method: 'GET', + prefix: '', + url: '/post' + } + ]) +}) + test('filter routes with hide', async t => { const app = fastify({ exposeHeadRoutes: false }) await app.register(plugin) From 847bb3171a1499598324d20da411d815ac8572bc Mon Sep 17 00:00:00 2001 From: Francesco Maida Date: Wed, 25 Feb 2026 17:38:00 +0100 Subject: [PATCH 2/3] chore: changed test and fixed script --- lib/utils.js | 4 +--- package.json | 2 +- test/index.test.js | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index e4ca65d..8eb83cf 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -135,7 +135,5 @@ function handleRoutes (value, opts) { if (opts.hideEmpty && value.length === 0) { return undefined } - if (value.length) { - return value - } + return value } diff --git a/package.json b/package.json index 55bc136..d8d89bd 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": "node --test && npm run test:typescript", + "test": "node --test **/*.test.js && npm run test:typescript", "test:typescript": "tsd" }, "repository": { diff --git a/test/index.test.js b/test/index.test.js index 262cd85..ca3732b 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -333,5 +333,5 @@ test('empty routes with no opts', async t => { const result = handleRoutes(value, opts) - t.assert.deepEqual(result, undefined) + t.assert.deepEqual(result, []) }) From 13b053c4d33f08eae8888dcb5977f35b40214b52 Mon Sep 17 00:00:00 2001 From: Francesco Maida Date: Wed, 25 Feb 2026 17:42:22 +0100 Subject: [PATCH 3/3] chore: change path --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d8d89bd..2436e79 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": "node --test **/*.test.js && npm run test:typescript", + "test": "node --test */*.test.js && npm run test:typescript", "test:typescript": "tsd" }, "repository": {