Projektstart

This commit is contained in:
2026-01-22 15:49:12 +01:00
parent 7212eb6f7a
commit 57e5f652f8
10637 changed files with 2598792 additions and 64 deletions

864
backend/node_modules/avvio/test/after-and-ready.test.js generated vendored Normal file
View File

@@ -0,0 +1,864 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('boot a plugin and then execute a call after that', (t) => {
t.plan(5)
const app = boot()
let pluginLoaded = false
let afterCalled = false
app.use(function (s, opts, done) {
t.notOk(afterCalled, 'after not called')
pluginLoaded = true
done()
})
app.after(function (err, cb) {
t.error(err)
t.ok(pluginLoaded, 'afterred!')
afterCalled = true
cb()
})
app.on('start', () => {
t.ok(afterCalled, 'after called')
t.ok(pluginLoaded, 'plugin loaded')
})
})
test('after without a done callback', (t) => {
t.plan(5)
const app = boot()
let pluginLoaded = false
let afterCalled = false
app.use(function (s, opts, done) {
t.notOk(afterCalled, 'after not called')
pluginLoaded = true
done()
})
app.after(function (err) {
t.error(err)
t.ok(pluginLoaded, 'afterred!')
afterCalled = true
})
app.on('start', () => {
t.ok(afterCalled, 'after called')
t.ok(pluginLoaded, 'plugin loaded')
})
})
test('verify when a afterred call happens', (t) => {
t.plan(3)
const app = boot()
app.use(function (s, opts, done) {
done()
})
app.after(function (err, cb) {
t.error(err)
t.pass('afterred finished')
cb()
})
app.on('start', () => {
t.pass('booted')
})
})
test('internal after', (t) => {
t.plan(18)
const app = boot()
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
let afterCalled = false
app.use(first)
app.use(third)
function first (s, opts, done) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
firstLoaded = true
s.use(second)
s.after(function (err, cb) {
t.error(err)
t.notOk(afterCalled, 'after was not called')
afterCalled = true
cb()
})
done()
}
function second (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(afterCalled, 'after was not called')
secondLoaded = true
done()
}
function third (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(afterCalled, 'after was called')
t.notOk(thirdLoaded, 'third is not loaded')
thirdLoaded = true
done()
}
app.on('start', () => {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(afterCalled, 'after was called')
t.pass('booted')
})
})
test('ready adds at the end of the queue', (t) => {
t.plan(14)
const app = boot()
let pluginLoaded = false
let afterCalled = false
let readyCalled = false
app.ready(function (err, cb) {
t.error(err)
t.ok(pluginLoaded, 'after the plugin')
t.ok(afterCalled, 'after after')
readyCalled = true
process.nextTick(cb)
})
app.use(function (s, opts, done) {
t.notOk(afterCalled, 'after not called')
t.notOk(readyCalled, 'ready not called')
pluginLoaded = true
app.ready(function (err) {
t.error(err)
t.ok(readyCalled, 'after the first ready')
t.ok(afterCalled, 'after the after callback')
})
done()
})
app.after(function (err, cb) {
t.error(err)
t.ok(pluginLoaded, 'executing after!')
t.notOk(readyCalled, 'ready not called')
afterCalled = true
cb()
})
app.on('start', () => {
t.ok(afterCalled, 'after called')
t.ok(pluginLoaded, 'plugin loaded')
t.ok(readyCalled, 'ready called')
})
})
test('if the after/ready callback has two parameters, the first one must be the context', (t) => {
t.plan(4)
const server = { my: 'server' }
const app = boot(server)
app.use(function (s, opts, done) {
done()
})
app.after(function (err, context, cb) {
t.error(err)
t.equal(server, context)
cb()
})
app.ready(function (err, context, cb) {
t.error(err)
t.equal(server, context)
cb()
})
})
test('if the after/ready async, the returns must be the context generated', (t) => {
t.plan(3)
const server = { my: 'server', index: 0 }
const app = boot(server)
app.override = function (old) {
return { ...old, index: old.index + 1 }
}
app.use(function (s, opts, done) {
s.use(function (s, opts, done) {
s.ready().then(itself => t.same(itself, s, 'deep deep'))
done()
})
s.ready().then(itself => t.same(itself, s, 'deep'))
done()
})
app.ready().then(itself => t.same(itself, server, 'outer'))
})
test('if the after/ready callback, the returns must be the context generated', (t) => {
t.plan(3)
const server = { my: 'server', index: 0 }
const app = boot(server)
app.override = function (old) {
return { ...old, index: old.index + 1 }
}
app.use(function (s, opts, done) {
s.use(function (s, opts, done) {
s.ready((_, itself, done) => {
t.same(itself, s, 'deep deep')
done()
})
done()
})
s.ready((_, itself, done) => {
t.same(itself, s, 'deep')
done()
})
done()
})
app.ready((_, itself, done) => {
t.same(itself, server, 'outer')
done()
})
})
test('error should come in the first after - one parameter', (t) => {
t.plan(3)
const server = { my: 'server' }
const app = boot(server)
app.use(function (s, opts, done) {
done(new Error('err'))
})
app.after(function (err) {
t.ok(err instanceof Error)
t.equal(err.message, 'err')
})
app.ready(function (err) {
t.error(err)
})
})
test('error should come in the first after - two parameters', (t) => {
t.plan(3)
const server = { my: 'server' }
const app = boot(server)
app.use(function (s, opts, done) {
done(new Error('err'))
})
app.after(function (err, cb) {
t.ok(err instanceof Error)
t.equal(err.message, 'err')
cb()
})
app.ready(function (err) {
t.error(err)
})
})
test('error should come in the first after - three parameter', (t) => {
t.plan(4)
const server = { my: 'server' }
const app = boot(server)
app.use(function (s, opts, done) {
done(new Error('err'))
})
app.after(function (err, context, cb) {
t.ok(err instanceof Error)
t.equal(err.message, 'err')
t.equal(context, server)
cb()
})
app.ready(function (err) {
t.error(err)
})
})
test('error should come in the first ready - one parameter', (t) => {
t.plan(2)
const server = { my: 'server' }
const app = boot(server)
app.use(function (s, opts, done) {
done(new Error('err'))
})
app.ready(function (err) {
t.ok(err instanceof Error)
t.equal(err.message, 'err')
})
})
test('error should come in the first ready - two parameters', (t) => {
t.plan(2)
const server = { my: 'server' }
const app = boot(server)
app.use(function (s, opts, done) {
done(new Error('err'))
})
app.ready(function (err, cb) {
t.ok(err instanceof Error)
t.equal(err.message, 'err')
cb()
})
})
test('error should come in the first ready - three parameters', (t) => {
t.plan(3)
const server = { my: 'server' }
const app = boot(server)
app.use(function (s, opts, done) {
done(new Error('err'))
})
app.ready(function (err, context, cb) {
t.ok(err instanceof Error)
t.equal(err.message, 'err')
t.equal(context, server)
cb()
})
})
test('if `use` has a callback with more then one parameter, the error must not reach ready', (t) => {
t.plan(1)
const server = { my: 'server' }
const app = boot(server)
app.use(function (s, opts, done) {
done(new Error('err'))
})
app.ready(function (err) {
t.ok(err)
})
})
test('if `use` has a callback without parameters, the error must reach ready', (t) => {
t.plan(1)
const server = { my: 'server' }
const app = boot(server)
app.use(function (s, opts, done) {
done(new Error('err'))
}, () => {})
app.ready(function (err) {
t.ok(err)
})
})
test('should pass the errors from after to ready', (t) => {
t.plan(6)
const server = {}
const app = boot(server, {})
server.use(function (s, opts, done) {
t.equal(s, server, 'the first argument is the server')
t.same(opts, {}, 'no options')
done()
}).after((err, done) => {
t.error(err)
done(new Error('some error'))
})
server.onClose(() => {
t.ok('onClose called')
})
server.ready(err => {
t.equal(err.message, 'some error')
})
app.on('start', () => {
server.close(() => {
t.pass('booted')
})
})
})
test('after no encapsulation', t => {
t.plan(4)
const app = boot()
app.override = function (s, fn, opts) {
s = Object.create(s)
return s
}
app.use(function (instance, opts, next) {
instance.test = true
instance.after(function (err, i, done) {
t.error(err)
t.notOk(i.test)
done()
})
next()
})
app.after(function (err, i, done) {
t.error(err)
t.notOk(i.test)
done()
})
})
test('ready no encapsulation', t => {
t.plan(4)
const app = boot()
app.override = function (s, fn, opts) {
s = Object.create(s)
return s
}
app.use(function (instance, opts, next) {
instance.test = true
instance.ready(function (err, i, done) {
t.error(err)
t.notOk(i.test)
done()
})
next()
})
app.ready(function (err, i, done) {
t.error(err)
t.notOk(i.test)
done()
})
})
test('after encapsulation with a server', t => {
t.plan(4)
const server = { my: 'server' }
const app = boot(server)
app.override = function (s, fn, opts) {
s = Object.create(s)
return s
}
app.use(function (instance, opts, next) {
instance.test = true
instance.after(function (err, i, done) {
t.error(err)
t.ok(i.test)
done()
})
next()
})
app.after(function (err, i, done) {
t.error(err)
t.notOk(i.test)
done()
})
})
test('ready encapsulation with a server', t => {
t.plan(4)
const server = { my: 'server' }
const app = boot(server)
app.override = function (s, fn, opts) {
s = Object.create(s)
return s
}
app.use(function (instance, opts, next) {
instance.test = true
instance.ready(function (err, i, done) {
t.error(err)
t.ok(i.test)
done()
})
next()
})
app.ready(function (err, i, done) {
t.error(err)
t.notOk(i.test)
done()
})
})
test('after should passthrough the errors', (t) => {
t.plan(5)
const app = boot()
let pluginLoaded = false
let afterCalled = false
app.use(function (s, opts, done) {
t.notOk(afterCalled, 'after not called')
pluginLoaded = true
done(new Error('kaboom'))
})
app.after(function () {
t.ok(pluginLoaded, 'afterred!')
afterCalled = true
})
app.ready(function (err) {
t.ok(err)
t.ok(afterCalled, 'after called')
t.ok(pluginLoaded, 'plugin loaded')
})
})
test('stop loading plugins if it errors', (t) => {
t.plan(2)
const app = boot()
app.use(function first (server, opts, done) {
t.pass('first called')
done(new Error('kaboom'))
})
app.use(function second (server, opts, done) {
t.fail('this should never be called')
})
app.ready((err) => {
t.equal(err.message, 'kaboom')
})
})
test('keep loading if there is an .after', (t) => {
t.plan(4)
const app = boot()
app.use(function first (server, opts, done) {
t.pass('first called')
done(new Error('kaboom'))
})
app.after(function (err) {
t.equal(err.message, 'kaboom')
})
app.use(function second (server, opts, done) {
t.pass('second called')
done()
})
app.ready((err) => {
t.error(err)
})
})
test('do not load nested plugin if parent errors', (t) => {
t.plan(4)
const app = boot()
app.use(function first (server, opts, done) {
t.pass('first called')
server.use(function second (_, opts, done) {
t.fail('this should never be called')
})
done(new Error('kaboom'))
})
app.after(function (err) {
t.equal(err.message, 'kaboom')
})
app.use(function third (server, opts, done) {
t.pass('third called')
done()
})
app.ready((err) => {
t.error(err)
})
})
test('.after nested', (t) => {
t.plan(4)
const app = boot()
app.use(function outer (app, opts, done) {
app.use(function first (app, opts, done) {
t.pass('first called')
done(new Error('kaboom'))
})
app.after(function (err) {
t.equal(err.message, 'kaboom')
})
app.use(function second (app, opts, done) {
t.pass('second called')
done()
})
done()
})
app.ready((err) => {
t.error(err)
})
})
test('nested error', (t) => {
t.plan(4)
const app = boot()
app.use(function outer (app, opts, done) {
app.use(function first (app, opts, done) {
t.pass('first called')
done(new Error('kaboom'))
})
app.use(function second (app, opts, done) {
t.fail('this should never be called')
})
done()
})
app.after(function (err) {
t.equal(err.message, 'kaboom')
})
app.use(function third (server, opts, done) {
t.pass('third called')
done()
})
app.ready((err) => {
t.error(err)
})
})
test('preReady event', (t) => {
t.plan(4)
const app = boot()
const order = [1, 2]
app.use(function first (server, opts, done) {
t.pass('first called')
done()
})
app.use(function second (server, opts, done) {
t.pass('second called')
done()
})
app.on('preReady', () => {
t.equal(order.shift(), 1)
})
app.ready(() => {
t.equal(order.shift(), 2)
})
})
test('preReady event (multiple)', (t) => {
t.plan(6)
const app = boot()
const order = [1, 2, 3, 4]
app.use(function first (server, opts, done) {
t.pass('first called')
done()
})
app.use(function second (server, opts, done) {
t.pass('second called')
done()
})
app.on('preReady', () => {
t.equal(order.shift(), 1)
})
app.on('preReady', () => {
t.equal(order.shift(), 2)
})
app.on('preReady', () => {
t.equal(order.shift(), 3)
})
app.ready(() => {
t.equal(order.shift(), 4)
})
})
test('preReady event (nested)', (t) => {
t.plan(6)
const app = boot()
const order = [1, 2, 3, 4]
app.use(function first (server, opts, done) {
t.pass('first called')
done()
})
app.use(function second (server, opts, done) {
t.pass('second called')
server.on('preReady', () => {
t.equal(order.shift(), 3)
})
done()
})
app.on('preReady', () => {
t.equal(order.shift(), 1)
})
app.on('preReady', () => {
t.equal(order.shift(), 2)
})
app.ready(() => {
t.equal(order.shift(), 4)
})
})
test('preReady event (errored)', (t) => {
t.plan(5)
const app = boot()
const order = [1, 2, 3]
app.use(function first (server, opts, done) {
t.pass('first called')
done(new Error('kaboom'))
})
app.use(function second (server, opts, done) {
t.fail('We should not be here')
})
app.on('preReady', () => {
t.equal(order.shift(), 1)
})
app.on('preReady', () => {
t.equal(order.shift(), 2)
})
app.ready((err) => {
t.ok(err)
t.equal(order.shift(), 3)
})
})
test('after return self', (t) => {
t.plan(6)
const app = boot()
let pluginLoaded = false
let afterCalled = false
let second = false
app.use(function (s, opts, done) {
t.notOk(afterCalled, 'after not called')
pluginLoaded = true
done()
})
app.after(function () {
t.ok(pluginLoaded, 'afterred!')
afterCalled = true
// happens with after(() => app.use(..))
return app
})
app.use(function (s, opts, done) {
t.ok(afterCalled, 'after called')
second = true
done()
})
app.on('start', () => {
t.ok(afterCalled, 'after called')
t.ok(pluginLoaded, 'plugin loaded')
t.ok(second, 'second plugin loaded')
})
})
test('after 1 param swallows errors with server and timeout', (t) => {
t.plan(3)
const server = {}
boot(server, { autostart: false, timeout: 1000 })
server.use(function first (server, opts, done) {
t.pass('first called')
done(new Error('kaboom'))
})
server.use(function second (server, opts, done) {
t.fail('We should not be here')
})
server.after(function (err) {
t.ok(err)
})
server.ready(function (err) {
t.error(err)
})
})

