Comparing version 7.2.4 to 7.2.5
{ | ||
"name": "avvio", | ||
"version": "7.2.4", | ||
"version": "7.2.5", | ||
"description": "Asynchronous bootstrapping of Node applications", | ||
@@ -5,0 +5,0 @@ "main": "boot.js", |
@@ -52,3 +52,3 @@ 'use strict' | ||
this.isAfter = isAfter | ||
this.q = fastq(parent, loadPlugin, 1) | ||
this.q = fastq(parent, loadPluginNextTick, 1) | ||
this.q.pause() | ||
@@ -250,2 +250,9 @@ this._error = null | ||
// delays plugin loading until the next tick to ensure any bound `_after` callbacks have a chance | ||
// to run prior to executing the next plugin | ||
function loadPluginNextTick (toLoad, cb) { | ||
const parent = this | ||
process.nextTick(loadPlugin.bind(parent), toLoad, cb) | ||
} | ||
// loads a plugin | ||
@@ -252,0 +259,0 @@ function loadPlugin (toLoad, cb) { |
@@ -7,2 +7,4 @@ 'use strict' | ||
const sleep = promisify(setTimeout) | ||
const fs = require('fs').promises | ||
const path = require('path') | ||
@@ -284,2 +286,70 @@ test('await after - nested plugins with same tick callbacks', async (t) => { | ||
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) => { | ||
@@ -286,0 +356,0 @@ const app = {} |
'use strict' | ||
const { test } = require('tap') | ||
const { promisify } = require('util') | ||
const sleep = promisify(setTimeout) | ||
const boot = require('..') | ||
@@ -245,1 +247,27 @@ | ||
}) | ||
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') | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139804
42
4728
1