-
-
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
Changes from 10 commits
fe806f4
2e03e57
597597e
002c432
680b14f
aea7b65
3ad9fa3
31febbf
c149bdb
46cf90a
299cfa4
564b189
fe88c03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,20 +419,6 @@ Runner.prototype.fail = function(test, err, force) { | |
* @param {Error} err | ||
*/ | ||
Runner.prototype.failHook = function(hook, err) { | ||
hook.originalTitle = hook.originalTitle || hook.title; | ||
if (hook.ctx && hook.ctx.currentTest) { | ||
hook.title = | ||
hook.originalTitle + ' for ' + dQuote(hook.ctx.currentTest.title); | ||
} else { | ||
var parentTitle; | ||
if (hook.parent.title) { | ||
parentTitle = hook.parent.title; | ||
} else { | ||
parentTitle = hook.parent.root ? '{root}' : ''; | ||
} | ||
hook.title = hook.originalTitle + ' in ' + dQuote(parentTitle); | ||
} | ||
|
||
this.fail(hook, err); | ||
}; | ||
|
||
|
@@ -464,6 +450,8 @@ Runner.prototype.hook = function(name, fn) { | |
hook.ctx.currentTest = self.test; | ||
} | ||
|
||
setHookTitle(hook); | ||
|
||
hook.allowUncaught = self.allowUncaught; | ||
|
||
self.emit(constants.EVENT_HOOK_BEGIN, hook); | ||
|
@@ -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 commentThe 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 commentThe 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. |
||
next(++i); | ||
}); | ||
|
||
function setHookTitle(hook) { | ||
hook.originalTitle = hook.originalTitle || hook.title; | ||
if (hook.ctx && hook.ctx.currentTest) { | ||
hook.title = | ||
hook.originalTitle + ' for ' + dQuote(hook.ctx.currentTest.title); | ||
} else { | ||
var parentTitle; | ||
if (hook.parent.title) { | ||
parentTitle = hook.parent.title; | ||
} else { | ||
parentTitle = hook.parent.root ? '{root}' : ''; | ||
} | ||
hook.title = hook.originalTitle + ' in ' + dQuote(parentTitle); | ||
} | ||
} | ||
} | ||
|
||
Runner.immediately(function() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ describe('multiple calls to done()', function() { | |
expect(res.failures[0], 'to satisfy', { | ||
fullTitle: 'suite "before all" hook in "suite"', | ||
err: { | ||
message: /done\(\) called multiple times in hook <suite "before all" hook> of file.+multiple-done-before\.fixture\.js/ | ||
message: /done\(\) called multiple times in hook <suite "before all" hook in "suite"> of file.+multiple-done-before\.fixture\.js/ | ||
boneskull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}); | ||
}); | ||
|
@@ -119,20 +119,18 @@ describe('multiple calls to done()', function() { | |
}); | ||
|
||
it('correctly attributes the errors', function() { | ||
expect(res.failures, 'to satisfy', [ | ||
{ | ||
fullTitle: 'suite "before each" hook in "suite"', | ||
err: { | ||
message: /done\(\) called multiple times in hook <suite "before each" hook> of file.+multiple-done-before-each\.fixture\.js/ | ||
} | ||
}, | ||
{ | ||
fullTitle: 'suite "before each" hook in "suite"', | ||
err: { | ||
message: /done\(\) called multiple times in hook <suite "before each" hook> of file.+multiple-done-before-each\.fixture\.js/ | ||
} | ||
expect(res.failures[0], 'to equal', res.failures[1]); | ||
expect(res.failures[0], 'to satisfy', { | ||
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 commentThe 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 commentThe 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 commentThe 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 This happens because when a single test/hook has multiple failures, the first error is reused, and the |
||
{ | ||
code: 'ERR_MOCHA_MULTIPLE_DONE' | ||
} | ||
] | ||
} | ||
]); | ||
}); | ||
}); | ||
}); | ||
|
||
|
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 tofail
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.