Skip to content

Commit

Permalink
test: refactor to use getEventListeners in timers
Browse files Browse the repository at this point in the history
Use `getEventListeners` instead of `listenerCount` because nodejs#35991
was landed.

Refs: nodejs#35991
Refs: nodejs#36006
PR-URL: nodejs#47759
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Mestery <[email protected]>
  • Loading branch information
deokjinkim authored and MoLow committed Jul 6, 2023
1 parent 4b2a015 commit dedbeee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions test/parallel/test-timers-immediate-promisified.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}));
}

Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-timers-interval-promisified.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}));
}

Expand All @@ -139,15 +139,15 @@ 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) {
break;
}
}
assert.strictEqual(i, 2);
assert.strictEqual(signal.listenerCount('abort'), 0);
assert.strictEqual(getEventListeners(signal, 'abort').length, 0);
}

tryBreak().then(common.mustCall());
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-timers-timeout-promisified.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}));
}

Expand Down

0 comments on commit dedbeee

Please sign in to comment.