View File

@@ -0,0 +1,32 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('proper support for after with a passed async function in wrapped mode', (t) => {
const app = {}
boot(app)
t.plan(5)
const e = new Error('kaboom')
app.use(function (f, opts) {
return Promise.reject(e)
}).after(function (err, cb) {
t.equal(err, e)
cb(err)
}).after(function () {
t.pass('this is just called')
}).after(function (err, cb) {
t.equal(err, e)
cb(err)
})
app.ready().then(() => {
t.fail('this should not be called')
}).catch(err => {
t.ok(err)
t.equal(err.message, 'kaboom')
})
})

View File

@@ -0,0 +1,20 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('after does not await itself', async (t) => {
t.plan(3)
const app = {}
boot(app)
app.use(async (app) => {
t.pass('plugin init')
})
app.after(() => app)
t.pass('reachable')
await app.ready()
t.pass('reachable')
})

24
backend/node_modules/avvio/test/after-throw.test.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('catched error by Promise.reject', (t) => {
const app = boot()
t.plan(2)
t.threw = function (err) {
t.equal(err.message, 'kaboom2')
}
app.use(function (f, opts) {
return Promise.reject(new Error('kaboom'))
}).after(function (err) {
t.equal(err.message, 'kaboom')
throw new Error('kaboom2')
})
app.ready(function () {
t.fail('the ready callback should never be called')
})
})

View File

@@ -0,0 +1,90 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
const app = {}
boot(app)
test('multi after', (t) => {
t.plan(6)
app.use(function (f, opts, cb) {
cb()
}).after(() => {
t.pass('this is just called')
app.use(function (f, opts, cb) {
t.pass('this is just called')
cb()
})
}).after(function () {
t.pass('this is just called')
app.use(function (f, opts, cb) {
t.pass('this is just called')
cb()
})
}).after(function (err, cb) {
t.pass('this is just called')
cb(err)
})
app.ready().then(() => {
t.pass('ready')
}).catch(() => {
t.fail('this should not be called')
})
})
test('after grouping - use called after after called', (t) => {
t.plan(9)
const app = {}
boot(app)
const TEST_VALUE = {}
const OTHER_TEST_VALUE = {}
const NEW_TEST_VALUE = {}
const sO = (fn) => {
fn[Symbol.for('skip-override')] = true
return fn
}
app.use(sO(function (f, options, next) {
f.test = TEST_VALUE
next()
}))
app.after(function (err, f, done) {
t.error(err)
t.equal(f.test, TEST_VALUE)
f.test2 = OTHER_TEST_VALUE
done()
})
app.use(sO(function (f, options, next) {
t.equal(f.test, TEST_VALUE)
t.equal(f.test2, OTHER_TEST_VALUE)
f.test3 = NEW_TEST_VALUE
next()
}))
app.after(function (err, f, done) {
t.error(err)
t.equal(f.test, TEST_VALUE)
t.equal(f.test2, OTHER_TEST_VALUE)
t.equal(f.test3, NEW_TEST_VALUE)
done()
})
app.ready().then(() => {
t.pass('ready')
}).catch((e) => {
console.log(e)
t.fail('this should not be called')
})
})

325
backend/node_modules/avvio/test/async-await.test.js generated vendored Normal file
View File

@@ -0,0 +1,325 @@
'use strict'
/* eslint no-prototype-builtins: off */
const { test } = require('tap')
const sleep = function (ms) {
return new Promise(function (resolve) {
setTimeout(resolve, ms)
})
}
const boot = require('..')
test('one level', async (t) => {
t.plan(14)
const app = boot()
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
app.use(first)
app.use(third)
async function first (s, opts) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
firstLoaded = true
s.use(second)
}
async function second (s, opts) {
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
secondLoaded = true
}
async function third (s, opts) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
thirdLoaded = true
}
const readyContext = await app.ready()
t.equal(app, readyContext)
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.pass('booted')
})
test('multiple reentrant plugin loading', async (t) => {
t.plan(31)
const app = boot()
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
let fourthLoaded = false
let fifthLoaded = false
app.use(first)
app.use(fifth)
async function first (s, opts) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
firstLoaded = true
s.use(second)
}
async function second (s, opts) {
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
secondLoaded = true
s.use(third)
await sleep(10)
s.use(fourth)
}
async function third (s, opts) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
thirdLoaded = true
}
async function fourth (s, opts) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
fourthLoaded = true
}
async function fifth (s, opts) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
fifthLoaded = true
}
await app.ready()
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
t.ok(fifthLoaded, 'fifth is loaded')
t.pass('booted')
})
test('async ready plugin registration (errored)', async (t) => {
t.plan(1)
const app = boot()
app.use(async (server, opts) => {
await sleep(10)
throw new Error('kaboom')
})
try {
await app.ready()
t.fail('we should not be here')
} catch (err) {
t.equal(err.message, 'kaboom')
}
})
test('after', async (t) => {
t.plan(15)
const app = boot()
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
app.use(first)
async function first (s, opts) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
firstLoaded = true
s.after(second)
s.after(third)
}
async function second (err) {
t.error(err)
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
await sleep(10)
secondLoaded = true
}
async function third () {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
await sleep(10)
thirdLoaded = true
}
const readyContext = await app.ready()
t.equal(app, readyContext)
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.pass('booted')
})
test('after wrapped', async (t) => {
t.plan(15)
const app = {}
boot(app)
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
app.use(first)
async function first (s, opts) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
firstLoaded = true
s.after(second)
s.after(third)
}
async function second (err) {
t.error(err)
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
await sleep(10)
secondLoaded = true
}
async function third () {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
await sleep(10)
thirdLoaded = true
}
const readyContext = await app.ready()
t.equal(app, readyContext)
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.pass('booted')
})
test('promise plugins', async (t) => {
t.plan(14)
const app = boot()
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
app.use(first())
app.use(third())
async function first () {
return async function (s, opts) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
firstLoaded = true
s.use(second())
}
}
async function second () {
return async function (s, opts) {
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
secondLoaded = true
}
}
async function third () {
return async function (s, opts) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
thirdLoaded = true
}
}
const readyContext = await app.ready()
t.equal(app, readyContext)
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.pass('booted')
})
test('skip override with promise', (t) => {
t.plan(3)
const server = { my: 'server' }
const app = boot(server)
app.override = function (s, func) {
t.pass('override called')
if (func[Symbol.for('skip-override')]) {
return s
}
return Object.create(s)
}
app.use(first())
async function first () {
async function fn (s, opts) {
t.equal(s, server)
t.notOk(Object.prototype.isPrototypeOf.call(server, s))
}
fn[Symbol.for('skip-override')] = true
return fn
}
})
test('ready queue error', async (t) => {
const app = boot()
app.use(first)
async function first (s, opts) {}
app.ready(function (_, worker, done) {
const error = new Error('kaboom')
done(error)
})
await t.rejects(app.ready(), { message: 'kaboom' })
})

449
backend/node_modules/avvio/test/await-after.test.js generated vendored Normal file
View File

@@ -0,0 +1,449 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
const { promisify } = require('node:util')
const sleep = promisify(setTimeout)
const fs = require('node:fs').promises
const path = require('node:path')
test('await after - nested plugins with same tick callbacks', async (t) => {
const app = {}
boot(app)
let secondLoaded = false
app.use(async (app) => {
t.pass('plugin init')
app.use(async () => {
t.pass('plugin2 init')
await sleep(1)
secondLoaded = true
})
})
await app.after()
t.pass('reachable')
t.equal(secondLoaded, true)
await app.ready()
t.pass('reachable')
})
test('await after without server', async (t) => {
const app = boot()
let secondLoaded = false
app.use(async (app) => {
t.pass('plugin init')
app.use(async () => {
t.pass('plugin2 init')
await sleep(1)
secondLoaded = true
})
})
await app.after()
t.pass('reachable')
t.equal(secondLoaded, true)
await app.ready()
t.pass('reachable')
})
test('await after with cb functions', async (t) => {
const app = boot()
let secondLoaded = false
let record = ''
app.use(async (app) => {
t.pass('plugin init')
record += 'plugin|'
app.use(async () => {
t.pass('plugin2 init')
record += 'plugin2|'
await sleep(1)
secondLoaded = true
})
})
await app.after(() => {
record += 'after|'
})
t.pass('reachable')
t.equal(secondLoaded, true)
record += 'ready'
await app.ready()
t.pass('reachable')
t.equal(record, 'plugin|plugin2|after|ready')
})
test('await after - nested plugins with future tick callbacks', async (t) => {
const app = {}
boot(app)
t.plan(4)
app.use((f, opts, cb) => {
t.pass('plugin init')
app.use((f, opts, cb) => {
t.pass('plugin2 init')
setImmediate(cb)
})
setImmediate(cb)
})
await app.after()
t.pass('reachable')
await app.ready()
t.pass('reachable')
})
test('await after - nested async function plugins', async (t) => {
const app = {}
boot(app)
t.plan(5)
app.use(async (f, opts) => {
t.pass('plugin init')
await app.use(async (f, opts) => {
t.pass('plugin2 init')
})
t.pass('reachable')
})
await app.after()
t.pass('reachable')
await app.ready()
t.pass('reachable')
})
test('await after - promise resolves to undefined', async (t) => {
const app = {}
boot(app)
t.plan(4)
app.use(async (f, opts, cb) => {
app.use((f, opts, cb) => {
t.pass('plugin init')
cb()
})
const instance = await app.after()
t.equal(instance, undefined)
})
t.pass('reachable')
await app.ready()
t.pass('reachable')
})
test('await after - promise returning function plugins + promise chaining', async (t) => {
const app = {}
boot(app)
t.plan(6)
app.use((f, opts) => {
t.pass('plugin init')
return app.use((f, opts) => {
t.pass('plugin2 init')
return Promise.resolve()
}).then((f2) => {
t.equal(f2, f)
return 'test'
}).then((val) => {
t.equal(val, 'test')
})
})
await app.after()
t.pass('reachable')
await app.ready()
t.pass('reachable')
})
test('await after - error handling, async throw', async (t) => {
const app = {}
boot(app)
t.plan(2)
const e = new Error('kaboom')
app.use(async (f, opts) => {
throw Error('kaboom')
})
await t.rejects(app.after(), e)
await t.rejects(() => app.ready(), Error('kaboom'))
})
test('await after - error handling, async throw, nested', async (t) => {
const app = {}
boot(app)
t.plan(2)
const e = new Error('kaboom')
app.use(async (f, opts) => {
app.use(async (f, opts) => {
throw e
})
})
await t.rejects(app.after())
await t.rejects(() => app.ready(), e)
})
test('await after - error handling, same tick cb err', async (t) => {
const app = {}
boot(app)
t.plan(2)
app.use((f, opts, cb) => {
cb(Error('kaboom'))
})
await t.rejects(app.after())
await t.rejects(app.ready(), Error('kaboom'))
})
test('await after - error handling, same tick cb err, nested', async (t) => {
const app = {}
boot(app)
t.plan(2)
app.use((f, opts, cb) => {
app.use((f, opts, cb) => {
cb(Error('kaboom'))
})
cb()
})
await t.rejects(app.after())
await t.rejects(app.ready(), Error('kaboom'))
})
test('await after - error handling, future tick cb err', async (t) => {
const app = {}
boot(app)
t.plan(2)
app.use((f, opts, cb) => {
setImmediate(() => { cb(Error('kaboom')) })
})
await t.rejects(app.after())
await t.rejects(app.ready(), Error('kaboom'))
})
test('await after - error handling, future tick cb err, nested', async (t) => {
const app = {}
boot(app)
t.plan(2)
app.use((f, opts, cb) => {
app.use((f, opts, cb) => {
setImmediate(() => { cb(Error('kaboom')) })
})
cb()
})
await t.rejects(app.after(), Error('kaboom'))
await t.rejects(app.ready(), Error('kaboom'))
})
test('await after complex scenario', async (t) => {
const app = {}
boot(app)
t.plan(16)
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
let fourthLoaded = false
app.use(first)
await app.after()
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
app.use(second)
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
app.use(third)
await app.after()
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
await app.ready()
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
async function first () {
firstLoaded = true
}
async function second () {
secondLoaded = true
}
async function third (app) {
thirdLoaded = true
app.use(fourth)
}
async function fourth () {
fourthLoaded = true
}
})
test('without autostart and sync/async plugin mix', async (t) => {
const app = {}
boot(app, { autostart: false })
t.plan(21)
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
let fourthLoaded = false
app.use(first)
await app.after()
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
app.use(second)
await app.after()
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
await sleep(10)
app.use(third)
await app.after()
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
app.use(fourth)
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
await app.after()
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
await app.ready()
async function first () {
firstLoaded = true
}
async function second () {
const contents = await fs.readFile(path.join(__dirname, 'fixtures', 'dummy.txt'), 'utf-8')
t.equal(contents, 'hello, world!')
secondLoaded = true
}
async function third () {
await sleep(10)
thirdLoaded = true
}
function fourth (server, opts, done) {
fourthLoaded = true
done()
}
})
test('without autostart', async (t) => {
const app = {}
boot(app, { autostart: false })
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
app.use(async function first (app) {
firstLoaded = true
app.use(async () => {
await sleep(1)
secondLoaded = true
})
})
await app.after()
t.equal(firstLoaded, true)
t.equal(secondLoaded, true)
await app.use(async () => {
thirdLoaded = true
})
t.equal(thirdLoaded, true)
await app.ready()
})
test('without autostart and with override', async (t) => {
const app = {}
const _ = boot(app, { autostart: false })
let count = 0
_.override = function (s) {
const res = Object.create(s)
res.count = ++count
return res
}
app.use(async function first (app) {
t.equal(app.count, 1)
app.use(async (app) => {
t.equal(app.count, 2)
await app.after()
})
})
await app.after()
await app.use(async (app) => {
t.equal(app.count, 3)
})
await app.ready()
})
test('stop processing after errors', async (t) => {
t.plan(2)
const app = boot()
try {
await app.use(async function first (app) {
t.pass('first should be loaded')
throw new Error('kaboom')
})
} catch (e) {
t.equal(e.message, 'kaboom')
}
})

