Projektstart
This commit is contained in:
120
backend/node_modules/fastify-plugin/test/bundlers.test.js
generated
vendored
Normal file
120
backend/node_modules/fastify-plugin/test/bundlers.test.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
const fp = require('../plugin')
|
||||
|
||||
test('webpack removes require.main.filename', (t) => {
|
||||
const filename = require.main.filename
|
||||
const info = console.info
|
||||
t.teardown(() => {
|
||||
require.main.filename = filename
|
||||
console.info = info
|
||||
})
|
||||
|
||||
require.main.filename = null
|
||||
|
||||
console.info = function (msg) {
|
||||
t.fail('logged: ' + msg)
|
||||
}
|
||||
|
||||
fp((fastify, opts, next) => {
|
||||
next()
|
||||
}, {
|
||||
fastify: '^4.0.0'
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('support faux modules', (t) => {
|
||||
const plugin = fp((fastify, opts, next) => {
|
||||
next()
|
||||
})
|
||||
|
||||
t.equal(plugin.default, plugin)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('support faux modules does not override existing default field in babel module', (t) => {
|
||||
const module = {
|
||||
default: (fastify, opts, next) => next()
|
||||
}
|
||||
|
||||
module.default.default = 'Existing default field'
|
||||
|
||||
const plugin = fp(module)
|
||||
|
||||
t.equal(plugin.default, 'Existing default field')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('support ts named imports', (t) => {
|
||||
const plugin = fp((fastify, opts, next) => {
|
||||
next()
|
||||
}, {
|
||||
name: 'hello'
|
||||
})
|
||||
|
||||
t.equal(plugin.hello, plugin)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('from kebab-case to camelCase', (t) => {
|
||||
const plugin = fp((fastify, opts, next) => {
|
||||
next()
|
||||
}, {
|
||||
name: 'hello-world'
|
||||
})
|
||||
|
||||
t.equal(plugin.helloWorld, plugin)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('from @-prefixed named imports', (t) => {
|
||||
const plugin = fp((fastify, opts, next) => {
|
||||
next()
|
||||
}, {
|
||||
name: '@hello/world'
|
||||
})
|
||||
|
||||
t.equal(plugin.helloWorld, plugin)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('from @-prefixed named kebab-case to camelCase', (t) => {
|
||||
const plugin = fp((fastify, opts, next) => {
|
||||
next()
|
||||
}, {
|
||||
name: '@hello/my-world'
|
||||
})
|
||||
|
||||
t.equal(plugin.helloMyWorld, plugin)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('from kebab-case to camelCase multiple words', (t) => {
|
||||
const plugin = fp((fastify, opts, next) => {
|
||||
next()
|
||||
}, {
|
||||
name: 'hello-long-world'
|
||||
})
|
||||
|
||||
t.equal(plugin.helloLongWorld, plugin)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('from kebab-case to camelCase multiple words does not override', (t) => {
|
||||
const fn = (fastify, opts, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
const foobar = {}
|
||||
fn.helloLongWorld = foobar
|
||||
|
||||
const plugin = fp(fn, {
|
||||
name: 'hello-long-world'
|
||||
})
|
||||
|
||||
t.equal(plugin.helloLongWorld, foobar)
|
||||
t.end()
|
||||
})
|
||||
73
backend/node_modules/fastify-plugin/test/checkVersion.test.js
generated
vendored
Normal file
73
backend/node_modules/fastify-plugin/test/checkVersion.test.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
const fp = require('../plugin')
|
||||
|
||||
test('checkVersion having require.main.filename', (t) => {
|
||||
const info = console.info
|
||||
t.ok(require.main.filename)
|
||||
t.teardown(() => {
|
||||
console.info = info
|
||||
})
|
||||
|
||||
console.info = function (msg) {
|
||||
t.fail('logged: ' + msg)
|
||||
}
|
||||
|
||||
fp((fastify, opts, next) => {
|
||||
next()
|
||||
}, {
|
||||
fastify: '^4.0.0'
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('checkVersion having no require.main.filename but process.argv[1]', (t) => {
|
||||
const filename = require.main.filename
|
||||
const info = console.info
|
||||
t.teardown(() => {
|
||||
require.main.filename = filename
|
||||
console.info = info
|
||||
})
|
||||
|
||||
require.main.filename = null
|
||||
|
||||
console.info = function (msg) {
|
||||
t.fail('logged: ' + msg)
|
||||
}
|
||||
|
||||
fp((fastify, opts, next) => {
|
||||
next()
|
||||
}, {
|
||||
fastify: '^4.0.0'
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('checkVersion having no require.main.filename and no process.argv[1]', (t) => {
|
||||
const filename = require.main.filename
|
||||
const argv = process.argv
|
||||
const info = console.info
|
||||
t.teardown(() => {
|
||||
require.main.filename = filename
|
||||
process.argv = argv
|
||||
console.info = info
|
||||
})
|
||||
|
||||
require.main.filename = null
|
||||
process.argv[1] = null
|
||||
|
||||
console.info = function (msg) {
|
||||
t.fail('logged: ' + msg)
|
||||
}
|
||||
|
||||
fp((fastify, opts, next) => {
|
||||
next()
|
||||
}, {
|
||||
fastify: '^4.0.0'
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
16
backend/node_modules/fastify-plugin/test/composite.test.js
generated
vendored
Normal file
16
backend/node_modules/fastify-plugin/test/composite.test.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const fp = require('../plugin')
|
||||
|
||||
test('anonymous function should be named composite.test0', t => {
|
||||
t.plan(2)
|
||||
|
||||
const fn = fp((fastify, opts, next) => {
|
||||
next()
|
||||
})
|
||||
|
||||
t.equal(fn[Symbol.for('plugin-meta')].name, 'composite.test-auto-0')
|
||||
t.equal(fn[Symbol.for('fastify.display-name')], 'composite.test-auto-0')
|
||||
})
|
||||
13
backend/node_modules/fastify-plugin/test/esm/esm.mjs
generated
vendored
Normal file
13
backend/node_modules/fastify-plugin/test/esm/esm.mjs
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import t from 'tap'
|
||||
|
||||
import fp from '../../plugin.js'
|
||||
|
||||
t.test('esm base support', async t => {
|
||||
fp((fastify, opts, next) => {
|
||||
next()
|
||||
}, {
|
||||
fastify: '^3.0.0'
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
11
backend/node_modules/fastify-plugin/test/esm/index.test.js
generated
vendored
Normal file
11
backend/node_modules/fastify-plugin/test/esm/index.test.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
'use strict'
|
||||
|
||||
// Node v8 throw a `SyntaxError: Unexpected token import`
|
||||
// even if this branch is never touch in the code,
|
||||
// by using `eval` we can avoid this issue.
|
||||
// eslint-disable-next-line
|
||||
new Function('module', 'return import(module)')('./esm.mjs').catch((err) => {
|
||||
process.nextTick(() => {
|
||||
throw err
|
||||
})
|
||||
})
|
||||
48
backend/node_modules/fastify-plugin/test/extractPluginName.test.js
generated
vendored
Normal file
48
backend/node_modules/fastify-plugin/test/extractPluginName.test.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const extractPluginName = require('../lib/getPluginName').extractPluginName
|
||||
|
||||
const winStack = `Error: anonymous function
|
||||
at checkName (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\index.js:43:11)
|
||||
at plugin (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\index.js:24:20)
|
||||
at Test.test (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\test\\hello.test.js:9:14)
|
||||
at bound (domain.js:396:14)
|
||||
at Test.runBound (domain.js:409:12)
|
||||
at ret (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:278:21)
|
||||
at Test.main (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:282:7)
|
||||
at writeSubComment (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:371:13)
|
||||
at TAP.writeSubComment (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:403:5)
|
||||
at Test.runBeforeEach (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:370:14)
|
||||
at loop (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\function-loop\\index.js:35:15)
|
||||
at TAP.runBeforeEach (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:683:7)
|
||||
at TAP.processSubtest (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:369:12)
|
||||
at TAP.process (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:306:14)
|
||||
at TAP.sub (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:185:10)
|
||||
at TAP.test (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:209:17)`
|
||||
|
||||
const nixStack = `Error: anonymous function
|
||||
at checkName (/home/leonardo/desktop/fastify-plugin/index.js:43:11)
|
||||
at plugin (/home/leonardo/desktop/fastify-plugin/index.js:24:20)
|
||||
at Test.test (/home/leonardo/desktop/fastify-plugin/test/this.is.a.test.js:9:14)
|
||||
at bound (domain.js:396:14)
|
||||
at Test.runBound (domain.js:409:12)
|
||||
at ret (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:278:21)
|
||||
at Test.main (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:282:7)
|
||||
at writeSubComment (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:371:13)
|
||||
at TAP.writeSubComment (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:403:5)
|
||||
at Test.runBeforeEach (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:370:14)
|
||||
at loop (/home/leonardo/desktop/fastify-plugin/node_modules/function-loop/index.js:35:15)
|
||||
at TAP.runBeforeEach (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:683:7)
|
||||
at TAP.processSubtest (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:369:12)
|
||||
at TAP.process (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:306:14)
|
||||
at TAP.sub (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:185:10)
|
||||
at TAP.test (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:209:17)`
|
||||
|
||||
const anonymousStack = 'Unable to parse this'
|
||||
|
||||
t.plan(3)
|
||||
|
||||
t.equal(extractPluginName(winStack), 'hello.test')
|
||||
t.equal(extractPluginName(nixStack), 'this.is.a.test')
|
||||
t.equal(extractPluginName(anonymousStack), 'anonymous')
|
||||
16
backend/node_modules/fastify-plugin/test/mu1tip1e.composite.test.js
generated
vendored
Normal file
16
backend/node_modules/fastify-plugin/test/mu1tip1e.composite.test.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const fp = require('../plugin')
|
||||
|
||||
test('anonymous function should be named mu1tip1e.composite.test', t => {
|
||||
t.plan(2)
|
||||
|
||||
const fn = fp((fastify, opts, next) => {
|
||||
next()
|
||||
})
|
||||
|
||||
t.equal(fn[Symbol.for('plugin-meta')].name, 'mu1tip1e.composite.test-auto-0')
|
||||
t.equal(fn[Symbol.for('fastify.display-name')], 'mu1tip1e.composite.test-auto-0')
|
||||
})
|
||||
404
backend/node_modules/fastify-plugin/test/test.js
generated
vendored
Normal file
404
backend/node_modules/fastify-plugin/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,404 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const proxyquire = require('proxyquire')
|
||||
const test = t.test
|
||||
const fp = require('../plugin')
|
||||
const Fastify = require('fastify')
|
||||
|
||||
test('fastify-plugin is a function', t => {
|
||||
t.plan(1)
|
||||
t.type(fp, 'function')
|
||||
})
|
||||
|
||||
test('should return the function with the skip-override Symbol', t => {
|
||||
t.plan(1)
|
||||
|
||||
function plugin (fastify, opts, next) {
|
||||
next()
|
||||
}
|
||||
|
||||
fp(plugin)
|
||||
t.ok(plugin[Symbol.for('skip-override')])
|
||||
})
|
||||
|
||||
test('should support "default" function from babel module', t => {
|
||||
t.plan(1)
|
||||
|
||||
const plugin = {
|
||||
default: () => { }
|
||||
}
|
||||
|
||||
try {
|
||||
fp(plugin)
|
||||
t.pass()
|
||||
} catch (e) {
|
||||
t.equal(e.message, 'fastify-plugin expects a function, instead got a \'object\'')
|
||||
}
|
||||
})
|
||||
|
||||
test('should throw if the plugin is not a function', t => {
|
||||
t.plan(1)
|
||||
|
||||
try {
|
||||
fp('plugin')
|
||||
t.fail()
|
||||
} catch (e) {
|
||||
t.equal(e.message, 'fastify-plugin expects a function, instead got a \'string\'')
|
||||
}
|
||||
})
|
||||
|
||||
test('should check the fastify version', t => {
|
||||
t.plan(1)
|
||||
|
||||
function plugin (fastify, opts, next) {
|
||||
next()
|
||||
}
|
||||
|
||||
try {
|
||||
fp(plugin, { fastify: '>=0.10.0' })
|
||||
t.pass()
|
||||
} catch (e) {
|
||||
t.fail()
|
||||
}
|
||||
})
|
||||
|
||||
test('should check the fastify version', t => {
|
||||
t.plan(1)
|
||||
|
||||
function plugin (fastify, opts, next) {
|
||||
next()
|
||||
}
|
||||
|
||||
try {
|
||||
fp(plugin, '>=0.10.0')
|
||||
t.pass()
|
||||
} catch (e) {
|
||||
t.fail()
|
||||
}
|
||||
})
|
||||
|
||||
test('the options object should be an object', t => {
|
||||
t.plan(2)
|
||||
|
||||
try {
|
||||
fp(() => { }, null)
|
||||
t.fail()
|
||||
} catch (e) {
|
||||
t.equal(e.message, 'The options object should be an object')
|
||||
}
|
||||
|
||||
try {
|
||||
fp(() => { }, [])
|
||||
t.fail()
|
||||
} catch (e) {
|
||||
t.equal(e.message, 'The options object should be an object')
|
||||
}
|
||||
})
|
||||
|
||||
test('should throw if the version number is not a string', t => {
|
||||
t.plan(1)
|
||||
|
||||
try {
|
||||
fp(() => { }, { fastify: 12 })
|
||||
t.fail()
|
||||
} catch (e) {
|
||||
t.equal(e.message, 'fastify-plugin expects a version string, instead got \'number\'')
|
||||
}
|
||||
})
|
||||
|
||||
test('Should accept an option object', t => {
|
||||
t.plan(2)
|
||||
|
||||
const opts = { hello: 'world' }
|
||||
|
||||
function plugin (fastify, opts, next) {
|
||||
next()
|
||||
}
|
||||
|
||||
fp(plugin, opts)
|
||||
t.ok(plugin[Symbol.for('skip-override')])
|
||||
t.same(plugin[Symbol.for('plugin-meta')], opts)
|
||||
})
|
||||
|
||||
test('Should accept an option object and checks the version', t => {
|
||||
t.plan(2)
|
||||
|
||||
const opts = { hello: 'world', fastify: '>=0.10.0' }
|
||||
|
||||
function plugin (fastify, opts, next) {
|
||||
next()
|
||||
}
|
||||
|
||||
fp(plugin, opts)
|
||||
t.ok(plugin[Symbol.for('skip-override')])
|
||||
t.same(plugin[Symbol.for('plugin-meta')], opts)
|
||||
})
|
||||
|
||||
test('should set anonymous function name to file it was called from with a counter', t => {
|
||||
const fp = proxyquire('../plugin.js', { stubs: {} })
|
||||
|
||||
const fn = fp((fastify, opts, next) => {
|
||||
next()
|
||||
})
|
||||
|
||||
t.equal(fn[Symbol.for('plugin-meta')].name, 'test-auto-0')
|
||||
t.equal(fn[Symbol.for('fastify.display-name')], 'test-auto-0')
|
||||
|
||||
const fn2 = fp((fastify, opts, next) => {
|
||||
next()
|
||||
})
|
||||
|
||||
t.equal(fn2[Symbol.for('plugin-meta')].name, 'test-auto-1')
|
||||
t.equal(fn2[Symbol.for('fastify.display-name')], 'test-auto-1')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should set function name if Error.stackTraceLimit is set to 0', t => {
|
||||
const stackTraceLimit = Error.stackTraceLimit = 0
|
||||
|
||||
const fp = proxyquire('../plugin.js', { stubs: {} })
|
||||
|
||||
const fn = fp((fastify, opts, next) => {
|
||||
next()
|
||||
})
|
||||
|
||||
t.equal(fn[Symbol.for('plugin-meta')].name, 'test-auto-0')
|
||||
t.equal(fn[Symbol.for('fastify.display-name')], 'test-auto-0')
|
||||
|
||||
const fn2 = fp((fastify, opts, next) => {
|
||||
next()
|
||||
})
|
||||
|
||||
t.equal(fn2[Symbol.for('plugin-meta')].name, 'test-auto-1')
|
||||
t.equal(fn2[Symbol.for('fastify.display-name')], 'test-auto-1')
|
||||
|
||||
Error.stackTraceLimit = stackTraceLimit
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should set display-name to meta name', t => {
|
||||
t.plan(2)
|
||||
|
||||
const functionName = 'superDuperSpecialFunction'
|
||||
|
||||
const fn = fp((fastify, opts, next) => next(), {
|
||||
name: functionName
|
||||
})
|
||||
|
||||
t.equal(fn[Symbol.for('plugin-meta')].name, functionName)
|
||||
t.equal(fn[Symbol.for('fastify.display-name')], functionName)
|
||||
})
|
||||
|
||||
test('should preserve fastify version in meta', t => {
|
||||
t.plan(1)
|
||||
|
||||
const opts = { hello: 'world', fastify: '>=0.10.0' }
|
||||
|
||||
const fn = fp((fastify, opts, next) => next(), opts)
|
||||
|
||||
t.equal(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: '4.x',
|
||||
name: 'plugin1-name'
|
||||
}))
|
||||
|
||||
fastify.register(fp((fastify, opts, next) => next(), {
|
||||
fastify: '4.x',
|
||||
name: 'test',
|
||||
dependencies: ['plugin1-name', 'plugin2-name']
|
||||
}))
|
||||
|
||||
fastify.ready(err => {
|
||||
t.equal(err.message, "The dependency 'plugin2-name' of plugin 'test' 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: '4.x',
|
||||
name: 'plugin1-name'
|
||||
}))
|
||||
|
||||
fastify.register(fp((fastify, opts, next) => next(), {
|
||||
fastify: '4.x',
|
||||
name: 'test',
|
||||
decorators: { fastify: ['plugin1', 'plugin2'] }
|
||||
}))
|
||||
|
||||
fastify.ready(err => {
|
||||
t.equal(err.message, "The decorator 'plugin2' required by 'test' 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: '4.x',
|
||||
name: 'plugin1-name'
|
||||
}))
|
||||
|
||||
fastify.register(fp((fastify, opts, next) => next(), {
|
||||
fastify: '4.x',
|
||||
name: 'test',
|
||||
decorators: { reply: ['plugin1', 'plugin2'] }
|
||||
}))
|
||||
|
||||
fastify.ready(err => {
|
||||
t.equal(err.message, "The decorator 'plugin2' required by 'test' is not present in Reply")
|
||||
})
|
||||
})
|
||||
|
||||
test('should accept an option to encapsulate', t => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.register(fp((fastify, opts, next) => {
|
||||
fastify.decorate('accessible', true)
|
||||
next()
|
||||
}, {
|
||||
name: 'accessible-plugin'
|
||||
}))
|
||||
|
||||
fastify.register(fp((fastify, opts, next) => {
|
||||
fastify.decorate('alsoAccessible', true)
|
||||
next()
|
||||
}, {
|
||||
name: 'accessible-plugin2',
|
||||
encapsulate: false
|
||||
}))
|
||||
|
||||
fastify.register(fp((fastify, opts, next) => {
|
||||
fastify.decorate('encapsulated', true)
|
||||
next()
|
||||
}, {
|
||||
name: 'encapsulated-plugin',
|
||||
encapsulate: true
|
||||
}))
|
||||
|
||||
fastify.ready(err => {
|
||||
t.error(err)
|
||||
t.ok(fastify.hasDecorator('accessible'))
|
||||
t.ok(fastify.hasDecorator('alsoAccessible'))
|
||||
t.notOk(fastify.hasDecorator('encapsulated'))
|
||||
})
|
||||
})
|
||||
|
||||
test('should check dependencies when encapsulated', t => {
|
||||
t.plan(1)
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.register(fp((fastify, opts, next) => next(), {
|
||||
name: 'test',
|
||||
dependencies: ['missing-dependency-name'],
|
||||
encapsulate: true
|
||||
}))
|
||||
|
||||
fastify.ready(err => {
|
||||
t.equal(err.message, "The dependency 'missing-dependency-name' of plugin 'test' is not registered")
|
||||
})
|
||||
})
|
||||
|
||||
test('should check version when encapsulated', t => {
|
||||
t.plan(1)
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.register(fp((fastify, opts, next) => next(), {
|
||||
name: 'test',
|
||||
fastify: '<=2.10.0',
|
||||
encapsulate: true
|
||||
}))
|
||||
|
||||
fastify.ready(err => {
|
||||
t.match(err.message, /fastify-plugin: test - expected '<=2.10.0' fastify version, '\d.\d+.\d+' is installed/)
|
||||
})
|
||||
})
|
||||
|
||||
test('should check decorators when encapsulated', t => {
|
||||
t.plan(1)
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.decorate('plugin1', 'foo')
|
||||
|
||||
fastify.register(fp((fastify, opts, next) => next(), {
|
||||
fastify: '4.x',
|
||||
name: 'test',
|
||||
encapsulate: true,
|
||||
decorators: { fastify: ['plugin1', 'plugin2'] }
|
||||
}))
|
||||
|
||||
fastify.ready(err => {
|
||||
t.equal(err.message, "The decorator 'plugin2' required by 'test' is not present in Fastify")
|
||||
})
|
||||
})
|
||||
|
||||
test('plugin name when encapsulated', async t => {
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.register(function plugin (instance, opts, next) {
|
||||
next()
|
||||
})
|
||||
|
||||
fastify.register(fp(getFn('hello'), {
|
||||
fastify: '4.x',
|
||||
name: 'hello',
|
||||
encapsulate: true
|
||||
}))
|
||||
|
||||
fastify.register(function plugin (fastify, opts, next) {
|
||||
fastify.register(fp(getFn('deep'), {
|
||||
fastify: '4.x',
|
||||
name: 'deep',
|
||||
encapsulate: true
|
||||
}))
|
||||
|
||||
fastify.register(fp(function genericPlugin (fastify, opts, next) {
|
||||
t.equal(fastify.pluginName, 'deep-deep', 'should be deep-deep')
|
||||
|
||||
fastify.register(fp(getFn('deep-deep-deep'), {
|
||||
fastify: '4.x',
|
||||
name: 'deep-deep-deep',
|
||||
encapsulate: true
|
||||
}))
|
||||
|
||||
fastify.register(fp(getFn('deep-deep -> not-encapsulated-2'), {
|
||||
fastify: '4.x',
|
||||
name: 'not-encapsulated-2'
|
||||
}))
|
||||
|
||||
next()
|
||||
}, {
|
||||
fastify: '4.x',
|
||||
name: 'deep-deep',
|
||||
encapsulate: true
|
||||
}))
|
||||
|
||||
fastify.register(fp(getFn('plugin -> not-encapsulated'), {
|
||||
fastify: '4.x',
|
||||
name: 'not-encapsulated'
|
||||
}))
|
||||
|
||||
next()
|
||||
})
|
||||
|
||||
await fastify.ready()
|
||||
|
||||
function getFn (expectedName) {
|
||||
return function genericPlugin (fastify, opts, next) {
|
||||
t.equal(fastify.pluginName, expectedName, `should be ${expectedName}`)
|
||||
next()
|
||||
}
|
||||
}
|
||||
})
|
||||
24
backend/node_modules/fastify-plugin/test/toCamelCase.test.js
generated
vendored
Normal file
24
backend/node_modules/fastify-plugin/test/toCamelCase.test.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
const toCamelCase = require('../lib/toCamelCase')
|
||||
|
||||
test('from kebab-case to camelCase', (t) => {
|
||||
t.plan(1)
|
||||
t.equal(toCamelCase('hello-world'), 'helloWorld')
|
||||
})
|
||||
|
||||
test('from @-prefixed named imports', (t) => {
|
||||
t.plan(1)
|
||||
t.equal(toCamelCase('@hello/world'), 'helloWorld')
|
||||
})
|
||||
|
||||
test('from @-prefixed named kebab-case to camelCase', (t) => {
|
||||
t.plan(1)
|
||||
t.equal(toCamelCase('@hello/my-world'), 'helloMyWorld')
|
||||
})
|
||||
|
||||
test('from kebab-case to camelCase multiple words', (t) => {
|
||||
t.plan(1)
|
||||
t.equal(toCamelCase('hello-long-world'), 'helloLongWorld')
|
||||
})
|
||||
Reference in New Issue
Block a user