Skip to content

Commit 6c83cd3

Browse files
fix: should ensure can access all decorators from app built with helper.build (#742)
* fix: should ensure tests can access all decorators * refactor: use more appropriate name * refactor: revert template changes * fix: revert add default value to runFastify params * fix: revert add default value to runFastify params * fix: remove buildOptions
1 parent 04b0fae commit 6c83cd3

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ const assert = require('node:assert')
363363
test('test my application', async t => {
364364
const argv = ['app.js']
365365
const app = await build(argv, {
366-
extraParam: 'foo'
366+
extraParam: 'foo',
367+
skipOverride: true // If you want your application to be registered with fastify-plugin
367368
})
368369
t.after(() => app.close())
369370

helper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
enumerable: false,
1010
writable: false
1111
})
12+
1213
return runFastify(args, additionalOptions, serverOptions)
1314
},
1415
listen: runFastify

start.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const {
2121
showHelpForCommand,
2222
isKubernetes
2323
} = require('./util')
24+
const fp = require('fastify-plugin')
2425

2526
let Fastify = null
2627

@@ -170,7 +171,10 @@ async function runFastify (args, additionalOptions, serverOptions) {
170171
}
171172

172173
const appConfig = Object.assign({}, opts.options ? file.options : {}, opts.pluginOptions, additionalOptions)
173-
await fastify.register(file.default || file, appConfig)
174+
175+
const appFn = file.default || file
176+
const appPlugin = appConfig.skipOverride ? fp(appFn) : appFn
177+
await fastify.register(appPlugin, appConfig)
174178

175179
const closeListeners = closeWithGrace({ delay: opts.closeGraceDelay }, async function ({ signal, err, manual }) {
176180
if (err) {

test/helper.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,14 @@ test('should merge the CLI and FILE configs', async t => {
150150
t.same(lines.length, 1)
151151
t.same(lines[0].foo, '***')
152152
})
153+
154+
test('should ensure can access all decorators', async t => {
155+
const argv = ['./examples/plugin.js']
156+
const app = await helper.build(argv, { skipOverride: true })
157+
t.teardown(() => app.close())
158+
t.ok(app.test)
159+
160+
const app2 = await helper.listen(argv, { skipOverride: true })
161+
t.teardown(() => app2.close())
162+
t.ok(app2.test)
163+
})

0 commit comments

Comments
 (0)