31
backend/node_modules/avvio/test/await-self.test.js generated vendored Normal file
View File

@@ -0,0 +1,31 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('await self', async (t) => {
const app = {}
boot(app)
t.equal(await app, app)
})
test('await self three times', async (t) => {
const app = {}
boot(app)
t.equal(await app, app)
t.equal(await app, app)
t.equal(await app, app)
})
test('await self within plugin', async (t) => {
const app = {}
boot(app)
app.use(async (f) => {
t.equal(await f, f)
})
t.equal(await app, app)
})

294
backend/node_modules/avvio/test/await-use.test.js generated vendored Normal file
View File

@@ -0,0 +1,294 @@
'use strict'
const { test } = require('tap')
const { promisify } = require('node:util')
const sleep = promisify(setTimeout)
const boot = require('..')
test('await use - nested plugins with same tick callbacks', async (t) => {
const app = {}
boot(app)
t.plan(4)
await app.use((f, opts, cb) => {
t.pass('plugin init')
app.use((f, opts, cb) => {
t.pass('plugin2 init')
cb()
})
cb()
})
t.pass('reachable')
await app.ready()
t.pass('reachable')
})
test('await use - nested plugins with future tick callbacks', async (t) => {
const app = {}
boot(app)
t.plan(4)
await app.use((f, opts, cb) => {
t.pass('plugin init')
app.use((f, opts, cb) => {
t.pass('plugin2 init')
setImmediate(cb)
})
setImmediate(cb)
})
t.pass('reachable')
await app.ready()
t.pass('reachable')
})
test('await use - nested async function plugins', async (t) => {
const app = {}
boot(app)
t.plan(5)
await app.use(async (f, opts) => {
t.pass('plugin init')
await app.use(async (f, opts) => {
t.pass('plugin2 init')
})
t.pass('reachable')
})
t.pass('reachable')
await app.ready()
t.pass('reachable')
})
test('await use - promise returning function plugins + promise chaining', async (t) => {
const app = {}
boot(app)
t.plan(6)
await app.use((f, opts) => {
t.pass('plugin init')
return app.use((f, opts) => {
t.pass('plugin2 init')
return Promise.resolve()
}).then(() => {
t.pass('reachable')
return 'test'
}).then((val) => {
t.equal(val, 'test')
})
})
t.pass('reachable')
await app.ready()
t.pass('reachable')
})
test('await use - await and use chaining', async (t) => {
const app = {}
boot(app)
t.plan(3)
app.use(async (f, opts, cb) => {
await app.use(async (f, opts) => {
t.pass('plugin init')
}).use(async (f, opts) => {
t.pass('plugin2 init')
})
})
await app.ready()
t.pass('reachable')
})
function thenableRejects (t, thenable, err, msg) {
return t.rejects(async () => { await thenable }, err, msg)
}
test('await use - error handling, async throw', async (t) => {
const app = {}
boot(app)
t.plan(2)
await thenableRejects(t, app.use(async (f, opts) => {
throw Error('kaboom')
}), Error('kaboom'))
await t.rejects(app.ready(), Error('kaboom'))
})
test('await use - error handling, async throw, nested', async (t) => {
const app = {}
boot(app)
t.plan(2)
await thenableRejects(t, app.use(async function a (f, opts) {
await app.use(async function b (f, opts) {
throw Error('kaboom')
})
}, Error('kaboom')), 'b')
t.rejects(() => app.ready(), Error('kaboom'))
})
test('await use - error handling, same tick cb err', async (t) => {
const app = {}
boot(app)
t.plan(2)
await thenableRejects(t, app.use((f, opts, cb) => {
cb(Error('kaboom'))
}), Error('kaboom'))
t.rejects(() => app.ready(), Error('kaboom'))
})
test('await use - error handling, same tick cb err, nested', async (t) => {
const app = {}
boot(app)
t.plan(2)
await thenableRejects(t, app.use((f, opts, cb) => {
app.use((f, opts, cb) => {
cb(Error('kaboom'))
})
cb()
}), Error('kaboom'))
t.rejects(() => app.ready(), Error('kaboom'))
})
test('await use - error handling, future tick cb err', async (t) => {
const app = {}
boot(app)
t.plan(2)
await thenableRejects(t, app.use((f, opts, cb) => {
setImmediate(() => { cb(Error('kaboom')) })
}), Error('kaboom'))
t.rejects(() => app.ready(), Error('kaboom'))
})
test('await use - error handling, future tick cb err, nested', async (t) => {
const app = {}
boot(app)
t.plan(2)
await thenableRejects(t, app.use((f, opts, cb) => {
app.use((f, opts, cb) => {
setImmediate(() => { cb(Error('kaboom')) })
})
cb()
}), Error('kaboom'))
t.rejects(() => app.ready(), Error('kaboom'))
})
test('mixed await use and non-awaited use ', async (t) => {
const app = {}
boot(app)
t.plan(16)
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
let fourthLoaded = false
await app.use(first)
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
app.use(second)
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
await app.use(third)
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
await app.ready()
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
async function first () {
firstLoaded = true
}
async function second () {
secondLoaded = true
}
async function third (app) {
thirdLoaded = true
app.use(fourth)
}
async function fourth () {
fourthLoaded = true
}
})
test('await use - mix of same and future tick callbacks', async (t) => {
const app = {}
boot(app, { autostart: false })
let record = ''
t.plan(4)
await app.use(async function plugin0 () {
t.pass('plugin0 init')
record += 'plugin0|'
})
await app.use(async function plugin1 () {
t.pass('plugin1 init')
await sleep(500)
record += 'plugin1|'
})
await sleep(1)
await app.use(async function plugin2 () {
t.pass('plugin2 init')
await sleep(500)
record += 'plugin2|'
})
record += 'ready'
t.equal(record, 'plugin0|plugin1|plugin2|ready')
})
test('await use - fork the promise chain', (t) => {
t.plan(3)
const app = {}
boot(app, { autostart: false })
async function setup () {
let set = false
await app.use(async function plugin0 () {
t.pass('plugin0 init')
await sleep(500)
set = true
})
t.equal(set, true)
}
setup()
app.ready((err, done) => {
t.error(err)
done()
})
})

439
backend/node_modules/avvio/test/basic.test.js generated vendored Normal file
View File

@@ -0,0 +1,439 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('boot an empty app', (t) => {
t.plan(1)
const app = boot()
app.on('start', () => {
t.pass('booted')
})
})
test('start returns app', (t) => {
t.plan(1)
const app = boot({}, { autostart: false })
app
.start()
.ready((err) => {
t.error(err)
})
})
test('boot an app with a plugin', (t) => {
t.plan(4)
const app = boot()
let after = false
app.use(function (server, opts, done) {
t.equal(server, app, 'the first argument is the server')
t.same(opts, {}, 'no options')
t.ok(after, 'delayed execution')
done()
})
after = true
app.on('start', () => {
t.pass('booted')
})
})
test('boot an app with a promisified plugin', (t) => {
t.plan(4)
const app = boot()
let after = false
app.use(function (server, opts) {
t.equal(server, app, 'the first argument is the server')
t.same(opts, {}, 'no options')
t.ok(after, 'delayed execution')
return Promise.resolve()
})
after = true
app.on('start', () => {
t.pass('booted')
})
})
test('boot an app with a plugin and a callback /1', (t) => {
t.plan(2)
const app = boot(() => {
t.pass('booted')
})
app.use(function (server, opts, done) {
t.pass('plugin loaded')
done()
})
})
test('boot an app with a plugin and a callback /2', (t) => {
t.plan(2)
const app = boot({}, () => {
t.pass('booted')
})
app.use(function (server, opts, done) {
t.pass('plugin loaded')
done()
})
})
test('boot a plugin with a custom server', (t) => {
t.plan(4)
const server = {}
const app = boot(server)
app.use(function (s, opts, done) {
t.equal(s, server, 'the first argument is the server')
t.same(opts, {}, 'no options')
done()
})
app.onClose(() => {
t.ok('onClose called')
})
app.on('start', () => {
app.close(() => {
t.pass('booted')
})
})
})
test('custom instance should inherits avvio methods /1', (t) => {
t.plan(6)
const server = {}
const app = boot(server, {})
server.use(function (s, opts, done) {
t.equal(s, server, 'the first argument is the server')
t.same(opts, {}, 'no options')
done()
}).after(() => {
t.ok('after called')
})
server.onClose(() => {
t.ok('onClose called')
})
server.ready(() => {
t.ok('ready called')
})
app.on('start', () => {
server.close(() => {
t.pass('booted')
})
})
})
test('custom instance should inherits avvio methods /2', (t) => {
t.plan(6)
const server = {}
const app = new boot(server, {}) // eslint-disable-line new-cap
server.use(function (s, opts, done) {
t.equal(s, server, 'the first argument is the server')
t.same(opts, {}, 'no options')
done()
}).after(() => {
t.ok('after called')
})
server.onClose(() => {
t.ok('onClose called')
})
server.ready(() => {
t.ok('ready called')
})
app.on('start', () => {
server.close(() => {
t.pass('booted')
})
})
})
test('boot a plugin with options', (t) => {
t.plan(3)
const server = {}
const app = boot(server)
const myOpts = {
hello: 'world'
}
app.use(function (s, opts, done) {
t.equal(s, server, 'the first argument is the server')
t.same(opts, myOpts, 'passed options')
done()
}, myOpts)
app.on('start', () => {
t.pass('booted')
})
})
test('boot a plugin with a function that returns the options', (t) => {
t.plan(4)
const server = {}
const app = boot(server)
const myOpts = {
hello: 'world'
}
const myOptsAsFunc = parent => {
t.equal(parent, server)
return parent.myOpts
}
app.use(function (s, opts, done) {
s.myOpts = opts
done()
}, myOpts)
app.use(function (s, opts, done) {
t.equal(s, server, 'the first argument is the server')
t.same(opts, myOpts, 'passed options via function accessing parent injected variable')
done()
}, myOptsAsFunc)
app.on('start', () => {
t.pass('booted')
})
})
test('throw on non-function use', (t) => {
t.plan(1)
const app = boot()
t.throws(() => {
app.use({})
})
})
// https://github.com/mcollina/avvio/issues/20
test('ready and nextTick', (t) => {
const app = boot()
process.nextTick(() => {
app.ready(() => {
t.end()
})
})
})
// https://github.com/mcollina/avvio/issues/20
test('promises and microtask', (t) => {
const app = boot()
Promise.resolve()
.then(() => {
app.ready(function () {
t.end()
})
})
})
test('always loads nested plugins after the current one', (t) => {
t.plan(2)
const server = {}
const app = boot(server)
let second = false
app.use(function (s, opts, done) {
app.use(function (s, opts, done) {
second = true
done()
})
t.notOk(second)
done()
})
app.on('start', () => {
t.ok(second)
})
})
test('promise long resolve', (t) => {
t.plan(2)
const app = boot()
setTimeout(function () {
t.throws(() => {
app.use((s, opts, done) => {
done()
})
}, 'root plugin has already booted')
})
app.ready(function (err) {
t.notOk(err)
})
})
test('do not autostart', (t) => {
const app = boot(null, {
autostart: false
})
app.on('start', () => {
t.fail()
})
t.end()
})
test('start with ready', (t) => {
t.plan(2)
const app = boot(null, {
autostart: false
})
app.on('start', () => {
t.pass()
})
app.ready(function (err) {
t.error(err)
})
})
test('load a plugin after start()', (t) => {
t.plan(1)
let startCalled = false
const app = boot(null, {
autostart: false
})
app.use((s, opts, done) => {
t.ok(startCalled)
done()
})
// we use a timer because
// it is more reliable than
// nextTick and setImmediate
// this almost always will come
// after those are completed
setTimeout(() => {
app.start()
startCalled = true
}, 2)
})
test('booted should be set before ready', (t) => {
t.plan(2)
const app = boot()
app.ready(function (err) {
t.error(err)
t.equal(app.booted, true)
})
})
test('start should be emitted after ready resolves', (t) => {
t.plan(1)
const app = boot()
let ready = false
app.ready().then(function () {
ready = true
})
app.on('start', function () {
t.equal(ready, true)
})
})
test('throws correctly if registering after ready', (t) => {
t.plan(1)
const app = boot()
app.ready(function () {
t.throws(() => {
app.use((a, b, done) => done())
}, 'root plugin has already booted')
})
})
test('preReady errors must be managed', (t) => {
t.plan(2)
const app = boot()
app.use((f, opts, cb) => {
cb()
})
app.on('preReady', () => {
throw new Error('boom')
})
app.ready(err => {
t.pass('ready function is called')
t.equal(err.message, 'boom')
})
})
test('preReady errors do not override plugin\'s errors', (t) => {
t.plan(3)
const app = boot()
app.use((f, opts, cb) => {
cb(new Error('baam'))
})
app.on('preReady', () => {
t.pass('preReady is executed')
throw new Error('boom')
})
app.ready(err => {
t.pass('ready function is called')
t.equal(err.message, 'baam')
})
})
test('support faux modules', (t) => {
t.plan(4)
const app = boot()
let after = false
// Faux modules are modules built with TypeScript
// or Babel that they export a .default property.
app.use({
default: function (server, opts, done) {
t.equal(server, app, 'the first argument is the server')
t.same(opts, {}, 'no options')
t.ok(after, 'delayed execution')
done()
}
})
after = true
app.on('start', () => {
t.pass('booted')
})
})

