fastify-plugin
Advanced tools
Comparing version 1.6.0 to 1.6.1
12
index.js
@@ -18,4 +18,6 @@ 'use strict' | ||
const pluginName = (options && options.name) || checkName(fn) | ||
if (typeof options === 'string') { | ||
checkVersion(options) | ||
checkVersion(options, pluginName) | ||
options = {} | ||
@@ -29,3 +31,3 @@ } | ||
if (!options.name) { | ||
options.name = checkName(fn) | ||
options.name = pluginName | ||
} | ||
@@ -36,3 +38,3 @@ | ||
if (options.fastify) { | ||
checkVersion(options.fastify) | ||
checkVersion(options.fastify, pluginName) | ||
} | ||
@@ -55,3 +57,3 @@ | ||
function checkVersion (version) { | ||
function checkVersion (version, pluginName) { | ||
if (typeof version !== 'string') { | ||
@@ -69,3 +71,3 @@ throw new TypeError(`fastify-plugin expects a version string, instead got '${typeof version}'`) | ||
if (fastifyVersion && !semver.satisfies(fastifyVersion, version)) { | ||
throw new Error(`fastify-plugin - expected '${version}' fastify version, '${fastifyVersion}' is installed`) | ||
throw new Error(`fastify-plugin: ${pluginName} - expected '${version}' fastify version, '${fastifyVersion}' is installed`) | ||
} | ||
@@ -72,0 +74,0 @@ } |
{ | ||
"name": "fastify-plugin", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "Plugin helper for Fastify", | ||
@@ -27,11 +27,11 @@ "main": "index.js", | ||
"devDependencies": { | ||
"fastify": "^2.0.0", | ||
"proxyquire": "^2.1.0", | ||
"standard": "^12.0.1", | ||
"@types/node": "^11.15.7", | ||
"fastify": "^2.12.0", | ||
"proxyquire": "^2.1.3", | ||
"standard": "^14.0.0", | ||
"tap": "^12.6.5", | ||
"typescript": "^3.3.3", | ||
"@types/node": "^11.9.3" | ||
"typescript": "^3.8.2" | ||
}, | ||
"dependencies": { | ||
"semver": "^6.0.0" | ||
"semver": "^6.3.0" | ||
}, | ||
@@ -38,0 +38,0 @@ "greenkeeper": { |
@@ -42,3 +42,3 @@ 'use strict' | ||
const anonymousStack = `Unable to parse this` | ||
const anonymousStack = 'Unable to parse this' | ||
@@ -45,0 +45,0 @@ t.plan(3) |
@@ -111,3 +111,3 @@ 'use strict' | ||
} catch (e) { | ||
t.is(e.message, `fastify-plugin - expected '1000.1000.1000' fastify version, '${v}' is installed`) | ||
t.is(e.message, `fastify-plugin: plugin - expected '1000.1000.1000' fastify version, '${v}' is installed`) | ||
} | ||
@@ -186,6 +186,22 @@ }) | ||
} catch (e) { | ||
t.is(e.message, `fastify-plugin - expected '1000.1000.1000' fastify version, '${v}' is installed`) | ||
t.is(e.message, `fastify-plugin: plugin - expected '1000.1000.1000' fastify version, '${v}' is installed`) | ||
} | ||
}) | ||
test('should throw if the fastify version does not satisfies the plugin requested version - plugin name', t => { | ||
t.plan(1) | ||
function plugin (fastify, opts, next) { | ||
next() | ||
} | ||
const v = require('fastify/package.json').version.replace(/-rc\.\d+/, '') | ||
try { | ||
fp(plugin, { name: 'this-is-an-awesome-name', fastify: '1000.1000.1000' }) | ||
t.fail() | ||
} catch (e) { | ||
t.is(e.message, `fastify-plugin: this-is-an-awesome-name - expected '1000.1000.1000' fastify version, '${v}' is installed`) | ||
} | ||
}) | ||
test('should set anonymous function name to file it was called from', t => { | ||
@@ -241,3 +257,3 @@ t.plan(2) | ||
fastify.ready(err => { | ||
t.is(err.message, `The dependency 'plugin2-name' of plugin 'test' is not registered`) | ||
t.is(err.message, "The dependency 'plugin2-name' of plugin 'test' is not registered") | ||
}) | ||
@@ -262,3 +278,3 @@ }) | ||
fastify.ready(err => { | ||
t.is(err.message, `The decorator 'plugin2' is not present in Fastify`) | ||
t.is(err.message, "The decorator 'plugin2' is not present in Fastify") | ||
}) | ||
@@ -283,4 +299,4 @@ }) | ||
fastify.ready(err => { | ||
t.is(err.message, `The decorator 'plugin2' is not present in Reply`) | ||
t.is(err.message, "The decorator 'plugin2' is not present in Reply") | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20458
437
Updatedsemver@^6.3.0