Socket
Socket
Sign inDemoInstall

fastify-plugin

Package Overview
Dependencies
1
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.5.0

2

fastify-plugin.d.ts

@@ -15,3 +15,3 @@ /// <reference types="fastify" />

declare function fastifyPlugin<HttpServer, HttpRequest, HttpResponse, T>(
fn: fastify.Plugin<HttpServer, HttpRequest, HttpResponse, T>,
fn: fastify.Plugin<HttpServer, HttpRequest, HttpResponse, T> | { default: fastify.Plugin<HttpServer, HttpRequest, HttpResponse, T> },
options?: fastifyPlugin.PluginOptions | string,

@@ -18,0 +18,0 @@ next?: fastifyPlugin.nextCallback

@@ -8,2 +8,6 @@ 'use strict'

function plugin (fn, options = {}) {
if (typeof fn.default !== 'undefined') { // Support for 'export default' behaviour in transpiled ECMAScript module
fn = fn.default
}
if (typeof fn !== 'function') {

@@ -10,0 +14,0 @@ throw new TypeError(`fastify-plugin expects a function, instead got a '${typeof fn}'`)

{
"name": "fastify-plugin",
"version": "1.4.0",
"version": "1.5.0",
"description": "Plugin helper for Fastify",

@@ -27,7 +27,7 @@ "main": "index.js",

"devDependencies": {
"@types/node": "^9.6.22",
"fastify": "^1.13.0",
"@types/node": "^9.6.41",
"fastify": "^1.14.1",
"proxyquire": "^2.0.1",
"standard": "^12.0.0",
"tap": "^12.0.0",
"tap": "^12.5.1",
"ts-node": "^7.0.0",

@@ -34,0 +34,0 @@ "typescript": "^2.9.2"

@@ -7,2 +7,3 @@ 'use strict'

const fp = require('./../')
const Fastify = require('fastify')

@@ -25,2 +26,17 @@ test('fastify-plugin is a function', t => {

test('should support "default" function from babel module', t => {
t.plan(1)
const plugin = {
default: () => {}
}
try {
fp(plugin)
t.pass()
} catch (e) {
t.is(e.message, 'fastify-plugin expects a function, instead got a \'object\'')
}
})
test('should throw if the plugin is not a function', t => {

@@ -208,1 +224,61 @@ t.plan(1)

})
test('should check fastify dependency graph - plugin', t => {
t.plan(1)
const fastify = Fastify()
fastify.register(fp((fastify, opts, next) => next(), {
fastify: '1.x',
name: 'plugin1-name'
}))
fastify.register(fp((fastify, opts, next) => next(), {
fastify: '1.x',
name: 'test',
dependencies: ['plugin1-name', 'plugin2-name']
}))
fastify.ready(err => {
t.is(err.message, `The dependency 'plugin2-name' is not registered`)
})
})
test('should check fastify dependency graph - decorate', t => {
t.plan(1)
const fastify = Fastify()
fastify.decorate('plugin1', fp((fastify, opts, next) => next(), {
fastify: '1.x',
name: 'plugin1-name'
}))
fastify.register(fp((fastify, opts, next) => next(), {
fastify: '1.x',
name: 'test',
decorators: { fastify: ['plugin1', 'plugin2'] }
}))
fastify.ready(err => {
t.is(err.message, `The decorator 'plugin2' is not present in Fastify`)
})
})
test('should check fastify dependency graph - decorateReply', t => {
t.plan(1)
const fastify = Fastify()
fastify.decorateReply('plugin1', fp((fastify, opts, next) => next(), {
fastify: '1.x',
name: 'plugin1-name'
}))
fastify.register(fp((fastify, opts, next) => next(), {
fastify: '1.x',
name: 'test',
decorators: { reply: ['plugin1', 'plugin2'] }
}))
fastify.ready(err => {
t.is(err.message, `The decorator 'plugin2' is not present in Reply`)
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc