-
Notifications
You must be signed in to change notification settings - Fork 30k
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: increase coverage for lib/events.js #9865
Conversation
This adds tests for the case in which listeners() is invoked on a EventEmitter with no events.
bb6db3d
to
6d63d0d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if CI is ✅
LGTM IF ci is green |
Two failed hosts look CI infra related, not related to this test. But because EVERYONE LOVES GREEN, let's try again: https://ci.nodejs.org/job/node-test-pull-request/5037/ |
In the process of creating nodejs#9865, it was discovered that the code checking whether or not events was defined was unnecessary because the only situation in which events would be undefined is if it is monkeypatched by an external entity. This should be removed in order to discourage this. If the test added in nodejs#9865 is merged, it will need to removed on merge of this commit.
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.
I added tests for the case explored in #9866 in which |
Thanks for adding the additional test! |
@Trott: Great point! I've update the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still LGTM :)
Adds tests for the case in which listeners() is invoked on a EventEmitter with no events. 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. PR-URL: nodejs#9865 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Landed in a912b79 |
Adds tests for the case in which listeners() is invoked on a EventEmitter with no events. 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. PR-URL: #9865 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Adds tests for the case in which listeners() is invoked on a EventEmitter with no events. 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. PR-URL: nodejs#9865 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Adds tests for the case in which listeners() is invoked on a EventEmitter with no events. 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. PR-URL: #9865 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Adds tests for the case in which listeners() is invoked on a EventEmitter with no events. 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. PR-URL: #9865 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
test, events
Description of change
This adds a test for the case in which listeners() is invoked on an
EventEmitter with no events.
Note that the EventEmitter does not allow
_events
to ever beundefined as it is instantiated in the initializer. The only situation in
which it might be undefined is if it is monkey-patched externally.
Because of this, the added tests monkey-patches
this._events
tomimic this expected behavior.