Skip to content

Conversation

@captainsafia
Copy link
Contributor

@captainsafiacaptainsafia commented Dec 1, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected 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 be
undefined 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 to
mimic this expected behavior.

@nodejs-github-botnodejs-github-bot added the test Issues and PRs related to the tests. label Dec 1, 2016
This adds tests for the case in which listeners() is invoked on a EventEmitter with no events.
@TrottTrott added the events Issues and PRs related to the events subsystem / EventEmitter. label Dec 1, 2016
Copy link
Member

@TrottTrott left a 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 ✅

@Trott
Copy link
Member

Trott commented Dec 1, 2016

CI: https://ci.nodejs.org/job/node-test-pull-request/5035/

@MylesBorins
Copy link
Contributor

LGTM IF ci is green

@Trott
Copy link
Member

Trott commented Dec 1, 2016

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/

captainsafia added a commit to captainsafia/node that referenced this pull request Dec 1, 2016
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.
@captainsafia
Copy link
ContributorAuthor

I added tests for the case explored in #9866 in which _events can be undefined without monkeypatching.

@Trott
Copy link
Member

Trott commented Dec 2, 2016

Thanks for adding the additional test! util.inherits() mutates its first argument. So I would prefer that either util.inherits() be moved right under the class statement or else that the class statement be moved to this block. Otherwise, there may be some surprises if we add another block at a later date that uses TestStream.

@captainsafia
Copy link
ContributorAuthor

@Trott: Great point! I've update the code.

@Trott
Copy link
Member

Trott commented Dec 2, 2016

Copy link
Member

@addaleaxaddaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM :)

Trott pushed a commit to Trott/io.js that referenced this pull request Dec 3, 2016
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
@Trott
Copy link
Member

Trott commented Dec 3, 2016

Landed in a912b79

@TrottTrott closed this Dec 3, 2016
addaleax pushed a commit that referenced this pull request Dec 5, 2016
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
@Fishrock123Fishrock123 mentioned this pull request Dec 5, 2016
2 tasks
jmdarling pushed a commit to jmdarling/node that referenced this pull request Dec 8, 2016
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
MylesBorins pushed a commit that referenced this pull request Dec 20, 2016
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
MylesBorins pushed a commit that referenced this pull request Dec 21, 2016
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
@MylesBorinsMylesBorins mentioned this pull request Dec 21, 2016
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eventsIssues and PRs related to the events subsystem / EventEmitter.testIssues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@captainsafia@Trott@MylesBorins@addaleax@lpinca@cjihrig@nodejs-github-bot