-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix #4348 #4383
Fix #4348 #4383
Conversation
@boneskull this is ready for review. |
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.
IMO we should not change the hook title like this:
- it's the one defined by the user and we have
Runnable#fullTitle
to get the title incl. all suites names. - does
grep
/fgrep
still work? - for
beforeAll
/afterAll
hooks, the suite defines the context and not a test. - we have no primary keys for our tests/hooks yet, e.g. for re-running specific tests. Maybe we should think about introducing ID's, using a string title for this purpose doesn't seem a good solution.
@@ -514,8 +502,25 @@ Runner.prototype.hook = function(name, fn) { | |||
} | |||
self.emit(constants.EVENT_HOOK_END, hook); | |||
delete hook.ctx.currentTest; | |||
setHookTitle(hook); |
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.
What is this for?
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.
When hook.ctx.currentTest is deleted, this changes the hook's title so that it no longer mentions the test case and only mentions the test suite. It affects the "multiple done calls" errors.
@juergba it sounds like you're saying that the title rewriting, which mocha is already doing, is bad. Do you want to submit an alternative PR which fixes that? Do we know why the current rewriting behavior was implemented? |
No, not bad. When a hook fails, normally no more related tests are executed. E.g. when a Actually I don't like how failing |
Right, so the current title rewriting is bad and should be changed. What's
the right approach for teams affected by #4348?
…On Tue, Jul 28, 2020, 1:33 PM Juerg B. ***@***.***> wrote:
No, not bad. When a hook fails, normally no more related tests are
executed. E.g. when a beforeAll hook fails, all corresponding tests
"disappear". Renaming such a failing hook is a different thing than
renaming all hooks. It's easier to identify the failing hook in the
reporter output like this.
Actually I don't like how failing beforeAll and afterAll hooks are
renamed, based on hook.ctx.currentTest.
Setting if (name === HOOK_TYPE_BEFORE_ALL) { hook.ctx.currentTest =
hook.parent.tests[0]; } ... is not really correct. The context should be
the suite not the first/last test. But this topic is out of scope and
should be checked carefully before changing anything.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#4383 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35ODA7FHWBGUSAW7WCNTR54DWBANCNFSM4PIDQ5WA>
.
|
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.
thanks! this looks good. the only blocker would be the wording on the unintelligible error message that I commented on. feel free to suggest whatever makes sense to you.
otherwise just a couple suggestions/comments.
fullTitle: 'suite "before each" hook in "suite"', | ||
err: { | ||
message: /done\(\) called multiple times in hook <suite "before each" hook in "suite"> of file.+multiple-done-before-each\.fixture\.js/, | ||
multiple: [ |
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.
this error object is weird, but I guess that's what it does.
you can combine this into a single assertion:
expect(res.failures[0], 'to equal', res.failures[1])
.and('to satisfy', {
// etc.
});
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.
(likewise the assertion(s) in the new test may be able to be combined this way)
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.
Yeah, you probably already know this, but I rewrote the assertion to point out that both items of the array actually refer to the same object. I can't do a ===
check in the tests, because it's been converted to/from JSON, so the assertions are running against 2 different parsed copies of the same object. Does 'to equal'
handle that? EDIT: disregard; I'm already using 'to equal' I see what you're saying.
This happens because when a single test/hook has multiple failures, the first error is reused, and the multiple
array is created to store the others. Ideally I think mocha should be creating a new "hookinvocation" instance for each time the hook runs, where each "hookinvocation" can store a reference to the test case it's paired to. But I don't think I'll have time for that size of code change.
lib/runner.js
Outdated
@@ -419,20 +419,6 @@ Runner.prototype.fail = function(test, err, force) { | |||
* @param {Error} err | |||
*/ | |||
Runner.prototype.failHook = function(hook, err) { |
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.
could probably just remove failHook
and replace its usage with calls directly to fail
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.
Will do.
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.
OK, n/m, LGTM unless you want to address my two suggestions (removing failHook
and updating the assertion/assertions)
@boneskull thanks, I think I addressed all your feedback and tests are passing. |
Requirements
Description of the Change
Rewrites a hook's title always, instead of only when the hook fails. Fixes issues described in #4348.
Alternate Designs
None
Why should this be in core?
It's a bug as described in #4348
Benefits
Bug is fixed
Possible Drawbacks
Any change is potentially breaking, even a bugfix.
Applicable issues
#4348