From 7764ea17b7a896118dc60b9984fcf4cfdd9b449e Mon Sep 17 00:00:00 2001 From: Mathieu Hofman <86499+mhofman@users.noreply.github.com> Date: Tue, 15 Mar 2022 19:05:12 -0700 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Richard Gibson --- packages/init/node-async_hooks.js | 6 +++--- packages/init/test/test-async_hooks.js | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/init/node-async_hooks.js b/packages/init/node-async_hooks.js index 2b35e65ea3..c7e04a2dc6 100644 --- a/packages/init/node-async_hooks.js +++ b/packages/init/node-async_hooks.js @@ -53,11 +53,12 @@ const findAsyncSymbolsFromPromiseCreateHook = () => { const bootstrapData = []; { + const bootstrapHookData = []; const bootstrapHook = createHook({ init(asyncId, type, triggerAsyncId, resource) { if (type !== 'PROMISE') return; // process._rawDebug('Bootstrap', asyncId, triggerAsyncId, resource); - bootstrapData.push({ asyncId, triggerAsyncId, resource }); + bootstrapHookData.push({ asyncId, triggerAsyncId, resource }); }, destroy(_asyncId) { // Needs to be present to trigger the addition of the destroyed symbol @@ -71,10 +72,9 @@ const findAsyncSymbolsFromPromiseCreateHook = () => { // In some versions of Node, async_hooks don't give access to the resource // itself, but to a "wrapper" which is basically hooks metadata for the promise - const promisesData = bootstrapData.filter( + const promisesData = bootstrapHookData.filter( ({ resource }) => Promise.resolve(resource) === resource, ); - bootstrapData.length = 0; const { length } = promisesData; if (length > 1) { // process._rawDebug('Found multiple potential candidates'); diff --git a/packages/init/test/test-async_hooks.js b/packages/init/test/test-async_hooks.js index 9cf7ce64d6..fa76f403ed 100644 --- a/packages/init/test/test-async_hooks.js +++ b/packages/init/test/test-async_hooks.js @@ -48,9 +48,7 @@ test('async_hooks Promise patch', async t => { // Create a promise with symbols attached const p3 = Promise.resolve(); - if (hasSymbols) { - t.truthy(Reflect.ownKeys(p3)); - } + t.is(Reflect.ownKeys(p3).length > 0, hasSymbols); return Promise.resolve().then(() => { resolve(8); @@ -62,9 +60,7 @@ test('async_hooks Promise patch', async t => { // node versions will fail and generate a new one because of an own check p1.then(() => {}); - if (hasSymbols) { - t.truthy(Reflect.ownKeys(ret)); - } + t.is(Reflect.ownKeys(ret).length > 0, hasSymbols); // testHooks.disable();