Skip to content

Commit

Permalink
Add tests for dependency graph checking (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
cemremengu authored and mcollina committed Jan 16, 2019
1 parent 279fc07 commit 31708bb
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/test.js
Expand Up @@ -4,6 +4,7 @@ const t = require('tap')
const proxyquire = require('proxyquire')
const test = t.test
const fp = require('./../')
const Fastify = require('fastify')

test('fastify-plugin is a function', t => {
t.plan(1)
Expand Down Expand Up @@ -203,3 +204,63 @@ test('should preserve fastify version in meta', t => {

t.is(fn[Symbol.for('plugin-meta')].fastify, '>=0.10.0')
})

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`)
})
})

0 comments on commit 31708bb

Please sign in to comment.