Skip to content

Commit 9a1fc05

Browse files
authored
CLI: Remove confusing expected: undefined from TAP for non-assert fail
== pushFailure == This was setting `actual: null` and, left expected unset/undefined. In HtmlReporter this idom was recognised to mean "don't show values", based on hasOwn for `expected`. This worked because QUnit.log() passes the internal assert result object as-is. In TAP output, this was not skipped because Test.js#logAssertion copies the object for the testEnd.errors array, and in doing so forges an `expected` property to exist no matter what, thus with an implied value of undefined. The hasOwn checks in TapReporter thus always evaluate to true. This meant TAP output for pushFailure() calls not only showed redundant actual/expected entries, but actively created confusion by setting them to different values, drawing attention to a supposed difference that has no meaning > actual: null > expected: undefined Fix by changing pushFailure to omit both actual and expected, and change the condition in both reporters to skip rendering of values based on both being strictly equal to `undefined`, instead of based on `hasOwn('expected')`. == onUncaughtException / `QUnit.on('error')` == For uncaught errors, we already omitted both actual and undefined, the HtmlReporter thus already skipped them (for the reason above), but in TAP output they showed, for the same reason as above as: > actual: undefined > expected: undefined Which, while not as actively confusing, is at least redundant. This is naturally fixed by the same change, which now omits this.
1 parent 62cc6d9 commit 9a1fc05

28 files changed

+18
-86
lines changed

docs/api/assert/pushResult.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Report the result of a custom assertion.
1818
| name | description |
1919
|------|-------------|
2020
| `data.result` (boolean) | Result of the assertion |
21-
| `data.actual` | Expression being tested |
22-
| `data.expected` | Known comparison value |
21+
| `data.actual` | Expression being tested (optional) |
22+
| `data.expected` | Known comparison value (optional) |
2323
| `data.message` (string or undefined) | Short description of the assertion |
2424

2525
## Examples

