From aee639ec38e649c77df4ee57d5b38b520cc336e2 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Fri, 25 Feb 2022 16:32:58 +0100 Subject: [PATCH] Revert "fix: delay plugin promise resolution until next tick (#173)" This reverts commit 15c4cd34f631034f950e750036014c43f0c1d394. --- plugin.js | 20 +++++++-------- test/await-after.test.js | 54 +--------------------------------------- test/fixtures/dummy.txt | 1 - 3 files changed, 10 insertions(+), 65 deletions(-) delete mode 100644 test/fixtures/dummy.txt diff --git a/plugin.js b/plugin.js index 1a263c4..2c93034 100644 --- a/plugin.js +++ b/plugin.js @@ -149,18 +149,16 @@ Plugin.prototype.loadedSoFar = function () { this._error = err this.q.pause() - process.nextTick(() => { - if (err) { - debug('rejecting promise', this.name, err) - this._promise.reject(err) - } else { - debug('resolving promise', this.name) - this._promise.resolve() - } - this._promise = null + if (err) { + debug('rejecting promise', this.name, err) + this._promise.reject(err) + } else { + debug('resolving promise', this.name) + this._promise.resolve() + } + this._promise = null - process.nextTick(cb, err) - }) + process.nextTick(cb, err) }) this.q.resume() } diff --git a/test/await-after.test.js b/test/await-after.test.js index 65ef569..653cdb4 100644 --- a/test/await-after.test.js +++ b/test/await-after.test.js @@ -4,8 +4,6 @@ const { test } = require('tap') const boot = require('..') const { promisify } = require('util') const sleep = promisify(setTimeout) -const fs = require('fs').promises -const path = require('path') test('await after - nested plugins with same tick callbacks', async (t) => { const app = {} @@ -275,7 +273,7 @@ test('await after complex scenario', async (t) => { t.notOk(fourthLoaded, 'fourth is not loaded') app.use(second) t.ok(firstLoaded, 'first is loaded') - t.ok(secondLoaded, 'second 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) @@ -308,56 +306,6 @@ test('await after complex scenario', async (t) => { } }) -test('without autostart and sync/async plugin mix', async (t) => { - const app = {} - boot(app, { autostart: false }) - t.plan(11) - - let firstLoaded = false - let secondLoaded = false - let thirdLoaded = 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') - - const contents = await fs.readFile(path.join(__dirname, 'fixtures', 'dummy.txt'), 'utf-8') - t.equal(contents, 'hello, world!') - - 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') - - 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') - - 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 (app) { - await sleep(10) - thirdLoaded = true - } -}) - test('without autostart', async (t) => { const app = {} boot(app, { autostart: false }) diff --git a/test/fixtures/dummy.txt b/test/fixtures/dummy.txt deleted file mode 100644 index 30f51a3..0000000 --- a/test/fixtures/dummy.txt +++ /dev/null @@ -1 +0,0 @@ -hello, world! \ No newline at end of file