113
backend/node_modules/avvio/test/callbacks.test.js generated vendored Normal file
View File

@@ -0,0 +1,113 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('reentrant', (t) => {
t.plan(7)
const app = boot()
let firstLoaded = false
let secondLoaded = false
app
.use(first)
.after(() => {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.pass('booted')
})
function first (s, opts, done) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
firstLoaded = true
s.use(second)
done()
}
function second (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
secondLoaded = true
done()
}
})
test('reentrant with callbacks deferred', (t) => {
t.plan(11)
const app = boot()
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
app.use(first)
function first (s, opts, done) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
firstLoaded = true
s.use(second)
setTimeout(() => {
try {
s.use(third)
} catch (err) {
t.equal(err.message, 'Root plugin has already booted')
}
}, 500)
done()
}
function second (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
secondLoaded = true
done()
}
function third (s, opts, done) {
thirdLoaded = true
done()
}
app.on('start', () => {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.pass('booted')
})
})
test('multiple loading time', t => {
t.plan(1)
const app = boot()
function a (instance, opts, done) {
(opts.use || []).forEach(_ => { instance.use(_, { use: opts.subUse || [] }) })
setTimeout(done, 10)
}
const pointer = a
function b (instance, opts, done) {
(opts.use || []).forEach(_ => { instance.use(_, { use: opts.subUse || [] }) })
setTimeout(done, 20)
}
function c (instance, opts, done) {
(opts.use || []).forEach(_ => { instance.use(_, { use: opts.subUse || [] }) })
setTimeout(done, 30)
}
app
.use(function a (instance, opts, done) {
instance.use(pointer, { use: [b], subUse: [c] })
.use(b)
setTimeout(done, 0)
})
.after(() => {
t.pass('booted')
})
})

View File

@@ -0,0 +1,26 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('catch exceptions in parent.override', (t) => {
t.plan(2)
const server = {}
const app = boot(server, {
autostart: false
})
app.override = function () {
throw Error('catch it')
}
app
.use(function () {})
.start()
app.ready(function (err) {
t.type(err, Error)
t.match(err, /catch it/)
})
})

67
backend/node_modules/avvio/test/chainable.test.js generated vendored Normal file
View File

@@ -0,0 +1,67 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('chainable standalone', (t) => {
t.plan(5)
const readyResult = boot()
.use(function (ctx, opts, done) {
t.pass('1st plugin')
done()
}).after(function (err, done) {
t.error(err)
t.pass('2nd after')
done()
}).ready(function () {
t.pass('we are ready')
})
t.equal(readyResult, undefined)
})
test('chainable automatically binded', (t) => {
t.plan(5)
const app = {}
boot(app)
const readyResult = app
.use(function (ctx, opts, done) {
t.pass('1st plugin')
done()
}).after(function (err, done) {
t.error(err)
t.pass('2nd after')
done()
}).ready(function () {
t.pass('we are ready')
})
t.equal(readyResult, undefined)
})
test('chainable standalone with server', (t) => {
t.plan(6)
const server = {}
boot(server, {
expose: {
use: 'register'
}
})
const readyResult = server.register(function (ctx, opts, done) {
t.pass('1st plugin')
done()
}).after(function (err, done) {
t.error(err)
t.pass('2nd after')
done()
}).register(function (ctx, opts, done) {
t.pass('3rd plugin')
done()
}).ready(function () {
t.pass('we are ready')
})
t.equal(readyResult, undefined)
})

544
backend/node_modules/avvio/test/close.test.js generated vendored Normal file
View File

@@ -0,0 +1,544 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
const { AVV_ERR_CALLBACK_NOT_FN } = require('../lib/errors')
test('boot an app with a plugin', (t) => {
t.plan(4)
const app = boot()
let last = false
app.use(function (server, opts, done) {
app.onClose(() => {
t.ok('onClose called')
t.notOk(last)
last = true
})
done()
})
app.on('start', () => {
app.close(() => {
t.ok(last)
t.pass('Closed in the correct order')
})
})
})
test('onClose arguments', (t) => {
t.plan(5)
const app = boot()
app.use(function (server, opts, next) {
server.onClose((instance, done) => {
t.ok('called')
t.equal(server, instance)
done()
})
next()
})
app.use(function (server, opts, next) {
server.onClose((instance) => {
t.ok('called')
t.equal(server, instance)
})
next()
})
app.on('start', () => {
app.close(() => {
t.pass('Closed in the correct order')
})
})
})
test('onClose arguments - fastify encapsulation test case', (t) => {
t.plan(5)
const server = { my: 'server' }
const app = boot(server)
app.override = function (s, fn, opts) {
s = Object.create(s)
return s
}
app.use(function (instance, opts, next) {
instance.test = true
instance.onClose((i, done) => {
t.ok(i.test)
done()
})
next()
})
app.use(function (instance, opts, next) {
t.notOk(instance.test)
instance.onClose((i, done) => {
t.notOk(i.test)
done()
})
next()
})
app.on('start', () => {
t.notOk(app.test)
app.close(() => {
t.pass('Closed in the correct order')
})
})
})
test('onClose arguments - fastify encapsulation test case / 2', (t) => {
t.plan(5)
const server = { my: 'server' }
const app = boot(server)
app.override = function (s, fn, opts) {
s = Object.create(s)
return s
}
server.use(function (instance, opts, next) {
instance.test = true
instance.onClose((i, done) => {
t.ok(i.test)
done()
})
next()
})
server.use(function (instance, opts, next) {
t.notOk(instance.test)
instance.onClose((i, done) => {
t.notOk(i.test)
done()
})
next()
})
app.on('start', () => {
t.notOk(server.test)
try {
server.close()
t.pass()
} catch (err) {
t.fail(err)
}
})
})
test('onClose arguments - encapsulation test case no server', (t) => {
t.plan(5)
const app = boot()
app.override = function (s, fn, opts) {
s = Object.create(s)
return s
}
app.use(function (instance, opts, next) {
instance.test = true
instance.onClose((i, done) => {
t.notOk(i.test)
done()
})
next()
})
app.use(function (instance, opts, next) {
t.notOk(instance.test)
instance.onClose((i) => {
t.notOk(i.test)
})
next()
})
app.on('start', () => {
t.notOk(app.test)
app.close(() => {
t.pass('Closed in the correct order')
})
})
})
test('onClose should handle errors', (t) => {
t.plan(3)
const app = boot()
app.use(function (server, opts, done) {
app.onClose((instance, done) => {
t.ok('called')
done(new Error('some error'))
})
done()
})
app.on('start', () => {
app.close(err => {
t.equal(err.message, 'some error')
t.pass('Closed in the correct order')
})
})
})
test('#54 close handlers should receive same parameters when queue is not empty', (t) => {
t.plan(6)
const context = { test: true }
const app = boot(context)
app.use(function (server, opts, done) {
done()
})
app.on('start', () => {
app.close((err, done) => {
t.equal(err, null)
t.pass('Closed in the correct order')
setImmediate(done)
})
app.close(err => {
t.equal(err, null)
t.pass('Closed in the correct order')
})
app.close(err => {
t.equal(err, null)
t.pass('Closed in the correct order')
})
})
})
test('onClose should handle errors / 2', (t) => {
t.plan(4)
const app = boot()
app.onClose((instance, done) => {
t.ok('called')
done(new Error('some error'))
})
app.use(function (server, opts, done) {
app.onClose((instance, done) => {
t.ok('called')
done()
})
done()
})
app.on('start', () => {
app.close(err => {
t.equal(err.message, 'some error')
t.pass('Closed in the correct order')
})
})
})
test('close arguments', (t) => {
t.plan(4)
const app = boot()
app.use(function (server, opts, done) {
app.onClose((instance, done) => {
t.ok('called')
done()
})
done()
})
app.on('start', () => {
app.close((err, instance, done) => {
t.error(err)
t.equal(instance, app)
done()
t.pass('Closed in the correct order')
})
})
})
test('close event', (t) => {
t.plan(3)
const app = boot()
let last = false
app.on('start', () => {
app.close(() => {
t.notOk(last)
last = true
})
})
app.on('close', () => {
t.ok(last)
t.pass('event fired')
})
})
test('close order', (t) => {
t.plan(5)
const app = boot()
const order = [1, 2, 3, 4]
app.use(function (server, opts, done) {
app.onClose(() => {
t.equal(order.shift(), 3)
})
app.use(function (server, opts, done) {
app.onClose(() => {
t.equal(order.shift(), 2)
})
done()
})
done()
})
app.use(function (server, opts, done) {
app.onClose(() => {
t.equal(order.shift(), 1)
})
done()
})
app.on('start', () => {
app.close(() => {
t.equal(order.shift(), 4)
t.pass('Closed in the correct order')
})
})
})
test('close without a cb', (t) => {
t.plan(1)
const app = boot()
app.onClose((instance, done) => {
t.ok('called')
done()
})
app.close()
})
test('onClose with 0 parameters', (t) => {
t.plan(4)
const server = { my: 'server' }
const app = boot(server)
app.use(function (instance, opts, next) {
instance.onClose(function () {
t.ok('called')
t.equal(arguments.length, 0)
})
next()
})
app.close(err => {
t.error(err)
t.pass('Closed')
})
})
test('onClose with 1 parameter', (t) => {
t.plan(3)
const server = { my: 'server' }
const app = boot(server)
app.use(function (instance, opts, next) {
instance.onClose(function (context) {
t.equal(arguments.length, 1)
})
next()
})
app.close(err => {
t.error(err)
t.pass('Closed')
})
})
test('close passing not a function', (t) => {
t.plan(1)
const app = boot()
app.onClose((instance, done) => {
t.ok('called')
done()
})
t.throws(() => app.close({}), { message: 'not a function' })
})
test('close passing not a function', (t) => {
t.plan(1)
const app = boot()
app.onClose((instance, done) => {
t.ok('called')
done()
})
t.throws(() => app.close({}), { message: 'not a function' })
})
test('close passing not a function when wrapping', (t) => {
t.plan(1)
const app = {}
boot(app)
app.onClose((instance, done) => {
t.ok('called')
done()
})
t.throws(() => app.close({}), { message: 'not a function' })
})
test('close should trigger ready()', (t) => {
t.plan(2)
const app = boot(null, {
autostart: false
})
app.on('start', () => {
// this will be emitted after the
// callback in close() is fired
t.pass('started')
})
app.close(() => {
t.pass('closed')
})
})
test('close without a cb returns a promise', (t) => {
t.plan(1)
const app = boot()
app.close().then(() => {
t.pass('promise resolves')
})
})
test('close without a cb returns a promise when attaching to a server', (t) => {
t.plan(1)
const server = {}
boot(server)
server.close().then(() => {
t.pass('promise resolves')
})
})
test('close with async onClose handlers', t => {
t.plan(7)
const app = boot()
const order = [1, 2, 3, 4, 5, 6]
app.onClose(() => {
return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
t.equal(order.shift(), 5)
})
})
app.onClose(() => {
t.equal(order.shift(), 4)
})
app.onClose(instance => {
return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
t.equal(order.shift(), 3)
})
})
app.onClose(async instance => {
return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
t.equal(order.shift(), 2)
})
})
app.onClose(async () => {
return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
t.equal(order.shift(), 1)
})
})
app.on('start', () => {
app.close(() => {
t.equal(order.shift(), 6)
t.pass('Closed in the correct order')
})
})
})
test('onClose callback must be a function', (t) => {
t.plan(1)
const app = boot()
app.use(function (server, opts, done) {
t.throws(() => app.onClose({}), new AVV_ERR_CALLBACK_NOT_FN('onClose', 'object'))
done()
})
})
test('close custom server with async onClose handlers', t => {
t.plan(7)
const server = {}
const app = boot(server)
const order = [1, 2, 3, 4, 5, 6]
server.onClose(() => {
return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
t.equal(order.shift(), 5)
})
})
server.onClose(() => {
t.equal(order.shift(), 4)
})
server.onClose(instance => {
return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
t.equal(order.shift(), 3)
})
})
server.onClose(async instance => {
return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
t.equal(order.shift(), 2)
})
})
server.onClose(async () => {
return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
t.equal(order.shift(), 1)
})
})
app.on('start', () => {
app.close(() => {
t.equal(order.shift(), 6)
t.pass('Closed in the correct order')
})
})
})

26
backend/node_modules/avvio/test/errors.test.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
'use strict'
const { test } = require('tap')
const errors = require('../lib/errors')
test('Correct codes of AvvioErrors', t => {
const testcases = [
'AVV_ERR_EXPOSE_ALREADY_DEFINED',
'AVV_ERR_ATTRIBUTE_ALREADY_DEFINED',
'AVV_ERR_CALLBACK_NOT_FN',
'AVV_ERR_PLUGIN_NOT_VALID',
'AVV_ERR_ROOT_PLG_BOOTED',
'AVV_ERR_PARENT_PLG_LOADED',
'AVV_ERR_READY_TIMEOUT',
'AVV_ERR_PLUGIN_EXEC_TIMEOUT'
]
t.plan(testcases.length + 1)
// errors.js exposes errors and the createError fn
t.equal(testcases.length, Object.keys(errors).length)
for (const testcase of testcases) {
const error = new errors[testcase]()
t.equal(error.code, testcase)
}
})

