Skip to content

Commit

Permalink
fix: should ensure can access all decorators from app built with `hel…
Browse files Browse the repository at this point in the history
…per.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
  • Loading branch information
jean-michelet authored Jul 25, 2024
1 parent 04b0fae commit 6c83cd3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ const assert = require('node:assert')
test('test my application', async t => {
const argv = ['app.js']
const app = await build(argv, {
extraParam: 'foo'
extraParam: 'foo',
skipOverride: true // If you want your application to be registered with fastify-plugin
})
t.after(() => app.close())

Expand Down
1 change: 1 addition & 0 deletions helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
enumerable: false,
writable: false
})

return runFastify(args, additionalOptions, serverOptions)
},
listen: runFastify
Expand Down
6 changes: 5 additions & 1 deletion start.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
showHelpForCommand,
isKubernetes
} = require('./util')
const fp = require('fastify-plugin')

let Fastify = null

Expand Down Expand Up @@ -170,7 +171,10 @@ async function runFastify (args, additionalOptions, serverOptions) {
}

const appConfig = Object.assign({}, opts.options ? file.options : {}, opts.pluginOptions, additionalOptions)
await fastify.register(file.default || file, appConfig)

const appFn = file.default || file
const appPlugin = appConfig.skipOverride ? fp(appFn) : appFn
await fastify.register(appPlugin, appConfig)

const closeListeners = closeWithGrace({ delay: opts.closeGraceDelay }, async function ({ signal, err, manual }) {
if (err) {
Expand Down
11 changes: 11 additions & 0 deletions test/helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,14 @@ test('should merge the CLI and FILE configs', async t => {
t.same(lines.length, 1)
t.same(lines[0].foo, '***')
})

test('should ensure can access all decorators', async t => {
const argv = ['./examples/plugin.js']
const app = await helper.build(argv, { skipOverride: true })
t.teardown(() => app.close())
t.ok(app.test)

const app2 = await helper.listen(argv, { skipOverride: true })
t.teardown(() => app2.close())
t.ok(app2.test)
})

0 comments on commit 6c83cd3

Please sign in to comment.