From dedbeee33632e080416b0ee119cd3c15c3061e5e Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Wed, 3 May 2023 11:28:57 +0900 Subject: [PATCH] test: refactor to use `getEventListeners` in timers Use `getEventListeners` instead of `listenerCount` because #35991 was landed. Refs: https://github.com/nodejs/node/pull/35991 Refs: https://github.com/nodejs/node/pull/36006 PR-URL: https://github.com/nodejs/node/pull/47759 Reviewed-By: Daeyeon Jeong Reviewed-By: Benjamin Gruenbaum Reviewed-By: Mestery --- test/parallel/test-timers-immediate-promisified.js | 4 ++-- test/parallel/test-timers-interval-promisified.js | 10 +++++----- test/parallel/test-timers-timeout-promisified.js | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-timers-immediate-promisified.js b/test/parallel/test-timers-immediate-promisified.js index 5808312b564e48..b504ce1778e8d9 100644 --- a/test/parallel/test-timers-immediate-promisified.js +++ b/test/parallel/test-timers-immediate-promisified.js @@ -6,7 +6,7 @@ const timers = require('timers'); const { promisify } = require('util'); const child_process = require('child_process'); -// TODO(benjamingr) - refactor to use getEventListeners when #35991 lands +const { getEventListeners } = require('events'); const { NodeEventTarget } = require('internal/event_target'); const timerPromises = require('timers/promises'); @@ -60,7 +60,7 @@ process.on('multipleResolves', common.mustNotCall()); const signal = new NodeEventTarget(); signal.aborted = false; setPromiseImmediate(0, { signal }).finally(common.mustCall(() => { - assert.strictEqual(signal.listenerCount('abort'), 0); + assert.strictEqual(getEventListeners(signal, 'abort').length, 0); })); } diff --git a/test/parallel/test-timers-interval-promisified.js b/test/parallel/test-timers-interval-promisified.js index e6550445f142eb..46b977ff80a8ef 100644 --- a/test/parallel/test-timers-interval-promisified.js +++ b/test/parallel/test-timers-interval-promisified.js @@ -6,7 +6,7 @@ const timers = require('timers'); const { promisify } = require('util'); const child_process = require('child_process'); -// TODO(benjamingr) - refactor to use getEventListeners when #35991 lands +const { getEventListeners } = require('events'); const { NodeEventTarget } = require('internal/event_target'); const timerPromises = require('timers/promises'); @@ -122,10 +122,10 @@ process.on('multipleResolves', common.mustNotCall()); signal.aborted = false; const iterator = setInterval(1, undefined, { signal }); iterator.next().then(common.mustCall(() => { - assert.strictEqual(signal.listenerCount('abort'), 1); + assert.strictEqual(getEventListeners(signal, 'abort').length, 1); iterator.return(); })).finally(common.mustCall(() => { - assert.strictEqual(signal.listenerCount('abort'), 0); + assert.strictEqual(getEventListeners(signal, 'abort').length, 0); })); } @@ -139,7 +139,7 @@ process.on('multipleResolves', common.mustNotCall()); // eslint-disable-next-line no-unused-vars for await (const _ of iterator) { if (i === 0) { - assert.strictEqual(signal.listenerCount('abort'), 1); + assert.strictEqual(getEventListeners(signal, 'abort').length, 1); } i++; if (i === 2) { @@ -147,7 +147,7 @@ process.on('multipleResolves', common.mustNotCall()); } } assert.strictEqual(i, 2); - assert.strictEqual(signal.listenerCount('abort'), 0); + assert.strictEqual(getEventListeners(signal, 'abort').length, 0); } tryBreak().then(common.mustCall()); diff --git a/test/parallel/test-timers-timeout-promisified.js b/test/parallel/test-timers-timeout-promisified.js index 4e3881acec1ce2..95298c6a42977d 100644 --- a/test/parallel/test-timers-timeout-promisified.js +++ b/test/parallel/test-timers-timeout-promisified.js @@ -6,7 +6,7 @@ const timers = require('timers'); const { promisify } = require('util'); const child_process = require('child_process'); -// TODO(benjamingr) - refactor to use getEventListeners when #35991 lands +const { getEventListeners } = require('events'); const { NodeEventTarget } = require('internal/event_target'); const timerPromises = require('timers/promises'); @@ -60,7 +60,7 @@ process.on('multipleResolves', common.mustNotCall()); const signal = new NodeEventTarget(); signal.aborted = false; setPromiseTimeout(0, null, { signal }).finally(common.mustCall(() => { - assert.strictEqual(signal.listenerCount('abort'), 0); + assert.strictEqual(getEventListeners(signal, 'abort').length, 0); })); }