12
backend/node_modules/avvio/test/esm.mjs generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import { test } from 'tap'
import boot from '../boot.js'
test('support import', async (t) => {
const app = boot()
app.use(import('./fixtures/esm.mjs'))
await app.ready()
t.equal(app.loaded, true)
})

14
backend/node_modules/avvio/test/esm.test.js generated vendored Normal file
View File

@@ -0,0 +1,14 @@
'use strict'
const { test } = require('tap')
test('support esm import', (t) => {
import('./esm.mjs').then(() => {
t.pass('esm is supported')
t.end()
}).catch((err) => {
process.nextTick(() => {
throw err
})
})
})

View File

@@ -0,0 +1,23 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
const noop = () => {}
test('boot a plugin and then execute a call after that', (t) => {
t.plan(1)
process.on('warning', (warning) => {
t.fail('we should not get a warning', warning)
})
const app = boot()
// eslint-disable-next-line no-var
for (var i = 0; i < 12; i++) {
app.on('preReady', noop)
}
setTimeout(() => {
t.pass('Everything ok')
}, 500)
})

80
backend/node_modules/avvio/test/expose.test.js generated vendored Normal file
View File

@@ -0,0 +1,80 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
const { AVV_ERR_EXPOSE_ALREADY_DEFINED, AVV_ERR_ATTRIBUTE_ALREADY_DEFINED } = require('../lib/errors')
const { kAvvio } = require('../lib/symbols')
for (const key of ['use', 'after', 'ready', 'onClose', 'close']) {
test('throws if ' + key + ' is by default already there', (t) => {
t.plan(1)
const app = {}
app[key] = () => { }
t.throws(() => boot(app), new AVV_ERR_EXPOSE_ALREADY_DEFINED(key, key))
})
test('throws if ' + key + ' is already there', (t) => {
t.plan(1)
const app = {}
app['cust' + key] = () => { }
t.throws(() => boot(app, { expose: { [key]: 'cust' + key } }), new AVV_ERR_EXPOSE_ALREADY_DEFINED('cust' + key, key))
})
test('support expose for ' + key, (t) => {
const app = {}
app[key] = () => { }
const expose = {}
expose[key] = 'muahah'
boot(app, {
expose
})
t.end()
})
}
test('set the kAvvio to true on the server', (t) => {
t.plan(1)
const server = {}
boot(server)
t.ok(server[kAvvio])
})
test('.then()', t => {
t.plan(3)
t.test('.then() can not be overwritten', (t) => {
t.plan(1)
const server = {
then: () => {}
}
t.throws(() => boot(server), AVV_ERR_ATTRIBUTE_ALREADY_DEFINED('then'))
})
t.test('.then() is a function', (t) => {
t.plan(1)
const server = {}
boot(server)
t.type(server.then, 'function')
})
t.test('.then() can not be overwritten', (t) => {
t.plan(1)
const server = {}
boot(server)
t.throws(() => { server.then = 'invalid' }, TypeError('Cannot set property then of #<Object> which has only a getter'))
})
})

52
backend/node_modules/avvio/test/express.test.js generated vendored Normal file
View File

@@ -0,0 +1,52 @@
'use strict'
const { test } = require('tap')
const express = require('express')
const http = require('node:http')
const boot = require('..')
test('express support', (t) => {
const app = express()
boot.express(app)
// It does:
//
// boot(app, {
// expose: {
// use: 'load'
// }
// })
t.plan(2)
let loaded = false
let server
app.load(function (app, opts, done) {
loaded = true
app.use(function (req, res) {
res.end('hello world')
})
done()
})
app.after((cb) => {
t.ok(loaded, 'plugin loaded')
server = app.listen(0, cb)
t.teardown(server.close.bind(server))
})
app.ready(() => {
http.get(`http://localhost:${server.address().port}`).on('response', function (res) {
let data = ''
res.on('data', function (chunk) {
data += chunk
})
res.on('end', function () {
t.equal(data, 'hello world')
})
})
})
})

1
backend/node_modules/avvio/test/fixtures/dummy.txt generated vendored Normal file
View File

@@ -0,0 +1 @@
hello, world!

3
backend/node_modules/avvio/test/fixtures/esm.mjs generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export default async function (app) {
app.loaded = true
}

View File

@@ -0,0 +1,5 @@
'use strict'
module.exports = function noNext (app, opts, next) {
// no call to next
}

View File

@@ -0,0 +1,16 @@
'use strict'
const { test } = require('tap')
const boot = require('../..')
test('should print the time tree', (t) => {
t.plan(2)
const app = boot()
app.use(function first (instance, opts, cb) {
const out = instance.prettyPrint().split('\n')
t.equal(out[0], 'root -1 ms')
t.equal(out[1], '└── first -1 ms')
cb()
})
})

View File

@@ -0,0 +1,55 @@
'use strict'
const { test } = require('tap')
const { createPromise } = require('../../lib/create-promise')
test('createPromise() returns an object', (t) => {
t.plan(3)
t.type(createPromise(), 'object')
t.equal(Array.isArray(createPromise()), false)
t.notOk(Array.isArray(createPromise() !== null))
})
test('createPromise() returns an attribute with attribute resolve', (t) => {
t.plan(1)
t.ok('resolve' in createPromise())
})
test('createPromise() returns an attribute with attribute reject', (t) => {
t.plan(1)
t.ok('reject' in createPromise())
})
test('createPromise() returns an attribute with attribute createPromise', (t) => {
t.plan(1)
t.ok('promise' in createPromise())
})
test('when resolve is called, createPromise attribute is resolved', (t) => {
t.plan(1)
const p = createPromise()
p.promise
.then(() => {
t.pass()
})
.catch(() => {
t.fail()
})
p.resolve()
})
test('when reject is called, createPromise attribute is rejected', (t) => {
t.plan(1)
const p = createPromise()
p.promise
.then(() => {
t.fail()
})
.catch(() => {
t.pass()
})
p.reject()
})

View File

@@ -0,0 +1,82 @@
'use strict'
const { test } = require('tap')
const { executeWithThenable } = require('../../lib/execute-with-thenable')
const { kAvvio } = require('../../lib/symbols')
test('executeWithThenable', (t) => {
t.plan(6)
t.test('passes the arguments to the function', (t) => {
t.plan(5)
executeWithThenable((...args) => {
t.equal(args.length, 3)
t.equal(args[0], 1)
t.equal(args[1], 2)
t.equal(args[2], 3)
}, [1, 2, 3], (err) => {
t.error(err)
})
})
t.test('function references this to itself', (t) => {
t.plan(2)
const func = function () {
t.equal(this, func)
}
executeWithThenable(func, [], (err) => {
t.error(err)
})
})
t.test('handle resolving Promise of func', (t) => {
t.plan(1)
const fn = function () {
return Promise.resolve(42)
}
executeWithThenable(fn, [], (err) => {
t.error(err)
})
})
t.test('handle rejecting Promise of func', (t) => {
t.plan(1)
const fn = function () {
return Promise.reject(new Error('Arbitrary Error'))
}
executeWithThenable(fn, [], (err) => {
t.equal(err.message, 'Arbitrary Error')
})
})
t.test('dont handle avvio mocks PromiseLike results but use callback if provided', (t) => {
t.plan(1)
const fn = function () {
const result = Promise.resolve(42)
result[kAvvio] = true
}
executeWithThenable(fn, [], (err) => {
t.error(err)
})
})
t.test('dont handle avvio mocks Promises and if no callback is provided', (t) => {
t.plan(1)
const fn = function () {
t.pass(1)
const result = Promise.resolve(42)
result[kAvvio] = true
}
executeWithThenable(fn, [])
})
})

View File

@@ -0,0 +1,67 @@
'use strict'
const { test } = require('tap')
const { getPluginName } = require('../../lib/get-plugin-name')
const { kPluginMeta } = require('../../lib/symbols')
test('getPluginName of function', (t) => {
t.plan(1)
t.equal(getPluginName(function aPlugin () { }), 'aPlugin')
})
test('getPluginName of async function', (t) => {
t.plan(1)
t.equal(getPluginName(async function aPlugin () { }), 'aPlugin')
})
test('getPluginName of arrow function without name', (t) => {
t.plan(2)
t.equal(getPluginName(() => { }), '() => { }')
t.equal(getPluginName(() => { return 'random' }), '() => { return \'random\' }')
})
test('getPluginName of arrow function assigned to variable', (t) => {
t.plan(1)
const namedArrowFunction = () => { }
t.equal(getPluginName(namedArrowFunction), 'namedArrowFunction')
})
test("getPluginName based on Symbol 'plugin-meta' /1", (t) => {
t.plan(1)
function plugin () {
}
plugin[kPluginMeta] = {}
t.equal(getPluginName(plugin), 'plugin')
})
test("getPluginName based on Symbol 'plugin-meta' /2", (t) => {
t.plan(1)
function plugin () {
}
plugin[kPluginMeta] = {
name: 'fastify-non-existent'
}
t.equal(getPluginName(plugin), 'fastify-non-existent')
})
test('getPluginName if null is provided as options', (t) => {
t.plan(1)
t.equal(getPluginName(function a () {}, null), 'a')
})
test('getPluginName if name is provided in options', (t) => {
t.plan(1)
t.equal(getPluginName(function defaultName () {}, { name: 'providedName' }), 'providedName')
})

View File

@@ -0,0 +1,20 @@
'use strict'
const { test } = require('tap')
const { isBundledOrTypescriptPlugin } = require('../../lib/is-bundled-or-typescript-plugin')
test('isBundledOrTypescriptPlugin', (t) => {
t.plan(9)
t.equal(isBundledOrTypescriptPlugin(1), false)
t.equal(isBundledOrTypescriptPlugin('function'), false)
t.equal(isBundledOrTypescriptPlugin({}), false)
t.equal(isBundledOrTypescriptPlugin([]), false)
t.equal(isBundledOrTypescriptPlugin(null), false)
t.equal(isBundledOrTypescriptPlugin(function () {}), false)
t.equal(isBundledOrTypescriptPlugin(new Promise((resolve) => resolve)), false)
t.equal(isBundledOrTypescriptPlugin(Promise.resolve()), false)
t.equal(isBundledOrTypescriptPlugin({ default: () => {} }), true)
})

View File

@@ -0,0 +1,20 @@
'use strict'
const { test } = require('tap')
const { isPromiseLike } = require('../../lib/is-promise-like')
test('isPromiseLike', (t) => {
t.plan(9)
t.equal(isPromiseLike(1), false)
t.equal(isPromiseLike('function'), false)
t.equal(isPromiseLike({}), false)
t.equal(isPromiseLike([]), false)
t.equal(isPromiseLike(null), false)
t.equal(isPromiseLike(function () {}), false)
t.equal(isPromiseLike(new Promise((resolve) => resolve)), true)
t.equal(isPromiseLike(Promise.resolve()), true)
t.equal(isPromiseLike({ then: () => {} }), true)
})

123
backend/node_modules/avvio/test/lib/thenify.test.js generated vendored Normal file
View File

@@ -0,0 +1,123 @@
'use strict'
const { test, mock } = require('tap')
const { kThenifyDoNotWrap } = require('../../lib/symbols')
test('thenify', (t) => {
t.plan(7)
t.test('return undefined if booted', (t) => {
t.plan(2)
const { thenify } = mock('../../lib/thenify', {
'../../lib/debug': {
debug: (message) => { t.equal(message, 'thenify returning undefined because we are already booted') }
}
})
const result = thenify.call({
booted: true
})
t.equal(result, undefined)
})
t.test('return undefined if kThenifyDoNotWrap is true', (t) => {
t.plan(1)
const { thenify } = require('../../lib/thenify')
const result = thenify.call({
[kThenifyDoNotWrap]: true
})
t.equal(result, undefined)
})
t.test('return PromiseConstructorLike if kThenifyDoNotWrap is false', (t) => {
t.plan(3)
const { thenify } = mock('../../lib/thenify', {
'../../lib/debug': {
debug: (message) => { t.equal(message, 'thenify') }
}
})
const promiseContructorLike = thenify.call({
[kThenifyDoNotWrap]: false
})
t.type(promiseContructorLike, 'function')
t.equal(promiseContructorLike.length, 2)
})
t.test('return PromiseConstructorLike', (t) => {
t.plan(3)
const { thenify } = mock('../../lib/thenify', {
'../../lib/debug': {
debug: (message) => { t.equal(message, 'thenify') }
}
})
const promiseContructorLike = thenify.call({})
t.type(promiseContructorLike, 'function')
t.equal(promiseContructorLike.length, 2)
})
t.test('resolve should return _server', async (t) => {
t.plan(1)
const { thenify } = require('../../lib/thenify')
const server = {
_loadRegistered: () => {
return Promise.resolve()
},
_server: 'server'
}
const promiseContructorLike = thenify.call(server)
promiseContructorLike(function (value) {
t.equal(value, 'server')
}, function (reason) {
t.error(reason)
})
})
t.test('resolving should set kThenifyDoNotWrap to true', async (t) => {
t.plan(1)
const { thenify } = require('../../lib/thenify')
const server = {
_loadRegistered: () => {
return Promise.resolve()
},
[kThenifyDoNotWrap]: false,
_server: 'server'
}
const promiseContructorLike = thenify.call(server)
promiseContructorLike(function (value) {
t.equal(server[kThenifyDoNotWrap], true)
}, function (reason) {
t.error(reason)
})
})
t.test('rejection should pass through to reject', async (t) => {
t.plan(1)
const { thenify } = require('../../lib/thenify')
const server = {
_loadRegistered: () => {
return Promise.reject(new Error('Arbitrary rejection'))
},
_server: 'server'
}
const promiseContructorLike = thenify.call(server)
promiseContructorLike(function (value) {
t.error(value)
}, function (reason) {
t.equal(reason.message, 'Arbitrary rejection')
})
})
})

