-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Fix infinite loop crash when mixing test.only() with module.only()
I noticed that the first branch of `addOnlyTest()` was uncovered in test coverage reports. In expanding the `only-module-then-test.js` fixture to cover this (by adding a late test.only call), which was originally added in #1658. I decided to also add an early test.only call to see what would happen. The outcome is irrelevant/ambigious, but it seemed worth observing. To my surprise, it created an infinite loop. This further convinces me that we should make "early errors" show up in the HTML Reporter (TODO added in 37f6e4b), and subsequently get rid of this re-entry hack. The TapReporter and QUnit CLI are already able to render early errors. The HtmlReporter not yet. It's not generally a priority imho, but, because "No tests" is a common scenario, if we utilize an early error to report it, that makes it a priority to support in HtmlReporter as otherwise there'd be no visible feedback for it. It's okay to have to pop open devtools when causing an early syntax error or something like that in your own code, but when using the UI to match no tests, there should at least be some kind of visible feedback and not a blank page.
- Loading branch information
Showing
6 changed files
with
105 additions
and
2 deletions.
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
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
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
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
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,58 @@ | ||
// This currently runs 0 tests because stuff cancels out. | ||
// The intent is ambigious and outcome doesn't really matter. | ||
// It's covered as regression test against a past crash: | ||
// | ||
// * module A: | ||
// - start module scope A | ||
// * test A1: | ||
// - queue A1 | ||
// * test.only A2: | ||
// - start "test" focus mode. | ||
// - clear queue (delete A1). | ||
// - queue A2 | ||
// * module.only B: | ||
// - start "module" focus mode. | ||
// - clear queue (delete A2). | ||
// - modify parent A to become "ignored". | ||
// - start child-module scope B | ||
// * test B1: | ||
// - ignored, because it's a non-only test and | ||
// we are in "focus" mode due to the earlier test.only. | ||
// thus the only test we would run is a "test.only" test, | ||
// inside a "module.only" block, which this file doesn't have any of. | ||
// * test A4: | ||
// - ignored | ||
// * ProcessingQueue.end: | ||
// - create new Error('No tests were run.') | ||
// - emit it via a dynamically created test | ||
// - despite forcing validTest=true, the added test (as of QUnit 2.21.0) is ignored | ||
// because it is a non-only test and we're in "focus" mode. | ||
// This causes an infinite loop between ProcessingQueue.end and ProcessingQueue.advance | ||
// because it thinks it ads a test, but doesn't. | ||
// This scenerio is surprising because the usual way to active "focused" test mode, | ||
// is by defining a test.only() case, in which case the queue by definition isn't | ||
// empty. Even if the test.only() case was skipped by a filter (or config.moduleId/testId) | ||
// this is taken care of by forcing validTest=true. | ||
|
||
QUnit.module('module A', function () { | ||
// ... start module scope A | ||
|
||
// ... queue A1 | ||
QUnit.test('test A1', function (assert) { | ||
assert.true(false, 'not run'); | ||
}); | ||
|
||
QUnit.test.only('test A2', function (assert) { | ||
assert.true(false, 'not run'); | ||
}); | ||
|
||
QUnit.module.only('module B', function () { | ||
QUnit.test('test B1', function (assert) { | ||
assert.true(true, 'run'); | ||
}); | ||
}); | ||
|
||
QUnit.test('test A4', function (assert) { | ||
assert.true(false, 'not run'); | ||
}); | ||
}); |
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,21 @@ | ||
# command: ["qunit", "only-test-only-module-mix.js"] | ||
|
||
TAP version 13 | ||
not ok 1 global failure | ||
--- | ||
message: No tests were run. | ||
severity: failed | ||
actual : undefined | ||
expected: undefined | ||
stack: | | ||
Error: No tests were run. | ||
at qunit.js | ||
at internal | ||
... | ||
1..3 | ||
# pass 2 | ||
# skip 0 | ||
# todo 0 | ||
# fail 1 | ||
|
||
# exit code: 1 |