Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve the structure of the test-event-emitter-num-args file and use the node test runner #56671

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions test/parallel/test-event-emitter-num-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,31 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const assert = require('assert');
const events = require('events');
const common = require('../common');
const assert = require('node:assert');
const events = require('node:events');
const { test } = require('node:test');

const e = new events.EventEmitter();
const num_args_emitted = [];
[0, 1, 2, 3, 4, 5].forEach((number) => {
test(`eventEmitter.on registered callback correctly gets ${number} arguments`, () => {
const eventEmitter = new events.EventEmitter();

e.on('numArgs', function() {
const numArgs = arguments.length;
num_args_emitted.push(numArgs);
});

e.on('foo', function() {
num_args_emitted.push(arguments.length);
});
eventEmitter.on('numArgs', common.mustCall(function() {
assert.strictEqual(arguments.length, number);
}));

e.on('foo', function() {
num_args_emitted.push(arguments.length);
});
eventEmitter.emit('numArgs', ...new Array(number).fill(null));
});

e.emit('numArgs');
e.emit('numArgs', null);
e.emit('numArgs', null, null);
e.emit('numArgs', null, null, null);
e.emit('numArgs', null, null, null, null);
e.emit('numArgs', null, null, null, null, null);
test(`eventEmitter.on multiple registered callbacks correctly get ${number} arguments`, () => {
const eventEmitter = new events.EventEmitter();

e.emit('foo', null, null, null, null);
[0, 1, 2].forEach(function() {
eventEmitter.on('numArgs', common.mustCall(function() {
assert.strictEqual(arguments.length, number);
}));
});

process.on('exit', function() {
assert.deepStrictEqual(num_args_emitted, [0, 1, 2, 3, 4, 5, 4, 4]);
eventEmitter.emit('numArgs', ...new Array(number).fill(null));
});
});
Loading