test: remove unused function arguments in async-hooks tests

Remove unused function arguments in three async-hooks tests and
improve test consistancy.

PR-URL: https://github.com/nodejs/node/pull/24406
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Simon Bruce 2018-11-17 15:58:39 +10:30 committed by Rich Trott
parent 97309030ef
commit 738e076556
3 changed files with 14 additions and 16 deletions

View File

@ -8,11 +8,11 @@ const { checkInvocations } = require('./hook-checks');
if (!common.isMainThread) if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs'); common.skip('Worker bootstrapping works differently -> different async IDs');
const p = new Promise(common.mustCall(function executor(resolve, reject) { const p = new Promise(common.mustCall(function executor(resolve) {
resolve(5); resolve(5);
})); }));
p.then(function afterresolution(val) { p.then(function afterResolution(val) {
assert.strictEqual(val, 5); assert.strictEqual(val, 5);
return val; return val;
}); });

View File

@ -13,24 +13,22 @@ const hooks = initHooks();
hooks.enable(); hooks.enable();
const p = (new Promise(common.mustCall(executor))); const p = new Promise(common.mustCall(executor));
p.then(afterresolution); p.then(function afterResolution(val) {
function executor(resolve, reject) {
const as = hooks.activitiesOfTypes('PROMISE');
assert.strictEqual(as.length, 1);
const a = as[0];
checkInvocations(a, { init: 1 }, 'while in promise executor');
resolve(5);
}
function afterresolution(val) {
assert.strictEqual(val, 5); assert.strictEqual(val, 5);
const as = hooks.activitiesOfTypes('PROMISE'); const as = hooks.activitiesOfTypes('PROMISE');
assert.strictEqual(as.length, 2); assert.strictEqual(as.length, 2);
checkInvocations(as[0], { init: 1 }, 'after resolution parent promise'); checkInvocations(as[0], { init: 1 }, 'after resolution parent promise');
checkInvocations(as[1], { init: 1, before: 1 }, checkInvocations(as[1], { init: 1, before: 1 },
'after resolution child promise'); 'after resolution child promise');
});
function executor(resolve) {
const as = hooks.activitiesOfTypes('PROMISE');
assert.strictEqual(as.length, 1);
const a = as[0];
checkInvocations(a, { init: 1 }, 'while in promise executor');
resolve(5);
} }
process.on('exit', onexit); process.on('exit', onexit);

View File

@ -5,7 +5,7 @@ const assert = require('assert');
const initHooks = require('./init-hooks'); const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks'); const { checkInvocations } = require('./hook-checks');
const p = new Promise(common.mustCall(function executor(resolve, reject) { const p = new Promise(common.mustCall(function executor(resolve) {
resolve(5); resolve(5);
})); }));
@ -13,7 +13,7 @@ const p = new Promise(common.mustCall(function executor(resolve, reject) {
const hooks = initHooks({ allowNoInit: true }); const hooks = initHooks({ allowNoInit: true });
hooks.enable(); hooks.enable();
p.then(function afterresolution(val) { p.then(function afterResolution(val) {
assert.strictEqual(val, 5); assert.strictEqual(val, 5);
const as = hooks.activitiesOfTypes('PROMISE'); const as = hooks.activitiesOfTypes('PROMISE');
assert.strictEqual(as.length, 1); assert.strictEqual(as.length, 1);