Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5bc130b

Browse filesBrowse files
Lxxyxdanielleadams
authored andcommitted
test: increase coverage for events
1. test EventEmitter.setMaxListeners with invalid listener count https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/events.js.html#L171 2. test EventEmitter.setMaxListeners with invalid emitter https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/events.js.html#L186 3. test getEventListeners with invalid emiiter Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/events.js.html#L706 4. test events.once with options: null Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/events.js.html#L712 5. add test case for inspect new Event() Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/internal/event_target.js.html#L111 6. add test case for insepct new EventTarget() Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/internal/event_target.js.html#L446 7. add test case for Event and EventTarget constructor name PR-URL: #36668 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent b764269 commit 5bc130b
Copy full SHA for 5bc130b

File tree

Expand file treeCollapse file tree

4 files changed

+64
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+64
-1
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-event-emitter-max-listeners.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-event-emitter-max-listeners.js
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,17 @@ for (const obj of throwsObjs) {
5656
}
5757

5858
e.emit('maxListeners');
59+
60+
{
61+
const { EventEmitter, defaultMaxListeners } = events;
62+
for (const obj of throwsObjs) {
63+
assert.throws(() => EventEmitter.setMaxListeners(obj), {
64+
code: 'ERR_OUT_OF_RANGE',
65+
});
66+
}
67+
68+
assert.throws(
69+
() => EventEmitter.setMaxListeners(defaultMaxListeners, 'INVALID_EMITTER'),
70+
{ code: 'ERR_INVALID_ARG_TYPE' }
71+
);
72+
}
Collapse file

‎test/parallel/test-events-once.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-events-once.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ async function onceAnEvent() {
2323
strictEqual(ee.listenerCount('myevent'), 0);
2424
}
2525

26+
async function onceAnEventWithNullOptions() {
27+
const ee = new EventEmitter();
28+
29+
process.nextTick(() => {
30+
ee.emit('myevent', 42);
31+
});
32+
33+
const [value] = await once(ee, 'myevent', null);
34+
strictEqual(value, 42);
35+
}
36+
37+
2638
async function onceAnEventWithTwoArgs() {
2739
const ee = new EventEmitter();
2840

@@ -195,6 +207,7 @@ async function eventTargetAbortSignalAfterEvent() {
195207

196208
Promise.all([
197209
onceAnEvent(),
210+
onceAnEventWithNullOptions(),
198211
onceAnEventWithTwoArgs(),
199212
catchesErrors(),
200213
stopListeningAfterCatchingError(),
Collapse file

‎test/parallel/test-events-static-geteventlisteners.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-events-static-geteventlisteners.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const common = require('../common');
44

55
const {
66
deepStrictEqual,
7+
throws
78
} = require('assert');
89

910
const { getEventListeners, EventEmitter } = require('events');
@@ -34,3 +35,9 @@ const { getEventListeners, EventEmitter } = require('events');
3435
deepStrictEqual(getEventListeners(target, 'bar'), []);
3536
deepStrictEqual(getEventListeners(target, 'baz'), [fn1]);
3637
}
38+
39+
{
40+
throws(() => {
41+
getEventListeners('INVALID_EMITTER');
42+
}, /ERR_INVALID_ARG_TYPE/);
43+
}
Collapse file

‎test/parallel/test-eventtarget.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-eventtarget.js
+30-1Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const {
1313

1414
const { once } = require('events');
1515

16-
const { promisify } = require('util');
16+
const { promisify, inspect } = require('util');
1717
const delay = promisify(setTimeout);
1818

1919
// The globals are defined.
@@ -541,3 +541,32 @@ let asyncTest = Promise.resolve();
541541
et.addEventListener('foo', listener);
542542
et.dispatchEvent(new Event('foo'));
543543
}
544+
545+
{
546+
const ev = new Event('test');
547+
const evConstructorName = inspect(ev, {
548+
depth: -1
549+
});
550+
strictEqual(evConstructorName, 'Event');
551+
552+
const inspectResult = inspect(ev, {
553+
depth: 1
554+
});
555+
ok(inspectResult.includes('Event'));
556+
}
557+
558+
{
559+
const et = new EventTarget();
560+
const inspectResult = inspect(et, {
561+
depth: 1
562+
});
563+
ok(inspectResult.includes('EventTarget'));
564+
}
565+
566+
{
567+
const ev = new Event('test');
568+
strictEqual(ev.constructor.name, 'Event');
569+
570+
const et = new EventTarget();
571+
strictEqual(et.constructor.name, 'EventTarget');
572+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.