391
backend/node_modules/avvio/test/lib/time-tree.test.js generated vendored Normal file
View File

@@ -0,0 +1,391 @@
'use strict'
const { test } = require('tap')
const { TimeTree } = require('../../lib/time-tree')
test('TimeTree is constructed with a root attribute, set to null', t => {
t.plan(1)
const tree = new TimeTree()
t.equal(tree.root, null)
})
test('TimeTree is constructed with an empty tableId-Map', t => {
t.plan(2)
const tree = new TimeTree()
t.ok(tree.tableId instanceof Map)
t.equal(tree.tableId.size, 0)
})
test('TimeTree is constructed with an empty tableLabel-Map', t => {
t.plan(2)
const tree = new TimeTree()
t.ok(tree.tableLabel instanceof Map)
t.equal(tree.tableLabel.size, 0)
})
test('TimeTree#toJSON dumps the content of the TimeTree', t => {
t.plan(1)
const tree = new TimeTree()
t.same(tree.toJSON(), {})
})
test('TimeTree#toJSON is creating new instances of its content, ensuring being immutable', t => {
t.plan(1)
const tree = new TimeTree()
t.not(tree.toJSON(), tree.toJSON())
})
test('TimeTree#start is adding a node with correct shape, root-node', t => {
t.plan(15)
const tree = new TimeTree()
tree.start(null, 'root')
const rootNode = tree.root
t.equal(Object.keys(rootNode).length, 7)
t.ok('parent' in rootNode)
t.equal(rootNode.parent, null)
t.ok('id' in rootNode)
t.type(rootNode.id, 'string')
t.ok('label' in rootNode)
t.type(rootNode.label, 'string')
t.ok('nodes' in rootNode)
t.ok(Array.isArray(rootNode.nodes))
t.ok('start' in rootNode)
t.ok(Number.isInteger(rootNode.start))
t.ok('stop' in rootNode)
t.type(rootNode.stop, 'null')
t.ok('diff' in rootNode)
t.type(rootNode.diff, 'number')
})
test('TimeTree#start is adding a node with correct shape, child-node', t => {
t.plan(16)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
const rootNode = tree.root
t.equal(rootNode.nodes.length, 1)
const childNode = rootNode.nodes[0]
t.equal(Object.keys(childNode).length, 7)
t.ok('parent' in childNode)
t.type(childNode.parent, 'string')
t.ok('id' in childNode)
t.type(childNode.id, 'string')
t.ok('label' in childNode)
t.type(childNode.label, 'string')
t.ok('nodes' in childNode)
t.ok(Array.isArray(childNode.nodes))
t.ok('start' in childNode)
t.ok(Number.isInteger(childNode.start))
t.ok('stop' in childNode)
t.type(childNode.stop, 'null')
t.ok('diff' in childNode)
t.type(childNode.diff, 'number')
})
test('TimeTree#start is adding a root element when parent is null', t => {
t.plan(9)
const tree = new TimeTree()
tree.start(null, 'root')
const rootNode = tree.root
t.type(rootNode, 'object')
t.equal(Object.keys(rootNode).length, 7)
t.equal(rootNode.parent, null)
t.equal(rootNode.id, 'root')
t.equal(rootNode.label, 'root')
t.ok(Array.isArray(rootNode.nodes))
t.equal(rootNode.nodes.length, 0)
t.ok(Number.isInteger(rootNode.start))
t.type(rootNode.diff, 'number')
})
test('TimeTree#start is adding a root element when parent does not exist', t => {
t.plan(9)
const tree = new TimeTree()
tree.start('invalid', 'root')
const rootNode = tree.root
t.type(rootNode, 'object')
t.equal(Object.keys(rootNode).length, 7)
t.equal(rootNode.parent, null)
t.equal(rootNode.id, 'root')
t.equal(rootNode.label, 'root')
t.ok(Array.isArray(rootNode.nodes))
t.equal(rootNode.nodes.length, 0)
t.ok(Number.isInteger(rootNode.start))
t.type(rootNode.diff, 'number')
})
test('TimeTree#start parameter start can override automatically generated start time', t => {
t.plan(1)
const tree = new TimeTree()
tree.start(null, 'root', 1337)
t.ok(tree.root.start, 1337)
})
test('TimeTree#start returns id of root, when adding a root node /1', t => {
t.plan(1)
const tree = new TimeTree()
t.equal(tree.start(null, 'root'), 'root')
})
test('TimeTree#start returns id of root, when adding a root node /2', t => {
t.plan(1)
const tree = new TimeTree()
t.equal(tree.start(null, '/'), 'root')
})
test('TimeTree#start returns id of child, when adding a child node', t => {
t.plan(1)
const tree = new TimeTree()
tree.start(null, 'root')
t.match(tree.start('root', 'child'), /^child-[0-9.]+$/)
})
test('TimeTree tracks node ids /1', t => {
t.plan(3)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
t.equal(tree.tableId.size, 2)
t.ok(tree.tableId.has('root'))
t.ok(tree.tableId.has(tree.root.nodes[0].id))
})
test('TimeTree tracks node ids /2', t => {
t.plan(4)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.start('child', 'grandchild')
t.equal(tree.tableId.size, 3)
t.ok(tree.tableId.has('root'))
t.ok(tree.tableId.has(tree.root.nodes[0].id))
t.ok(tree.tableId.has(tree.root.nodes[0].nodes[0].id))
})
test('TimeTree tracks node ids /3', t => {
t.plan(4)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.start('root', 'child')
t.equal(tree.tableId.size, 3)
t.ok(tree.tableId.has('root'))
t.ok(tree.tableId.has(tree.root.nodes[0].id))
t.ok(tree.tableId.has(tree.root.nodes[1].id))
})
test('TimeTree tracks node labels /1', t => {
t.plan(4)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.start('root', 'sibling')
t.equal(tree.tableLabel.size, 3)
t.ok(tree.tableLabel.has('root'))
t.ok(tree.tableLabel.has('child'))
t.ok(tree.tableLabel.has('sibling'))
})
test('TimeTree tracks node labels /2', t => {
t.plan(3)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.start('root', 'child')
t.equal(tree.tableLabel.size, 2)
t.ok(tree.tableLabel.has('root'))
t.ok(tree.tableLabel.has('child'))
})
test('TimeTree#stop returns undefined', t => {
t.plan(1)
const tree = new TimeTree()
tree.start(null, 'root')
t.type(tree.stop('root'), 'undefined')
})
test('TimeTree#stop sets stop value of node', t => {
t.plan(3)
const tree = new TimeTree()
tree.start(null, 'root')
t.type(tree.root.stop, 'null')
tree.stop('root')
t.type(tree.root.stop, 'number')
t.ok(Number.isInteger(tree.root.stop))
})
test('TimeTree#stop parameter stop is used as stop value of node', t => {
t.plan(3)
const tree = new TimeTree()
tree.start(null, 'root')
t.type(tree.root.stop, 'null')
tree.stop('root', 1337)
t.type(tree.root.stop, 'number')
t.equal(tree.root.stop, 1337)
})
test('TimeTree#stop calculates the diff', t => {
t.plan(4)
const tree = new TimeTree()
tree.start(null, 'root', 1)
t.type(tree.root.diff, 'number')
t.equal(tree.root.diff, -1)
tree.stop('root', 5)
t.type(tree.root.diff, 'number')
t.equal(tree.root.diff, 4)
})
test('TimeTree#stop does nothing when node is not found', t => {
t.plan(2)
const tree = new TimeTree()
tree.start(null, 'root')
t.type(tree.root.stop, 'null')
tree.stop('invalid')
t.type(tree.root.stop, 'null')
})
test('TimeTree untracks node ids /1', t => {
t.plan(2)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.stop(tree.root.nodes[0].id)
t.equal(tree.tableId.size, 1)
t.ok(tree.tableId.has('root'))
})
test('TimeTree untracks node ids /2', t => {
t.plan(3)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.start('child', 'grandchild')
tree.stop(tree.root.nodes[0].nodes[0].id)
t.equal(tree.tableId.size, 2)
t.ok(tree.tableId.has('root'))
t.ok(tree.tableId.has(tree.root.nodes[0].id))
})
test('TimeTree untracks node ids /3', t => {
t.plan(3)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.start('root', 'child')
tree.stop(tree.root.nodes[0].id)
t.equal(tree.tableId.size, 2)
t.ok(tree.tableId.has('root'))
t.ok(tree.tableId.has(tree.root.nodes[1].id))
})
test('TimeTree untracks node ids /4', t => {
t.plan(3)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.start('root', 'child')
tree.stop(tree.root.nodes[1].id)
t.equal(tree.tableId.size, 2)
t.ok(tree.tableId.has('root'))
t.ok(tree.tableId.has(tree.root.nodes[0].id))
})
test('TimeTree untracks node labels /1', t => {
t.plan(3)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.start('root', 'sibling')
tree.stop(tree.root.nodes[1].id)
t.equal(tree.tableLabel.size, 2)
t.ok(tree.tableLabel.has('root'))
t.ok(tree.tableLabel.has('child'))
})
test('TimeTree untracks node labels /2', t => {
t.plan(3)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.start('root', 'sibling')
tree.stop(tree.root.nodes[0].id)
t.equal(tree.tableLabel.size, 2)
t.ok(tree.tableLabel.has('root'))
t.ok(tree.tableLabel.has('sibling'))
})
test('TimeTree does not untrack label if used by other node', t => {
t.plan(3)
const tree = new TimeTree()
tree.start(null, 'root')
tree.start('root', 'child')
tree.start('root', 'child')
tree.stop(tree.root.nodes[0].id)
t.equal(tree.tableLabel.size, 2)
t.ok(tree.tableLabel.has('root'))
t.ok(tree.tableLabel.has('child'))
})

View File

@@ -0,0 +1,19 @@
'use strict'
const { test } = require('tap')
const { validatePlugin } = require('../../lib/validate-plugin')
const { AVV_ERR_PLUGIN_NOT_VALID } = require('../../lib/errors')
test('validatePlugin', (t) => {
t.plan(8)
t.throws(() => validatePlugin(1), new AVV_ERR_PLUGIN_NOT_VALID('number'))
t.throws(() => validatePlugin('function'), new AVV_ERR_PLUGIN_NOT_VALID('string'))
t.throws(() => validatePlugin({}), new AVV_ERR_PLUGIN_NOT_VALID('object'))
t.throws(() => validatePlugin([]), new AVV_ERR_PLUGIN_NOT_VALID('array'))
t.throws(() => validatePlugin(null), new AVV_ERR_PLUGIN_NOT_VALID('null'))
t.doesNotThrow(() => validatePlugin(function () {}))
t.doesNotThrow(() => validatePlugin(new Promise((resolve) => resolve)))
t.doesNotThrow(() => validatePlugin(Promise.resolve()))
})

112
backend/node_modules/avvio/test/load-plugin.test.js generated vendored Normal file
View File

@@ -0,0 +1,112 @@
'use strict'
const fastq = require('fastq')
const boot = require('..')
const { test } = require('tap')
const { Plugin } = require('../lib/plugin')
test('successfully load a plugin with sync function', (t) => {
t.plan(1)
const app = boot({})
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts, done) {
done()
}, false, 0)
app._loadPlugin(plugin, function (err) {
t.equal(err, undefined)
})
})
test('catch an error when loading a plugin with sync function', (t) => {
t.plan(1)
const app = boot({})
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts, done) {
done(Error('ArbitraryError'))
}, false, 0)
app._loadPlugin(plugin, function (err) {
t.equal(err.message, 'ArbitraryError')
})
})
test('successfully load a plugin with async function', (t) => {
t.plan(1)
const app = boot({})
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), async function (instance, opts) { }, false, 0)
app._loadPlugin(plugin, function (err) {
t.equal(err, undefined)
})
})
test('catch an error when loading a plugin with async function', (t) => {
t.plan(1)
const app = boot({})
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), async function (instance, opts) {
throw Error('ArbitraryError')
}, false, 0)
app._loadPlugin(plugin, function (err) {
t.equal(err.message, 'ArbitraryError')
})
})
test('successfully load a plugin when function is a Promise, which resolves to a function', (t) => {
t.plan(1)
const app = boot({})
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), new Promise(resolve => resolve(function (instance, opts, done) {
done()
})), false, 0)
app._loadPlugin(plugin, function (err) {
t.equal(err, undefined)
})
})
test('catch an error when loading a plugin when function is a Promise, which resolves to a function', (t) => {
t.plan(1)
const app = boot({})
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), new Promise(resolve => resolve(function (instance, opts, done) {
done(Error('ArbitraryError'))
})), false, 0)
app._loadPlugin(plugin, function (err) {
t.equal(err.message, 'ArbitraryError')
})
})
test('successfully load a plugin when function is a Promise, which resolves to a function, which is wrapped in default', (t) => {
t.plan(1)
const app = boot({})
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), new Promise(resolve => resolve({
default: function (instance, opts, done) {
done()
}
})), false, 0)
app._loadPlugin(plugin, function (err) {
t.equal(err, undefined)
})
})
test('catch an error when loading a plugin when function is a Promise, which resolves to a function, which is wrapped in default', (t) => {
t.plan(1)
const app = boot({})
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), new Promise(resolve => resolve({
default: function (instance, opts, done) {
done(Error('ArbitraryError'))
}
})), false, 0)
app._loadPlugin(plugin, function (err) {
t.equal(err.message, 'ArbitraryError')
})
})

View File