docs/resources/example-fail.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
});
1515
QUnit.test('banana', function (assert) {
1616
assert.true(true, 'foo');
17-
var sentence = 'This is actual.';
17+
const sentence = 'This is actual.';
1818
assert.equal(sentence, 'This is expected.', 'example sentence');
1919
assert.true(true, 'bar');
2020
assert.true(true, 'baz');

src/core/on-uncaught-exception.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { emit } from './events.js';
2525
*/
2626
export default function onUncaughtException (error) {
2727
if (config.current) {
28+
// This omits 'actual' and 'expected' (undefined)
2829
config.current.assert.pushResult({
2930
result: false,
3031
message: `global failure: ${errorString(error)}`,

src/core/reporters/HtmlReporter.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -842,11 +842,12 @@ export default class HtmlReporter {
842842
let actual;
843843

844844
// When pushFailure() is called, it is implied that no expected value
845-
// or diff should be shown. It does not set details.expected.
845+
// or diff should be shown, because both expected and actual as undefined.
846846
//
847847
// This must check details.expected existence. If it exists as undefined,
848848
// that's a regular assertion for which to render actual/expected and a diff.
849-
if (!details.result && hasOwn.call(details, 'expected')) {
849+
const showAnyValues = !details.result && (details.expected !== undefined || details.actual !== undefined);
850+
if (showAnyValues) {
850851
if (details.negative) {
851852
expected = 'NOT ' + dump.parse(details.expected);
852853
} else {

src/core/reporters/TapReporter.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { errorString } from '../utilities.js';
33
import { console } from '../globals.js';
44
import { annotateStacktrace } from '../stacktrace.js';
55

6-
const hasOwn = Object.prototype.hasOwnProperty;
7-
86
/**
97
* Format a given value into YAML.
108
*
@@ -259,11 +257,12 @@ export default class TapReporter {
259257
out += `\n message: ${prettyYamlValue(error.message || 'failed')}`;
260258
out += `\n severity: ${prettyYamlValue(severity || 'failed')}`;
261259

262-
if (hasOwn.call(error, 'actual')) {
260+
// When pushFailure() is used, actual/expected are initially unset but
261+
// eventually in Test#logAssertion, for testReport#pushAssertion, these are
262+
// forged into existence as undefined.
263+
const hasAny = (error.expected !== undefined || error.actual !== undefined);
264+
if (hasAny) {
263265
out += `\n actual : ${prettyYamlValue(error.actual)}`;
264-
}
265-
266-
if (hasOwn.call(error, 'expected')) {
267266
out += `\n expected: ${prettyYamlValue(error.expected)}`;
268267
}
269268

src/core/test.js

-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ Test.prototype = {
572572
this.pushResult({
573573
result: false,
574574
message: message || 'error',
575-
actual: null,
576575
source
577576
});
578577
},

test/cli/cli-main.js

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ not ok 2 slow
3939
---
4040
message: Test took longer than 7ms; test timed out.
4141
severity: failed
42-
actual : null
43-
expected: undefined
4442
stack: |
4543
at internal
4644
...

test/cli/fixtures/assert-expect-failure-step.tap.txt

-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ not ok 3 wrong [a little off]
77
---
88
message: Expected 2 assertions, but 1 were run
99
severity: failed
10-
actual : null
11-
expected: undefined
1210
stack: |
1311
at /qunit/test/cli/fixtures/assert-expect-failure-step.js:22:7
1412
at internal
@@ -17,8 +15,6 @@ not ok 4 wrong [way off]
1715
---
1816
message: Expected 5 assertions, but 1 were run
1917
severity: failed
20-
actual : null
21-
expected: undefined
2218
stack: |
2319
at /qunit/test/cli/fixtures/assert-expect-failure-step.js:30:7
2420
at internal
@@ -29,8 +25,6 @@ not ok 5 previously passing [once]
2925
Expected 4 assertions, but 2 were run.
3026
It looks like you are upgrading from QUnit 2. Steps no longer count as separate assertions. https://qunitjs.com/api/assert/expect/
3127
severity: failed
32-
actual : null
33-
expected: undefined
3428
stack: |
3529
at /qunit/test/cli/fixtures/assert-expect-failure-step.js:40:7
3630
at internal
@@ -41,8 +35,6 @@ not ok 6 previously passing [twice]
4135
Expected 9 assertions, but 4 were run.
4236
It looks like you are upgrading from QUnit 2. Steps no longer count as separate assertions. https://qunitjs.com/api/assert/expect/
4337
severity: failed
44-
actual : null
45-
expected: undefined
4638
stack: |
4739
at /qunit/test/cli/fixtures/assert-expect-failure-step.js:49:7
4840
at internal

test/cli/fixtures/assert-expect-failure.tap.txt

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ not ok 1 failing test
66
---
77
message: Expected 2 assertions, but 1 were run
88
severity: failed
9-
actual : null
10-
expected: undefined
119
stack: |
1210
at /qunit/test/cli/fixtures/assert-expect-failure.js:1:7
1311
at internal

test/cli/fixtures/assert-expect-no-assertions.tap.txt

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ not ok 1 no assertions
66
---
77
message: Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.
88
severity: failed
9-
actual : null
10-
expected: undefined
119
stack: |
1210
at /qunit/test/cli/fixtures/assert-expect-no-assertions.js:1:7
1311
at internal

test/cli/fixtures/async-test-throw.tap.txt

-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ not ok 1 throw early
55
---
66
message: "Promise rejected during \"throw early\": boo"
77
severity: failed
8-
actual : null
9-
expected: undefined
108
stack: |
119
Error: boo
1210
at /qunit/test/cli/fixtures/async-test-throw.js:2:9
@@ -15,8 +13,6 @@ not ok 2 throw late
1513
---
1614
message: "Promise rejected during \"throw late\": boo"
1715
severity: failed
18-
actual : null
19-
expected: undefined
2016
stack: |
2117
Error: boo
2218
at /qunit/test/cli/fixtures/async-test-throw.js:8:9
@@ -25,8 +21,6 @@ not ok 3 test with bad thenable
2521
---
2622
message: "Promise rejected during \"test with bad thenable\": boo"
2723
severity: failed
28-
actual : null
29-
expected: undefined
3024
stack: |
3125
Error: boo
3226
at /qunit/test/cli/fixtures/async-test-throw.js:16:13

test/cli/fixtures/config-noglobals-add.tap.txt

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ not ok 1 adds global var
66
---
77
message: Introduced global variable(s): dummyGlobal
88
severity: failed
9-
actual : null
10-
expected: undefined
119
stack: |
1210
at qunit.js
1311
...

test/cli/fixtures/config-noglobals-remove.tap.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ not ok 1 deletes global var
66
---
77
message: Deleted global variable(s): dummyGlobal
88
severity: failed
9-
actual : null
10-
expected: undefined
119
stack: |
1210
at qunit.js
1311
...
@@ -17,4 +15,4 @@ not ok 1 deletes global var
1715
# todo 0
1816
# fail 1
1917

20-
# exit code: 1
18+
# exit code: 1

test/cli/fixtures/config-notrycatch-hook-rejection.tap.txt

-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ not ok 1 example > passing test
66
---
77
message: global failure: bad things happen
88
severity: failed
9-
actual : undefined
10-
expected: undefined
119
stack: |
1210
at internal
1311
...
1412
---
1513
message: Test took longer than 1000ms; test timed out.
1614
severity: failed
17-
actual : null
18-
expected: undefined
1915
stack: |
2016
at internal
2117
...

test/cli/fixtures/config-notrycatch-test-rejection.tap.txt

-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ not ok 1 example > returns a rejected promise
66
---
77
message: global failure: bad things happen
88
severity: failed
9-
actual : undefined
10-
expected: undefined
119
stack: |
1210
at internal
1311
...
1412
---
1513
message: Test took longer than 1000ms; test timed out.
1614
severity: failed
17-
actual : null
18-
expected: undefined
1915
stack: |
2016
at internal
2117
...

test/cli/fixtures/config-requireExpects.tap.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ not ok 1 passing test
66
---
77
message: Expected number of assertions to be defined, but expect() was not called.
88
severity: failed
9-
actual : null
10-
expected: undefined
119
stack: |
1210
at /qunit/test/cli/fixtures/config-requireExpects.js:3:7
1311
at internal
@@ -18,4 +16,4 @@ not ok 1 passing test
1816
# todo 0
1917
# fail 1
2018

21-
# exit code: 1
19+
# exit code: 1

test/cli/fixtures/config-testTimeout.tap.txt

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ not ok 1 slow
66
---
77
message: Test took longer than 10ms; test timed out.
88
severity: failed
9-
actual : null
10-
expected: undefined
119
stack: |
1210
at internal
1311
...

test/cli/fixtures/done-after-timeout.tap.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ not ok 1 times out before scheduled done is called
66
---
77
message: Test took longer than 10ms; test timed out.
88
severity: failed
9-
actual : null
10-
expected: undefined
119
stack: |
1210
at internal
1311
...
@@ -17,4 +15,4 @@ not ok 1 times out before scheduled done is called
1715
# todo 0
1816
# fail 1
1917

20-
# exit code: 1
18+
# exit code: 1

test/cli/fixtures/drooling-done.tap.txt

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ not ok 1 Test A
99
at /qunit/test/cli/fixtures/drooling-done.js:5:7
1010
at internal
1111
severity: failed
12-
actual : null
13-
expected: undefined
1412
stack: |
1513
Error: this is an intentional error
1614
at /qunit/test/cli/fixtures/drooling-done.js:8:9

test/cli/fixtures/drooling-extra-done.tap.txt

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ not ok 2 Test B
1111
at /qunit/test/cli/fixtures/drooling-extra-done.js:13:7
1212
at internal
1313
severity: failed
14-
actual : null
15-
expected: undefined
1614
stack: |
1715
Error: Unexpected release of async pause during a different test.
1816
> Test: Test A [async #1]

test/cli/fixtures/hanging-test.tap.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# name: test that hangs
2-
# command: ["qunit","hanging-test.js"]
2+
# command: ["qunit", "hanging-test.js"]
33

44
TAP version 13
55
not ok 1 hanging
66
---
77
message: Test took longer than 3000ms; test timed out.
88
severity: failed
9-
actual : null
10-
expected: undefined
119
stack: |
1210
at internal
1311
...

test/cli/fixtures/hooks-global-throw.tap.txt

-12
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ not ok 1 global hook throws
55
---
66
message: Global beforeEach failed on global hook throws: Error: banana
77
severity: failed
8-
actual : null
9-
expected: undefined
108
stack: |
119
Error: banana
1210
at /qunit/test/cli/fixtures/hooks-global-throw.js:3:11
1311
...
1412
---
1513
message: Global afterEach failed on global hook throws: Error: apple
1614
severity: failed
17-
actual : null
18-
expected: undefined
1915
stack: |
2016
Error: apple
2117
at /qunit/test/cli/fixtures/hooks-global-throw.js:17:11
@@ -24,17 +20,13 @@ not ok 2 global hook rejects
2420
---
2521
message: "Promise rejected before \"global hook rejects\": banana"
2622
severity: failed
27-
actual : null
28-
expected: undefined
2923
stack: |
3024
Error: banana
3125
at /qunit/test/cli/fixtures/hooks-global-throw.js:5:27
3226
...
3327
---
3428
message: "Promise rejected after \"global hook rejects\": apple"
3529
severity: failed
36-
actual : null
37-
expected: undefined
3830
stack: |
3931
Error: apple
4032
at /qunit/test/cli/fixtures/hooks-global-throw.js:19:27
@@ -43,17 +35,13 @@ not ok 3 global hook with bad thenable
4335
---
4436
message: "Promise rejected before \"global hook with bad thenable\": global brocoli"
4537
severity: failed
46-
actual : null
47-
expected: undefined
4838
stack: |
4939
Error: global brocoli
5040
at /qunit/test/cli/fixtures/hooks-global-throw.js:9:15
5141
...
5242
---
5343
message: "Promise rejected after \"global hook with bad thenable\": global artichoke"
5444
severity: failed
55-
actual : null
56-
expected: undefined
5745
stack: |
5846
Error: global artichoke
5947
at /qunit/test/cli/fixtures/hooks-global-throw.js:23:15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# name: test with pending async after timeout
2-
# command: ["qunit","pending-async-after-timeout.js"]
2+
# command: ["qunit", "pending-async-after-timeout.js"]
33

44
TAP version 13
55
not ok 1 example
66
---
77
message: Test took longer than 10ms; test timed out.
88
severity: failed
9-
actual : null
10-
expected: undefined
119
stack: |
1210
at internal
1311
...
@@ -17,4 +15,4 @@ not ok 1 example
1715
# todo 0
1816
# fail 1
1917

20-
# exit code: 1
18+
# exit code: 1

test/cli/fixtures/timeout.tap.txt

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ not ok 1 timeout > first
66
---
77
message: Test took longer than 10ms; test timed out.
88
severity: failed
9-
actual : null
10-
expected: undefined
119
stack: |
1210
at internal
1311
...

test/cli/fixtures/too-many-done-calls.tap.txt

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ not ok 1 Test A
1010
at /qunit/test/cli/fixtures/too-many-done-calls.js:1:7
1111
at internal
1212
severity: failed
13-
actual : null
14-
expected: undefined
1513
stack: |
1614
Error: Tried to release async pause that was already released.
1715
> Test: Test A [async #1]

0 commit comments

Comments
 (0)