From 70ff46cc4f16915637c84dfdd81a96cde5f99696 Mon Sep 17 00:00:00 2001 From: lependu Date: Sun, 14 Jan 2018 15:12:59 +0100 Subject: [PATCH] Updates fastify, plugin-meta --- package.json | 6 +++--- plugin.js | 5 ++++- test/cache.test.js | 24 +++++++++--------------- test/headers.test.js | 24 ++++++------------------ 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index ff3e4ff..88962ee 100644 --- a/package.json +++ b/package.json @@ -29,15 +29,15 @@ }, "homepage": "https://github.com/fastify/fastify-caching#readme", "devDependencies": { - "fastify": "^0.35.2", + "fastify": "^0.39.1", "pre-commit": "^1.2.2", "snazzy": "^7.0.0", "standard": "^10.0.3", - "tap": "^10.7.3" + "tap": "^11.0.1" }, "dependencies": { "abstract-cache": "^1.0.0", - "fastify-plugin": "^0.1.1", + "fastify-plugin": "^0.2.1", "uid-safe": "^2.1.5" } } diff --git a/plugin.js b/plugin.js index ec7da5e..9a0e340 100644 --- a/plugin.js +++ b/plugin.js @@ -83,7 +83,10 @@ function fastifyCachingPlugin (instance, options, next) { next() } -module.exports = fp(fastifyCachingPlugin, '>=0.33.0') +module.exports = fp(fastifyCachingPlugin, { + fastify: '>=0.39.1', + name: 'fastify-caching' +}) module.exports.privacy = { NOCACHE: 'no-cache', diff --git a/test/cache.test.js b/test/cache.test.js index bea0489..cc1d873 100644 --- a/test/cache.test.js +++ b/test/cache.test.js @@ -9,20 +9,18 @@ const fastify = require('fastify') test('cache property gets added to instance', (t) => { t.plan(2) const instance = fastify() - instance.register(plugin, (err) => { - if (err) t.threw(err) - - t.ok(instance.cache) - t.ok(instance.cache.set) - }) + instance + .register(plugin) + .ready(() => { + t.ok(instance.cache) + t.ok(instance.cache.set) + }) }) test('cache is usable', (t) => { t.plan(1) const instance = fastify() - instance.register(plugin, (err) => { - if (err) t.threw(err) - }) + instance.register(plugin) instance.get('/one', (req, reply) => { instance.cache.set('one', {one: true}, 100, (err) => { @@ -57,9 +55,7 @@ test('cache is usable', (t) => { test('etags get stored in cache', (t) => { t.plan(1) const instance = fastify() - instance.register(plugin, (err) => { - if (err) t.threw(err) - }) + instance.register(plugin) instance.get('/one', (req, reply) => { reply @@ -95,9 +91,7 @@ test('etags get stored in cache', (t) => { test('etag cache life is customizable', (t) => { t.plan(1) const instance = fastify() - instance.register(plugin, (err) => { - if (err) t.threw(err) - }) + instance.register(plugin) instance.get('/one', function (req, reply) { reply diff --git a/test/headers.test.js b/test/headers.test.js index 0dd4c54..378ac95 100644 --- a/test/headers.test.js +++ b/test/headers.test.js @@ -8,9 +8,7 @@ const fastify = require('fastify') test('decorators get added', (t) => { t.plan(1) const instance = fastify() - instance.register(plugin, (err) => { - if (err) t.threw(err) - }) + instance.register(plugin) instance.get('/', (req, reply) => { t.ok(reply.etag) reply.send() @@ -28,9 +26,7 @@ test('decorators add headers', (t) => { t.plan(2) const tag = '123456' const instance = fastify() - instance.register(plugin, (err) => { - if (err) t.threw(err) - }) + instance.register(plugin) instance.get('/', (req, reply) => { reply .etag(tag) @@ -51,9 +47,7 @@ test('decorators add headers', (t) => { test('sets no-cache header', (t) => { t.plan(2) const instance = fastify() - instance.register(plugin, {privacy: plugin.privacy.NOCACHE}, (err) => { - if (err) t.threw(err) - }) + instance.register(plugin, {privacy: plugin.privacy.NOCACHE}) instance.get('/', (req, reply) => { reply.send({hello: 'world'}) }) @@ -77,9 +71,7 @@ test('sets private with max-age header', (t) => { privacy: plugin.privacy.PRIVATE, expiresIn: 300 } - instance.register(plugin, opts, (err) => { - if (err) t.threw(err) - }) + instance.register(plugin, opts) instance.get('/', (req, reply) => { reply.send({hello: 'world'}) }) @@ -99,9 +91,7 @@ test('sets private with max-age header', (t) => { test('sets no-store with max-age header', (t) => { t.plan(2) const instance = fastify() - instance.register(plugin, {privacy: 'no-store', expiresIn: 300}, (err) => { - if (err) t.threw(err) - }) + instance.register(plugin, {privacy: 'no-store', expiresIn: 300}) instance.get('/', (req, reply) => { reply.send({hello: 'world'}) }) @@ -122,9 +112,7 @@ test('sets the expires header', (t) => { t.plan(2) const now = new Date() const instance = fastify() - instance.register(plugin, {privacy: plugin.privacy.NOCACHE}, (err) => { - if (err) t.threw(err) - }) + instance.register(plugin, {privacy: plugin.privacy.NOCACHE}) instance.get('/', (req, reply) => { reply .expires(now)