diff --git a/lib/utils.js b/lib/utils.js index b42473b..8eb83cf 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -135,4 +135,5 @@ function handleRoutes (value, opts) { if (opts.hideEmpty && value.length === 0) { return undefined } + return value } diff --git a/package.json b/package.json index 55bc136..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 && 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 5bc2166..ca3732b 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) @@ -309,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, []) })