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

test: expand test coverage of events.js and fs.js #10947

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
17 changes: 12 additions & 5 deletions test/parallel/test-event-emitter-num-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ const assert = require('assert');
const events = require('events');

const e = new events.EventEmitter();
const num_args_emited = [];
const num_args_emitted = [];

e.on('numArgs', function() {
const numArgs = arguments.length;
console.log('numArgs: ' + numArgs);
num_args_emited.push(numArgs);
num_args_emitted.push(numArgs);
});

console.log('start');
e.on('foo', function() {
num_args_emitted.push(arguments.length);
});

e.on('foo', function() {
num_args_emitted.push(arguments.length);
});

e.emit('numArgs');
e.emit('numArgs', null);
Expand All @@ -21,6 +26,8 @@ e.emit('numArgs', null, null, null);
e.emit('numArgs', null, null, null, null);
e.emit('numArgs', null, null, null, null, null);

e.emit('foo', null, null, null, null);

process.on('exit', function() {
assert.deepStrictEqual([0, 1, 2, 3, 4, 5], num_args_emited);
assert.deepStrictEqual([0, 1, 2, 3, 4, 5, 4, 4], num_args_emitted);
});
5 changes: 5 additions & 0 deletions test/parallel/test-event-emitter-remove-all-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ function listener() {}
ee.removeAllListeners('baz');
assert.strictEqual(ee.listeners('baz').length, 0);
}

{
const ee = new events.EventEmitter();
assert.deepStrictEqual(ee, ee.removeAllListeners());
}
6 changes: 6 additions & 0 deletions test/parallel/test-event-emitter-remove-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ function listener2() {}
ee.emit('hello');
}

{
const ee = new EventEmitter();

assert.deepStrictEqual(ee, ee.removeListener('foo', () => {}));
}

// Verify that the removed listener must be a function
assert.throws(() => {
const ee = new EventEmitter();
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-event-emitter-special-event-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const assert = require('assert');
const ee = new EventEmitter();
const handler = () => {};

assert.deepStrictEqual(ee.eventNames(), []);

assert.strictEqual(ee._events.hasOwnProperty, undefined);
assert.strictEqual(ee._events.toString, undefined);

Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-fs-read-file-assert-encoding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
require('../common');

const assert = require('assert');
const fs = require('fs');

const encoding = 'foo-8';
const filename = 'bar.txt';

assert.throws(
fs.readFile.bind(fs, filename, { encoding }, () => {}),
new RegExp(`Error: Unknown encoding: ${encoding}$`)
);