Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add name to plugin (#1) #199

Merged
merged 4 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ fastify.addHook('preHandler', function (request, reply, done) {
```
Properties from `reply.locals` will override those from `defaultContext`, but not from `data` parameter provided to `reply.view(template, data)` function.

To require `point-of-view` as a dependency to a [fastify-plugin](https://github.com/fastify/fastify-plugin), add the name `point-of-view` to the dependencies array in the [plugin's opts](https://github.com/fastify/fastify-plugin#dependencies).

```js
fastify.register(myViewRendererPlugin, {
dependencies: ['point-of-view']
})
```

<a name="note"></a>
## Note

Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,7 @@ function fastifyView (fastify, opts, next) {
}
}

module.exports = fp(fastifyView, { fastify: '>=3.x' })
module.exports = fp(fastifyView, {
fastify: '3.x',
name: 'point-of-view'
})
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,24 @@ test('register callback should throw if layout option provided with wrong engine
t.is(err.message, 'Only Handlebars, EJS, and Eta support the "layout" option')
})
})

test('plugin is registered with "point-of-view" name', t => {
t.plan(2)
const fastify = Fastify()

fastify.register(require('../index'), {
engine: {
ejs: require('ejs')
}
})

fastify.ready(err => {
t.error(err)

const kRegistedPlugins = Symbol.for('registered-plugin')
const registeredPlugins = fastify[kRegistedPlugins]
t.ok(registeredPlugins.find(name => name === 'point-of-view'))

fastify.close()
})
})