-
-
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
Print failures for pending/only forbidden #2874
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e2bb820
Test this.skip
ScottFreeCode dd34b2f
Test that something is printed
ScottFreeCode 262a17c
Add printout of failures
ScottFreeCode 89c7107
Simplify redundant lines
ScottFreeCode e0b785f
Fix linting errors
ScottFreeCode a0549d1
Test beforeEach skip
ScottFreeCode 2307511
Test before as well
ScottFreeCode 245c9cc
Also test suite skipped
ScottFreeCode 6cdfa05
Add test for suite marked only
ScottFreeCode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,6 +429,10 @@ Runner.prototype.runTest = function (fn) { | |
if (!test) { | ||
return; | ||
} | ||
if (this.forbidOnly && this.hasOnly) { | ||
fn(new Error('`.only` forbidden')); | ||
return; | ||
} | ||
if (this.asyncOnly) { | ||
test.asyncOnly = true; | ||
} | ||
|
@@ -529,7 +533,13 @@ Runner.prototype.runTests = function (suite, fn) { | |
} | ||
|
||
if (test.isPending()) { | ||
self.emit('pending', test); | ||
if (self.forbidPending) { | ||
test.isPending = alwaysFalse; | ||
self.fail(test, new Error('Pending test forbidden')); | ||
delete test.isPending; | ||
} else { | ||
self.emit('pending', test); | ||
} | ||
self.emit('test end', test); | ||
return next(); | ||
} | ||
|
@@ -538,7 +548,13 @@ Runner.prototype.runTests = function (suite, fn) { | |
self.emit('test', self.test = test); | ||
self.hookDown('beforeEach', function (err, errSuite) { | ||
if (test.isPending()) { | ||
self.emit('pending', test); | ||
if (self.forbidPending) { | ||
test.isPending = alwaysFalse; | ||
self.fail(test, new Error('Pending test forbidden')); | ||
delete test.isPending; | ||
} else { | ||
self.emit('pending', test); | ||
} | ||
self.emit('test end', test); | ||
return next(); | ||
} | ||
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. These two |
||
|
@@ -550,7 +566,9 @@ Runner.prototype.runTests = function (suite, fn) { | |
test = self.test; | ||
if (err) { | ||
var retry = test.currentRetry(); | ||
if (err instanceof Pending) { | ||
if (err instanceof Pending && self.forbidPending) { | ||
self.fail(test, new Error('Pending test forbidden')); | ||
} else if (err instanceof Pending) { | ||
test.pending = true; | ||
self.emit('pending', test); | ||
} else if (retry < test.retries()) { | ||
|
@@ -586,6 +604,10 @@ Runner.prototype.runTests = function (suite, fn) { | |
next(); | ||
}; | ||
|
||
function alwaysFalse () { | ||
return false; | ||
} | ||
|
||
/** | ||
* Run the given `suite` and invoke the callback `fn()` when complete. | ||
* | ||
|
@@ -820,12 +842,6 @@ Runner.prototype.run = function (fn) { | |
|
||
// callback | ||
this.on('end', function () { | ||
if (self.forbidOnly && self.hasOnly) { | ||
self.failures += self.stats.tests; | ||
} | ||
if (self.forbidPending) { | ||
self.failures += self.stats.pending; | ||
} | ||
debug('end'); | ||
process.removeListener('uncaughtException', uncaught); | ||
fn(self.failures); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
describe.only('forbid only - suite marked with only', function () { | ||
it('test1', function () {}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
test/integration/fixtures/options/forbid-pending/before-this.skip.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
describe('forbid pending - before calls `skip()`', function () { | ||
it('test', function () {}); | ||
before(function () { this.skip(); }); | ||
}); |
6 changes: 6 additions & 0 deletions
6
test/integration/fixtures/options/forbid-pending/beforeEach-this.skip.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
describe('forbid pending - beforeEach calls `skip()`', function () { | ||
it('test', function () {}); | ||
beforeEach(function () { this.skip(); }); | ||
}); |
5 changes: 5 additions & 0 deletions
5
test/integration/fixtures/options/forbid-pending/skip-suite.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
describe.skip('forbid pending - suite marked with skip', function () { | ||
it('test1', function () {}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
test/integration/fixtures/options/forbid-pending/this.skip.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
describe('forbid pending - test calls `skip()`', function () { | ||
it('test1', function () {}); | ||
it('test2', function () { this.skip(); }); | ||
it('test3', function () {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not entirely happy with this hack to circumvent
Runner.prototype.fail
's check that ignores pending tests based ontest.isPending()
, but I'm not sure if there's a better option. Any opinions would be appreciated, provided we can avoid stalling over the matter.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.
(Actually, I honestly wonder why
Runner.prototype.fail
needs to ignore pending tests. Wouldn't it be more correct not to call it on pending tests? Do we know where it's being called on pending tests so we could evaluate whether that could be adjusted instead?)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.
A pending test is a failure, because a pending test (a synchronous one, anyway) actually throws an exception. We catch that in the
Runnable
, then set the pending flag, then continue on to the "fail" handler inRunner
. At least, if memory serves...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.
And
Runner.prototype.fail
is what reporters depend on for events...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.
Hmm. The Pending exception is being handled in the
Runner
around line 533, in which apending
event is emitted instead of going to thefail
function at all. (Thefail
function ignores pending tests altogether, rather than emitting anything pending for them; hence the need to circumvent it in this line.)The
Runnable
is only throwing (and in one case passing todone
)Pending
exceptions, not catching any (it also only emits an "error" event, in the case thatdone
is called multiple times, so it's not handling the pending emission before sending an ignored error of some sort to theRunner
either).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.
Additionally, Coveralls indicates that the
fail
function's pending test ignore branch is never hit: https://coveralls.io/builds/11947829/source?filename=lib%2Frunner.js#L224 However, to confirm that we aren't just missing a test for this case, I'd have to go look at whether we have tests for all... five? six?... cases where tests can be pending:describe.skip
,it.skip
,it("title and no callback")
,this.skip
init
,this.skip
inbeforeEach
,this.skip
inbefore
...