Spaces:
Runtime error
Runtime error
File size: 2,063 Bytes
23ac194 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | '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)
})
|