From 6d63d0d12fc3f5745bc92310c10f1d382fa6d0d4 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Wed, 30 Nov 2016 22:04:28 -0600 Subject: [PATCH 1/3] test: increase coverage for lib/events.js This adds tests for the case in which listeners() is invoked on a EventEmitter with no events. --- test/parallel/test-event-emitter-listeners.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/parallel/test-event-emitter-listeners.js b/test/parallel/test-event-emitter-listeners.js index cfb2dafb121e03..1feadf41d3f6b4 100644 --- a/test/parallel/test-event-emitter-listeners.js +++ b/test/parallel/test-event-emitter-listeners.js @@ -49,3 +49,9 @@ function listener2() {} ee.once('foo', listener2); assert.deepStrictEqual(ee.listeners('foo'), [listener, listener2]); } + +{ + const ee = new events.EventEmitter(); + ee._events = undefined; + assert.deepStrictEqual(ee.listeners('foo'), []); +} From c5fd0619cefae7bc3ce0c8fd306c3ef9c7ee37c0 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Thu, 1 Dec 2016 15:49:40 -0600 Subject: [PATCH 2/3] test: add new test case for undefined _events This adds a new test case for the situation in which a class inherits from the EventEmitter but overrides the constructor in the EventEmitter so that the _events is never set. --- test/parallel/test-event-emitter-listeners.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/parallel/test-event-emitter-listeners.js b/test/parallel/test-event-emitter-listeners.js index 1feadf41d3f6b4..a789de8322f534 100644 --- a/test/parallel/test-event-emitter-listeners.js +++ b/test/parallel/test-event-emitter-listeners.js @@ -3,9 +3,11 @@ require('../common'); const assert = require('assert'); const events = require('events'); +const util = require('util'); function listener() {} function listener2() {} +class TestStream { constructor() { } } { const ee = new events.EventEmitter(); @@ -55,3 +57,9 @@ function listener2() {} ee._events = undefined; assert.deepStrictEqual(ee.listeners('foo'), []); } + +{ + util.inherits(TestStream, events.EventEmitter); + const s = new TestStream(); + assert.deepStrictEqual(s.listeners('foo'), []); +} From f6d8b1bf1252a48fdc099a4f81df46912e4eb245 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Thu, 1 Dec 2016 22:41:16 -0600 Subject: [PATCH 3/3] test: move TestStream inheritance modification --- test/parallel/test-event-emitter-listeners.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-event-emitter-listeners.js b/test/parallel/test-event-emitter-listeners.js index a789de8322f534..8aedd8fc3766bd 100644 --- a/test/parallel/test-event-emitter-listeners.js +++ b/test/parallel/test-event-emitter-listeners.js @@ -8,6 +8,7 @@ const util = require('util'); function listener() {} function listener2() {} class TestStream { constructor() { } } +util.inherits(TestStream, events.EventEmitter); { const ee = new events.EventEmitter(); @@ -59,7 +60,6 @@ class TestStream { constructor() { } } } { - util.inherits(TestStream, events.EventEmitter); const s = new TestStream(); assert.deepStrictEqual(s.listeners('foo'), []); }