@@ -0,0 +1,33 @@
'use strict'
/* eslint no-prototype-builtins: off */
const { test } = require('tap')
const boot = require('../boot')
test('onReadyTimeout', async (t) => {
const app = boot({}, {
timeout: 10, // 10 ms
autostart: false
})
app.use(function one (innerApp, opts, next) {
t.pass('loaded')
innerApp.ready(function readyNoResolve (err, done) {
t.notOk(err)
t.pass('first ready called')
// Do not call done() to timeout
})
next()
})
await app.start()
try {
await app.ready()
t.fail('should throw')
} catch (err) {
t.equal(err.message, 'Plugin did not start in time: \'readyNoResolve\'. You may have forgotten to call \'done\' function or to resolve a Promise')
// And not Plugin did not start in time: 'bound _encapsulateThreeParam'. You may have forgotten to call 'done' function or to resolve a Promise
}
})

374
backend/node_modules/avvio/test/override.test.js generated vendored Normal file
View File

@@ -0,0 +1,374 @@
'use strict'
/* eslint no-prototype-builtins: off */
const { test } = require('tap')
const boot = require('..')
test('custom inheritance', (t) => {
t.plan(3)
const server = { my: 'server' }
const app = boot(server)
app.override = function (s) {
t.equal(s, server)
const res = Object.create(s)
res.b = 42
return res
}
app.use(function first (s, opts, cb) {
t.not(s, server)
t.ok(Object.prototype.isPrototypeOf.call(server, s))
cb()
})
})
test('custom inheritance multiple levels', (t) => {
t.plan(6)
const server = { count: 0 }
const app = boot(server)
app.override = function (s) {
const res = Object.create(s)
res.count = res.count + 1
return res
}
app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(second)
cb()
function second (s2, opts, cb) {
t.not(s2, s1)
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
})
})
test('custom inheritance multiple levels twice', (t) => {
t.plan(10)
const server = { count: 0 }
const app = boot(server)
app.override = function (s) {
const res = Object.create(s)
res.count = res.count + 1
return res
}
app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(second)
s1.use(third)
let prev
cb()
function second (s2, opts, cb) {
prev = s2
t.not(s2, s1)
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
function third (s3, opts, cb) {
t.not(s3, s1)
t.ok(Object.prototype.isPrototypeOf.call(s1, s3))
t.notOk(Object.prototype.isPrototypeOf.call(prev, s3))
t.equal(s3.count, 2)
cb()
}
})
})
test('custom inheritance multiple levels with multiple heads', (t) => {
t.plan(13)
const server = { count: 0 }
const app = boot(server)
app.override = function (s) {
const res = Object.create(s)
res.count = res.count + 1
return res
}
app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(second)
cb()
function second (s2, opts, cb) {
t.not(s2, s1)
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
})
app.use(function third (s1, opts, cb) {
t.not(s1, server)
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(fourth)
cb()
function fourth (s2, opts, cb) {
t.not(s2, s1)
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
})
app.ready(function () {
t.equal(server.count, 0)
})
})
test('fastify test case', (t) => {
t.plan(7)
const noop = () => {}
function build () {
const app = boot(server, {})
app.override = function (s) {
return Object.create(s)
}
server.add = function (name, fn, cb) {
if (this[name]) return cb(new Error('already existent'))
this[name] = fn
cb()
}
return server
function server (req, res) {}
}
const instance = build()
t.ok(instance.add)
t.ok(instance.use)
instance.use((i, opts, cb) => {
t.not(i, instance)
t.ok(Object.prototype.isPrototypeOf.call(instance, i))
i.add('test', noop, (err) => {
t.error(err)
t.ok(i.test)
cb()
})
})
instance.ready(() => {
t.notOk(instance.test)
})
})
test('override should pass also the plugin function', (t) => {
t.plan(3)
const server = { my: 'server' }
const app = boot(server)
app.override = function (s, fn) {
t.type(fn, 'function')
t.equal(fn, first)
return s
}
app.use(first)
function first (s, opts, cb) {
t.equal(s, server)
cb()
}
})
test('skip override - fastify test case', (t) => {
t.plan(2)
const server = { my: 'server' }
const app = boot(server)
app.override = function (s, func) {
if (func[Symbol.for('skip-override')]) {
return s
}
return Object.create(s)
}
first[Symbol.for('skip-override')] = true
app.use(first)
function first (s, opts, cb) {
t.equal(s, server)
t.notOk(Object.prototype.isPrototypeOf.call(server, s))
cb()
}
})
test('override can receive options object', (t) => {
t.plan(4)
const server = { my: 'server' }
const options = { hello: 'world' }
const app = boot(server)
app.override = function (s, fn, opts) {
t.equal(s, server)
t.same(opts, options)
const res = Object.create(s)
res.b = 42
return res
}
app.use(function first (s, opts, cb) {
t.not(s, server)
t.ok(Object.prototype.isPrototypeOf.call(server, s))
cb()
}, options)
})
test('override can receive options function', (t) => {
t.plan(8)
const server = { my: 'server' }
const options = { hello: 'world' }
const app = boot(server)
app.override = function (s, fn, opts) {
t.equal(s, server)
if (typeof opts !== 'function') {
t.same(opts, options)
}
const res = Object.create(s)
res.b = 42
res.bar = 'world'
return res
}
app.use(function first (s, opts, cb) {
t.not(s, server)
t.ok(Object.prototype.isPrototypeOf.call(server, s))
s.foo = 'bar'
cb()
}, options)
app.use(function second (s, opts, cb) {
t.notOk(s.foo)
t.same(opts, { hello: 'world' })
t.ok(Object.prototype.isPrototypeOf.call(server, s))
cb()
}, p => ({ hello: p.bar }))
})
test('after trigger override', t => {
t.plan(8)
const server = { count: 0 }
const app = boot(server)
let overrideCalls = 0
app.override = function (s, fn, opts) {
overrideCalls++
const res = Object.create(s)
res.count = res.count + 1
return res
}
app
.use(function first (s, opts, cb) {
t.equal(s.count, 1, 'should trigger override')
cb()
})
.after(function () {
t.equal(overrideCalls, 1, 'after with 0 parameter should not trigger override')
})
.after(function (err) {
if (err) throw err
t.equal(overrideCalls, 1, 'after with 1 parameter should not trigger override')
})
.after(function (err, done) {
if (err) throw err
t.equal(overrideCalls, 1, 'after with 2 parameters should not trigger override')
done()
})
.after(function (err, context, done) {
if (err) throw err
t.equal(overrideCalls, 1, 'after with 3 parameters should not trigger override')
done()
})
.after(async function () {
t.equal(overrideCalls, 1, 'async after with 0 parameter should not trigger override')
})
.after(async function (err) {
if (err) throw err
t.equal(overrideCalls, 1, 'async after with 1 parameter should not trigger override')
})
.after(async function (err, context) {
if (err) throw err
t.equal(overrideCalls, 1, 'async after with 2 parameters should not trigger override')
})
})
test('custom inheritance override in after', (t) => {
t.plan(6)
const server = { count: 0 }
const app = boot(server)
app.override = function (s) {
const res = Object.create(s)
res.count = res.count + 1
return res
}
app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.after(() => {
s1.use(second)
})
cb()
function second (s2, opts, cb) {
t.not(s2, s1)
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
})
})

View File

@@ -0,0 +1,84 @@
'use strict'
const { test } = require('tap')
const fastq = require('fastq')
const boot = require('..')
const { Plugin } = require('../lib/plugin')
test('loadedSoFar resolves a Promise, if plugin.loaded is set to true', async (t) => {
t.plan(1)
const app = boot({})
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts, done) {
done()
}, false, 0)
plugin.loaded = true
await t.resolves(plugin.loadedSoFar())
})
test('loadedSoFar resolves a Promise, if plugin was loaded by avvio', async (t) => {
t.plan(2)
const app = boot({})
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts, done) {
done()
}, false, 0)
app._loadPlugin(plugin, function (err) {
t.equal(err, undefined)
})
await app.ready()
await t.resolves(plugin.loadedSoFar())
})
test('loadedSoFar resolves a Promise, if .after() has no error', async t => {
t.plan(1)
const app = boot()
app.after = function (callback) {
callback(null, () => {})
}
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts, done) {
done()
}, false, 0)
app._loadPlugin(plugin, function () {})
await t.resolves(plugin.loadedSoFar())
})
test('loadedSoFar rejects a Promise, if .after() has an error', async t => {
t.plan(1)
const app = boot()
app.after = function (fn) {
fn(new Error('ArbitraryError'), () => {})
}
const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts, done) {
done()
}, false, 0)
app._loadPlugin(plugin, function () {})
await t.rejects(plugin.loadedSoFar(), new Error('ArbitraryError'))
})
test('loadedSoFar resolves a Promise, if Plugin is attached to avvio after it the Plugin was instantiated', async t => {
t.plan(1)
const plugin = new Plugin(fastq(null, null, 1), function (instance, opts, done) {
done()
}, false, 0)
const promise = plugin.loadedSoFar()
plugin.server = boot()
plugin.emit('start')
await t.resolves(promise)
})

69
backend/node_modules/avvio/test/plugin-name.test.js generated vendored Normal file
View File

@@ -0,0 +1,69 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
const { kPluginMeta } = require('../lib/symbols')
test('plugins get a name from the plugin metadata if it is set', async (t) => {
t.plan(1)
const app = boot()
const func = (app, opts, next) => next()
func[kPluginMeta] = { name: 'a-test-plugin' }
app.use(func)
await app.ready()
t.match(app.toJSON(), {
label: 'root',
nodes: [
{ label: 'a-test-plugin' }
]
})
})
test('plugins get a name from the options if theres no metadata', async (t) => {
t.plan(1)
const app = boot()
function testPlugin (app, opts, next) { next() }
app.use(testPlugin, { name: 'test registration options name' })
await app.ready()
t.match(app.toJSON(), {
label: 'root',
nodes: [
{ label: 'test registration options name' }
]
})
})
test('plugins get a name from the function name if theres no name in the options and no metadata', async (t) => {
t.plan(1)
const app = boot()
function testPlugin (app, opts, next) { next() }
app.use(testPlugin)
await app.ready()
t.match(app.toJSON(), {
label: 'root',
nodes: [
{ label: 'testPlugin' }
]
})
})
test('plugins get a name from the function source if theres no other option', async (t) => {
t.plan(1)
const app = boot()
app.use((app, opts, next) => next())
await app.ready()
t.match(app.toJSON(), {
label: 'root',
nodes: [
{ label: '(app, opts, next) => next()' }
]
})
})

View File

@@ -0,0 +1,33 @@
'use strict'
/* eslint no-prototype-builtins: off */
const { test } = require('tap')
const boot = require('..')
test('do not load', async (t) => {
const app = boot({}, { timeout: 10 })
app.use(first)
async function first (s, opts) {
await s.use(second)
}
async function second (s, opts) {
await s.use(third)
}
function third (s, opts) {
return new Promise((resolve, reject) => {
// no resolve
})
}
try {
await app.start()
t.fail('should throw')
} catch (err) {
t.equal(err.message, 'Plugin did not start in time: \'third\'. You may have forgotten to call \'done\' function or to resolve a Promise')
}
})

218
backend/node_modules/avvio/test/plugin-timeout.test.js generated vendored Normal file
View File

