Skip to content

Commit bc1cc38

Browse files
committed
Core: Fix inaccurate test count in reporter output after re-run
When using the HTML Reporter to re-run a specific test, the summary would accurately report the number of assertions, but inaccurately report the number of tests. This was because the `Test.valid()` function, which decides whether the test will run and is where the testId re-run filter is applied, was called at different points with different state. Once it was called in the constructor when we pass it to the TestReport, and then again later at run-time to definitively decide whether to run it. The `valid()` function isn't meant to be able to change what it returns, but the first call could wrongly returns false because it observes that a `config.testId` filter is active, but `this.testId` is not yet assigned at this point in the constructor. Fixes #1687.
1 parent e04ec8a commit bc1cc38

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/test.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default function Test (settings) {
6666
// (Meaning the CI passes irregardless of the added tests).
6767
//
6868
// TODO: Make this an error in QUnit 3.0
69-
// throw new Error( "Unexpected new test after the run already ended" );
69+
// throw new Error( "Unexpected test after runEnd" );
7070
Logger.warn('Unexpected test after runEnd. This is unstable and will fail in QUnit 3.0.');
7171
return;
7272
}
@@ -75,6 +75,14 @@ export default function Test (settings) {
7575
throw new TypeError(`You must provide a callback to ${method}("${this.testName}")`);
7676
}
7777

78+
// Register unique strings
79+
for (let i = 0, l = this.module.tests; i < l.length; i++) {
80+
if (this.module.tests[i].name === this.testName) {
81+
this.testName += ' ';
82+
}
83+
}
84+
this.testId = generateHash(this.module.name, this.testName);
85+
7886
// No validation after this. Beyond this point, failures must be recorded as
7987
// a completed test with errors, instead of early bail out.
8088
// Otherwise, internals may be left in an inconsistent state.
@@ -94,15 +102,6 @@ export default function Test (settings) {
94102
valid: this.valid()
95103
});
96104

97-
// Register unique strings
98-
for (let i = 0, l = this.module.tests; i < l.length; i++) {
99-
if (this.module.tests[i].name === this.testName) {
100-
this.testName += ' ';
101-
}
102-
}
103-
104-
this.testId = generateHash(this.module.name, this.testName);
105-
106105
this.module.tests.push({
107106
name: this.testName,
108107
testId: this.testId,

test/cli/fixtures/expected/tap-outputs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ ok 1 test 2
632632
ok 2 module A > module B > test 1
633633
ok 3 module A > module C > test 2
634634
ok 4 module D > test 1
635-
1..0
636-
# pass 0
635+
1..4
636+
# pass 4
637637
# skip 0
638638
# todo 0
639639
# fail 0`,

0 commit comments

Comments
 (0)