Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/lib/node_modules/homebridge-config-ui-x/node_modules/avvio/test/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict'
const test = require('tap').test
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')
})
})
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0055 ]-- |