Skip to content

Commit 5a8b347

Browse files
committed
CLI: Fix TAP compliance for colon in unquoted YAML diag
When an assertion message contained a colon followed by a space, and otherwise is a single line of ASCII characters, we formatted it as an unquoted string. This is invalid in YAML 1.2, and thus tap-parser would ignore the diagnostic block. This does not affect the TAP result itself (the test name and failure status are separate from this), and it does not affect the QUnit CLI output where the information is shown either way. When passing the CLI output to tap-parser (such as in QTap), it silently ignored the "diag" block containing the assertion message/actual/expected value, because it is not valid YAML. Note that YAML 1.2 does allow literal colons and hash tags in unquoted strings, when they are not followed by or preceded by a space, but I'm keeping our version simpler by erring toward quoted strings when these appear. Just because we could squeeze one more edge case with plain unquoted strings, doesn't mean we have to. This way keeps our format a bit more intuitive by making it predictable and easy to deduce why a string is quoted or not, based solely on the chars used and not based on obscure YAML internals. Ref https://yaml.org/spec/1.2.2/#733-plain-style
1 parent e114e63 commit 5a8b347

16 files changed

+54
-17
lines changed

src/core/reporters/TapReporter.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ function prettyYamlValue (value, indent = 2) {
6161
// cause data loss or invalid YAML syntax.
6262
//
6363
// - Quotes, escapes, line breaks, or JSON-like stuff.
64-
const rSpecialJson = /['"\\/[{}\]\r\n]/;
64+
// - Not allowed in YAML unquoted strings per https://yaml.org/spec/1.2.2/#733-plain-style
65+
// * ": " (colon followed by space)
66+
// * " #" (space followed by hash)
67+
const rSpecialJson = /['"\\/[{}\]\r\n|:#]/;
6568

6669
// - Characters that are special at the start of a YAML value
6770
const rSpecialYaml = /[-?:,[\]{}#&*!|=>'"%@`]/;

test/cli/TapReporter-to-TapParser.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,40 @@ QUnit.module('TapReporter-to-TapParser', hooks => {
118118
});
119119
});
120120

121+
QUnit.test('Quoting [colon]', async (assert) => {
122+
emitter.emit('runStart');
123+
emitter.emit('testEnd', {
124+
fullName: ['example'],
125+
status: 'failed',
126+
runtime: 0,
127+
errors: [{
128+
message: 'behold: the colon'
129+
}]
130+
});
131+
emitter.emit('runEnd', {
132+
testCounts: {
133+
total: 1,
134+
passed: 0,
135+
failed: 1,
136+
skipped: 0,
137+
todo: 0
138+
}
139+
});
140+
141+
assert.propContains(await getParseResult(), {
142+
ok: false,
143+
failures: [
144+
{
145+
ok: false,
146+
name: 'example',
147+
diag: {
148+
message: 'behold: the colon'
149+
}
150+
}
151+
]
152+
});
153+
});
154+
121155
QUnit.test('Deep equal failure', async (assert) => {
122156
emitter.emit('runStart');
123157
emitter.emit('testEnd', {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ not ok 1 Throws match > bad
66
---
77
message: match error
88
severity: failed
9-
actual : Error: Match me with a pattern
9+
actual : "Error: Match me with a pattern"
1010
expected: "/incorrect pattern/"
1111
stack: |
1212
at /qunit/test/cli/fixtures/assert-throws-failure.js:3:12

test/cli/fixtures/callbacks-rejected.tap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
TAP version 13
55
not ok 1 global failure
66
---
7-
message: Error: begin
7+
message: "Error: begin"
88
severity: failed
99
stack: |
1010
Error: begin

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
TAP version 13
55
not ok 1 adds global var
66
---
7-
message: Introduced global variable(s): dummyGlobal
7+
message: "Introduced global variable(s): dummyGlobal"
88
severity: failed
99
...
1010
1..1

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
TAP version 13
55
not ok 1 deletes global var
66
---
7-
message: Deleted global variable(s): dummyGlobal
7+
message: "Deleted global variable(s): dummyGlobal"
88
severity: failed
99
...
1010
1..1

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TAP version 13
44
FOUND Unhandled Rejection: bad things happen
55
not ok 1 example > passing test
66
---
7-
message: global failure: bad things happen
7+
message: "global failure: bad things happen"
88
severity: failed
99
stack: |
1010
at internal

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TAP version 13
44
FOUND Unhandled Rejection: bad things happen
55
not ok 1 example > returns a rejected promise
66
---
7-
message: global failure: bad things happen
7+
message: "global failure: bad things happen"
88
severity: failed
99
stack: |
1010
at internal

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
TAP version 13
44
not ok 1 global hook throws
55
---
6-
message: Global beforeEach failed on global hook throws: Error: banana
6+
message: "Global beforeEach failed on global hook throws: Error: banana"
77
severity: failed
88
stack: |
99
Error: banana
1010
at /qunit/test/cli/fixtures/hooks-global-throw.js:3:11
1111
...
1212
---
13-
message: Global afterEach failed on global hook throws: Error: apple
13+
message: "Global afterEach failed on global hook throws: Error: apple"
1414
severity: failed
1515
stack: |
1616
Error: apple

test/cli/fixtures/no-tests.tap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
TAP version 13
55
not ok 1 global failure
66
---
7-
message: Error: No tests were run.
7+
message: "Error: No tests were run."
88
severity: failed
99
stack: |
1010
Error: No tests were run.

0 commit comments

Comments
 (0)