@@ -0,0 +1,218 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
const message = (name) => `Plugin did not start in time: '${name}'. You may have forgotten to call 'done' function or to resolve a Promise`
test('timeout without calling next - callbacks', (t) => {
t.plan(4)
const app = boot({}, {
timeout: 10 // 10 ms
})
app.use(one)
function one (app, opts, next) {
// do not call next on purpose
}
app.ready((err) => {
t.ok(err)
t.equal(err.fn, one)
t.equal(err.message, message('one'))
t.equal(err.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
})
})
test('timeout without calling next - promises', (t) => {
t.plan(4)
const app = boot({}, {
timeout: 10 // 10 ms
})
app.use(two)
function two (app, opts) {
return new Promise(function (resolve) {
// do not call resolve on purpose
})
}
app.ready((err) => {
t.ok(err)
t.equal(err.fn, two)
t.equal(err.message, message('two'))
t.equal(err.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
})
})
test('timeout without calling next - use file as name', (t) => {
t.plan(3)
const app = boot({}, {
timeout: 10 // 10 ms
})
app.use(require('./fixtures/plugin-no-next'))
app.ready((err) => {
t.ok(err)
t.equal(err.message, message('noNext'))
t.equal(err.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
})
})
test('timeout without calling next - use code as name', (t) => {
t.plan(3)
const app = boot({}, {
timeout: 10 // 10 ms
})
app.use(function (app, opts, next) {
// do not call next on purpose - code as name
})
app.ready((err) => {
t.ok(err)
t.equal(err.message, message('function (app, opts, next) { -- // do not call next on purpose - code as name'))
t.equal(err.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
})
})
test('does not keep going', (t) => {
t.plan(2)
const app = boot({}, {
timeout: 10 // 10 ms
})
app.use(function three (app, opts, next) {
next(new Error('kaboom'))
})
app.ready((err) => {
t.ok(err)
t.equal(err.message, 'kaboom')
})
})
test('throw in override without autostart', (t) => {
t.plan(2)
const server = { my: 'server' }
const app = boot(server, {
timeout: 10,
autostart: false
})
app.override = function (s) {
throw new Error('kaboom')
}
app.use(function (s, opts, cb) {
t.fail('this is never reached')
})
setTimeout(function () {
app.ready((err) => {
t.ok(err)
t.equal(err.message, 'kaboom')
})
}, 20)
})
test('timeout without calling next in ready and ignoring the error', (t) => {
t.plan(11)
const app = boot({}, {
timeout: 10, // 10 ms
autostart: false
})
let preReady = false
app.use(function one (app, opts, next) {
t.pass('loaded')
app.ready(function readyOk (err, done) {
t.notOk(err)
t.pass('first ready called')
done()
})
next()
})
app.on('preReady', () => {
t.pass('preReady should be called')
preReady = true
})
app.on('start', () => {
t.pass('start should be called')
})
app.ready(function onReadyWithoutDone (err, done) {
t.pass('wrong ready called')
t.ok(preReady, 'preReady already called')
t.notOk(err)
// done() // Don't call done
})
app.ready(function onReadyTwo (err) {
t.ok(err)
t.equal(err.message, message('onReadyWithoutDone'))
t.equal(err.code, 'AVV_ERR_READY_TIMEOUT')
// don't rethrow the error
})
app.start()
})
test('timeout without calling next in ready and rethrowing the error', (t) => {
t.plan(11)
const app = boot({}, {
timeout: 10, // 10 ms
autostart: true
})
app.use(function one (app, opts, next) {
t.pass('loaded')
app.ready(function readyOk (err, done) {
t.ok(err)
t.equal(err.message, message('onReadyWithoutDone'))
t.equal(err.code, 'AVV_ERR_READY_TIMEOUT')
done(err)
})
next()
})
app.on('preReady', () => {
t.pass('preReady should be called')
})
app.on('start', () => {
t.pass('start should be called in any case')
})
app.ready(function onReadyWithoutDone (err, done) {
t.pass('wrong ready called')
t.notOk(err)
// done() // Don't call done
})
app.ready(function onReadyTwo (err, done) {
t.ok(err)
t.equal(err.message, message('onReadyWithoutDone'))
t.equal(err.code, 'AVV_ERR_READY_TIMEOUT')
done(err)
})
app.start()
})
test('nested timeout do not crash - await', (t) => {
t.plan(4)
const app = boot({}, {
timeout: 10 // 10 ms
})
app.use(one)
async function one (app, opts) {
await app.use(two)
}
function two (app, opts, next) {
// do not call next on purpose
}
app.ready((err) => {
t.ok(err)
t.equal(err.fn, two)
t.equal(err.message, message('two'))
t.equal(err.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
})
})

75
backend/node_modules/avvio/test/pretty-print.test.js generated vendored Normal file
View File

@@ -0,0 +1,75 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('pretty print', t => {
t.plan(19)
const app = boot()
app
.use(first)
.use(duplicate, { count: 3 })
.use(second).after(afterUse).after(after)
.use(duplicate, { count: 2 })
.use(third).after(after)
.use(duplicate, { count: 1 })
const linesExpected = [/^root \d+ ms$/,
/^├── first \d+ ms$/,
/^├─┬ duplicate \d+ ms$/,
/^│ └─┬ duplicate \d+ ms$/,
/^│ {3}└─┬ duplicate \d+ ms$/,
/^│ {5}└── duplicate \d+ ms$/,
/^├── second \d+ ms$/,
/^├─┬ bound _after \d+ ms$/,
/^│ └── afterInsider \d+ ms$/,
/^├── bound _after \d+ ms$/,
/^├─┬ duplicate \d+ ms$/,
/^│ └─┬ duplicate \d+ ms$/,
/^│ {3}└── duplicate \d+ ms$/,
/^├── third \d+ ms$/,
/^├── bound _after \d+ ms$/,
/^└─┬ duplicate \d+ ms$/,
/^ {2}└── duplicate \d+ ms$/,
''
]
app.on('preReady', function show () {
const print = app.prettyPrint()
const lines = print.split('\n')
t.equal(lines.length, linesExpected.length)
lines.forEach((l, i) => {
t.match(l, linesExpected[i])
})
})
function first (s, opts, done) {
done()
}
function second (s, opts, done) {
done()
}
function third (s, opts, done) {
done()
}
function after (err, cb) {
cb(err)
}
function afterUse (err, cb) {
app.use(afterInsider)
cb(err)
}
function afterInsider (s, opts, done) {
done()
}
function duplicate (instance, opts, cb) {
if (opts.count > 0) {
instance.use(duplicate, { count: opts.count - 1 })
}
setTimeout(cb, 20)
}
})

124
backend/node_modules/avvio/test/reentrant.test.js generated vendored Normal file
View File

@@ -0,0 +1,124 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('one level', (t) => {
t.plan(13)
const app = boot()
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
app.use(first)
app.use(third)
function first (s, opts, done) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
firstLoaded = true
s.use(second)
done()
}
function second (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
secondLoaded = true
done()
}
function third (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
thirdLoaded = true
done()
}
app.on('start', () => {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.pass('booted')
})
})
test('multiple reentrant plugin loading', (t) => {
t.plan(31)
const app = boot()
let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false
let fourthLoaded = false
let fifthLoaded = false
app.use(first)
app.use(fifth)
function first (s, opts, done) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
firstLoaded = true
s.use(second)
done()
}
function second (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
secondLoaded = true
s.use(third)
s.use(fourth)
done()
}
function third (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
thirdLoaded = true
done()
}
function fourth (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
fourthLoaded = true
done()
}
function fifth (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
fifthLoaded = true
done()
}
app.on('start', () => {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
t.ok(fifthLoaded, 'fifth is loaded')
t.pass('booted')
})
})

151
backend/node_modules/avvio/test/to-json.test.js generated vendored Normal file
View File

@@ -0,0 +1,151 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('to json', (t) => {
t.plan(4)
const app = boot()
app
.use(one)
.use(two)
.use(three)
const outJson = {
id: 'root',
label: 'root',
start: /\d+/,
nodes: []
}
app.on('preReady', function show () {
const json = app.toJSON()
outJson.stop = /\d*/
outJson.diff = /\d*/
t.match(json, outJson)
})
function one (s, opts, done) {
const json = app.toJSON()
outJson.nodes.push({
id: /.+/,
parent: outJson.label,
label: 'one',
start: /\d+/
})
t.match(json, outJson)
done()
}
function two (s, opts, done) {
const json = app.toJSON()
outJson.nodes.push({
id: /.+/,
parent: outJson.label,
label: 'two',
start: /\d+/
})
t.match(json, outJson)
done()
}
function three (s, opts, done) {
const json = app.toJSON()
outJson.nodes.push({
id: /.+/,
parent: outJson.label,
label: 'three',
start: /\d+/
})
t.match(json, outJson)
done()
}
})
test('to json multi-level hierarchy', (t) => {
t.plan(4)
const server = { name: 'asd', count: 0 }
const app = boot(server)
const outJson = {
id: 'root',
label: 'root',
start: /\d+/,
nodes: [
{
id: /.+/,
parent: 'root',
start: /\d+/,
label: 'first',
nodes: [
{
id: /.+/,
parent: 'first',
start: /\d+/,
label: 'second',
nodes: [],
stop: /\d+/,
diff: /\d+/
},
{
id: /.+/,
parent: 'first',
start: /\d+/,
label: 'third',
nodes: [
{
id: /.+/,
parent: 'third',
start: /\d+/,
label: 'fourth',
nodes: [],
stop: /\d+/,
diff: /\d+/
}
],
stop: /\d+/,
diff: /\d+/
}
],
stop: /\d+/,
diff: /\d+/
}
],
stop: /\d+/,
diff: /\d+/
}
app.on('preReady', function show () {
const json = app.toJSON()
t.match(json, outJson)
})
app.override = function (s) {
const res = Object.create(s)
res.count = res.count + 1
res.name = 'qwe'
return res
}
app.use(function first (s1, opts, cb) {
s1.use(second)
s1.use(third)
cb()
function second (s2, opts, cb) {
t.equal(s2.count, 2)
cb()
}
function third (s3, opts, cb) {
s3.use(fourth)
t.equal(s3.count, 2)
cb()
}
function fourth (s4, opts, cb) {
t.equal(s4.count, 3)
cb()
}
})
})

22
backend/node_modules/avvio/test/twice-done.test.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
'use strict'
const { test } = require('tap')
const boot = require('..')
test('calling done twice does not throw error', (t) => {
t.plan(2)
const app = boot()
app
.use(twiceDone)
.ready((err) => {
t.notOk(err, 'no error')
})
function twiceDone (s, opts, done) {
done()
done()
t.pass('did not throw')
}
})

411
backend/node_modules/avvio/test/types/index.ts generated vendored Normal file
View File

@@ -0,0 +1,411 @@
import * as avvio from "../../";
{
// avvio with no argument
const app = avvio();
app.override = (server, fn, options) => server;
app.use(
(server, opts, done) => {
server.use;
server.after;
server.ready;
server.on;
server.start;
server.override;
server.onClose;
server.close;
opts.mySuper;
done();
},
{ mySuper: "option" }
);
app.use(async (server, options) => {
server.use;
server.after;
server.ready;
server.on;
server.start;
server.override;
server.onClose;
server.close;
});
app.use(async (server, options) => {},
(server) => {
server.use;
server.after;
server.ready;
server.on;
server.start;
server.override;
server.onClose;
server.close;
});
app.after(err => {
if (err) throw err;
});
app.after((err: Error, done: Function) => {
done();
});
app.after((err: Error, context: avvio.context<null>, done: Function) => {
context.use;
context.after;
context.ready;
context.on;
context.start;
context.override;
context.onClose;
context.close;
done();
});
app.ready().then(context => {
context.use;
context.after;
context.ready;
context.on;
context.start;
context.override;
context.onClose;
context.close;
});
app.ready(err => {
if (err) throw err;
});
app.ready((err: Error, done: Function) => {
done();
});
app.ready((err: Error, context: avvio.context<null>, done: Function) => {
context.use;
context.after;
context.ready;
context.on;
context.start;
context.override;
context.onClose;
context.close;
done();
});
app.close(err => {
if (err) throw err;
});
app.close((err: Error, done: Function) => {
done();
});
app.close((err: Error, context: avvio.context<null>, done: Function) => {
context.use;
context.after;
context.ready;
context.on;
context.start;
context.override;
context.onClose;
context.close;
done();
});
app.onClose((context, done) => {
context.use;
context.after;
context.ready;
context.on;
context.start;
context.override;
context.onClose;
context.close;
done();
});
}
{
// avvio with done
const app = avvio(() => undefined);
app.use(
(server, opts, done) => {
server.use;
server.after;
server.ready;
server.on;
server.start;
server.override;
server.onClose;
server.close;
opts.mySuper;
done();
},
{ mySuper: "option" }
);
app.use(async (server, options) => {
server.use;
server.after;
server.ready;
server.on;
server.start;
server.override;
server.onClose;
server.close;
});
app.use(async (server, options) => {},
(server) => {
server.use;
server.after;
server.ready;
server.on;
server.start;
server.override;
server.onClose;
server.close;
});
app.after(err => {
if (err) throw err;
});
app.after((err: Error, done: Function) => {
done();
});
app.after((err: Error, context: avvio.context<null>, done: Function) => {
context.use;
context.after;
context.ready;
context.on;
context.start;
context.override;
context.onClose;
context.close;
done();
});
app.ready().then(context => {
context.use;
context.after;
context.ready;
context.on;
context.start;
context.override;
context.onClose;
context.close;
});
app.ready(err => {
if (err) throw err;
});
app.ready((err: Error, done: Function) => {
done();
});
app.ready((err: Error, context: avvio.context<null>, done: Function) => {
context.use;
context.after;
context.ready;
context.on;
context.start;
context.override;
context.onClose;
context.close;
done();
});
app.close(err => {
if (err) throw err;
});
app.close((err: Error, done: Function) => {
done();
});
app.close((err: Error, context: avvio.context<null>, done: Function) => {
context.use;
context.after;
context.ready;
context.on;
context.start;
context.override;
context.onClose;
context.close;
done();
});
app.onClose((context, done) => {
context.use;
context.after;
context.ready;
context.on;
context.start;
context.override;
context.onClose;
context.close;
done();
});
}
{
const server = { typescriptIs: "amazing" };
// avvio with server
const app = avvio(server);
app.use(
(server, opts, done) => {
server.use;
server.after;
server.ready;
server.typescriptIs;
opts.mySuper;
done();
},
{ mySuper: "option" }
);
app.use(async (server, options) => {
server.use;
server.after;
server.ready;
server.typescriptIs;
});
app.use(async (server, options) => {},
((server) => {
server.use;
server.after;
server.ready;
server.typescriptIs;
}));
app.after(err => {
if (err) throw err;
});
app.after((err: Error, done: Function) => {
done();
});
app.after(
(err: Error, context: avvio.context<typeof server>, done: Function) => {
context.use;
context.after;
context.ready;
context.typescriptIs;
done();
}
);
app.ready().then(context => {
context.use;
context.after;
context.ready;
context.typescriptIs;
});
app.ready(err => {
if (err) throw err;
});
app.ready((err: Error, done: Function) => {
done();
});
app.ready(
(err: Error, context: avvio.context<typeof server>, done: Function) => {
context.use;
context.after;
context.ready;
context.close;
context.onClose;
context.typescriptIs;
done();
}
);
app.close(err => {
if (err) throw err;
});
app.close((err: Error, done: Function) => {
done();
});
app.close(
(err: Error, context: avvio.context<typeof server>, done: Function) => {
context.use;
context.after;
context.ready;
context.close;
context.onClose;
context.typescriptIs;
done();
}
);
app.onClose((context, done) => {
context.use;
context.after;
context.ready;
context.close;
context.onClose;
context.typescriptIs;
done();
});
}
{
const server = { hello: "world" };
const options = {
autostart: false,
expose: { after: "after", ready: "ready", use: "use", close: "close", onClose : "onClose" },
timeout: 50000
};
// avvio with server and options
const app = avvio(server, options);
}
{
const server = { hello: "world" };
const options = {
autostart: false,
expose: { after: "after", ready: "ready", use: "use" }
};
// avvio with server, options and done callback
const app = avvio(server, options, () => undefined);
}
{
const app = avvio();
const plugin: avvio.Plugin<any, any> = async (): Promise<void> => {};
const promise = plugin(app, {}, undefined as any);
(promise instanceof Promise);
}

9
backend/node_modules/avvio/test/types/tsconfig.json generated vendored Normal file
View File

@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"noEmit": true,
"strict": true
},
"files": ["./index.ts"]
}