-
-
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
Report skipped tests upon beforeEach hook failure #4233
base: main
Are you sure you want to change the base?
Conversation
4f28b5b
to
9bd10b3
Compare
7caf4f7
to
da95e71
Compare
bfe684c
to
bb10ce9
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.
wow, this is great. tests look good too. I don't see any major technical issues, and I think this is a good idea in general. mainly I'm concerned about the mismatch between our terminology and function names, as I've commented here. looking forward to your thoughts
@@ -449,9 +447,73 @@ setTimeout(function() { | |||
}, 5000); | |||
``` | |||
|
|||
### Failing Hooks | |||
|
|||
Upon a failing "before all", "before each" or "after each" hook, all remaining tests in the current suite and also its nested suites will be skipped. Skipped tests are included in the test results and marked as **skipped**. A skipped test is not considered a failed test. |
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, so we're differentiating between "skipped" and "pending"... I know these two concepts have been conflated.
|
||
describe('inner', function() { | ||
before(function() { | ||
// will be skipped |
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 think it's important to show (somehow) that order matters. In this case, the outer "before all" hook is run before the inner "before all" hook. If, instead, the inner hook threw, what would happen?
## Pending Tests | ||
|
||
"Pending"--as in "someone should write these test cases eventually"--test-cases are simply those _without_ a callback: | ||
"Pending" - as in "someone should write these test cases eventually" - test-cases are simply those _without_ a callback: |
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.
Is this an "EM DASH"? Ideally we should have something like smartypants that translates --
to —
. Maybe revert this?
@@ -462,7 +524,9 @@ describe('Array', function() { | |||
}); | |||
``` | |||
|
|||
Pending tests will be included in the test results, and marked as pending. A pending test is not considered a failed test. | |||
By appending `.skip()`, you may also tell Mocha to ignore a test: [inclusive tests](#inclusive-tests). |
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.
suggestion:
By appending `.skip()`, you may also tell Mocha to [ignore a test](#inclusive-tests).
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.
wait... I'm confused now. this.skip()
means "test is pending", not "test is skipped"?
I think we could be more clear here. For your consideration:
- Maybe we can, instead, make
this.skip()
report a test as skipped, andthis.pending()
report a test as pending. The behavior would be roughly similar (the test wouldn't get run), but the test would not be displayed as "pending" unless the user calledthis.pending()
instead ofthis.skip()
(likewise fordescribe.skip()
/describe.pending()
/it.skip()
/it.pending()
). This would be less of a breaking change than just trying to renameskip()
topending()
. - Maybe instead of calling them "skipped tests", as you introduce above, we can just use a different word. "Omitted" tests, maybe?
- This may be a good place to update the terminology we use elsewhere re: "inclusive" (
it.skip()
) and "exclusive" (it.only()
) tests. Those terms always felt vague to me. Instead of "inclusive", we could say "omitted", and instead of "exclusive", we could say "selected" or "picked" or something.
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.
The current situation (incl. this PR) is:
pending
: set by the user- test without callback:
it('some test')
- static:
it.skip()
ordescribe.skip()
- conditional:
this.skip()
- test without callback:
skipped
: test not run because of a failing hook
I haven't changed anything on the first item pending
. This mismatch between our terminology and function is an old problem. We could replace label pending
by label skipped
, but this would break a few third-party tools, reporters, ...
I certainly don't want to rename/add a new this.pending()
.
And the pending
part is out of this PR's scope.
The second label skipped
is new and is about failing hooks. We could rename it to "omitted" or "dropped" or whatever. Eg. Cypress and Mochawesome are using skipped
for tests omitted by failing hooks. That's why I have chosen skipped
. But yes, it is confusing.
We need two independent labels: pending (or we rename it to skipped) and a new one for hook-failed-omitted tests. So I need to know which name to chose.
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 bit of brainstorm:
My thoughts are, when I mark a test not to run, I want Mocha to ignore it, to disable it, to skip it, to omit it.
If it's skipped because of hook-failed, Mocha is skipping it, leaving out, or the test was unrun, unused, benched, called off, unprepared, dropped, withdrawn, canceled, halted. And some of this could apply to the previous case as well.
I think my favorites so far for hook-failed-omitted are called off
, canceled
, halted
. I think called off even best.
It could be interesting to amass a large number of these potential labels, and run a survey through users of Mocha to see how well they feel each of those words describes (from 1 to 10) those two cases. Not to base our choice on our opinion alone.
@@ -1641,7 +1705,7 @@ mocha.setup({ | |||
### Browser-specific Option(s) | |||
|
|||
Browser Mocha supports many, but not all [cli options](#command-line-usage). | |||
To use a [cli option](#command-line-usage) that contains a "-", please convert the option to camel-case, (eg. `check-leaks` to `checkLeaks`). | |||
To use a [cli option](#command-line-usage) that contains a "-", please convert the option to camel-case, (e.g. `check-leaks` to `checkLeaks`). |
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.
👍
if (err || test.isPending()) { | ||
if (test.isPending()) { | ||
if (self.forbidPending) { | ||
self.fail(test, new Error('Pending test forbidden'), true); |
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 should probably be an error with a code
as in lib/errors.js
@@ -726,8 +747,9 @@ Runner.prototype.runSuite = function(suite, fn) { | |||
} | |||
|
|||
this.emit(constants.EVENT_SUITE_BEGIN, (this.suite = suite)); | |||
suite.started = true; |
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.
if we have any more booleans on Suite
like this, we should consider a state
prop instead
|
||
function next(errSuite) { | ||
function nextSuite(errSuite) { |
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.
👍
@@ -840,7 +852,7 @@ Runner.prototype.uncaught = function(err) { | |||
|
|||
runnable.clearTimeout(); | |||
|
|||
if (runnable.isFailed()) { | |||
if (runnable.isFailed() || runnable.isSkipped()) { |
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.
pls update the debug
statement here
@@ -62,6 +62,7 @@ function Suite(title, parentContext, isRoot) { | |||
this.suites = []; | |||
this.tests = []; | |||
this.pending = false; | |||
this.skipped = false; |
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, so, if it's not possible to have this.pending && this.skipped === true
, then we should use a state
Per #1815 (comment), marking this and #4221 as |
Description
required: #4221
Before: a failing
beforeEach
hook ignores the three tests completely.After:
Description of the Change
EVENT_TEST_SKIPPED
test.state
:skipped
pending
test cases, but in color red.Applicable issues
#1955
#1815