Skip to content

Commit b4d48fc

Browse files
committed
CLI: Fix TAP compliance for actual/expected indent and skip/todo colors
Cherry-picked from adc4493 (3.0.0-dev).
1 parent ca5e5ac commit b4d48fc

9 files changed

+366
-38
lines changed

.github/workflows/coverage.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
runs-on: ubuntu-20.04
1010
env:
1111
PUPPETEER_DOWNLOAD_PATH: "${{ github.workspace }}/.puppeteer_download"
12+
FORCE_COLOR: "1"
1213
steps:
1314
- uses: actions/checkout@v4
1415

package-lock.json

+110-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
"requirejs": "^2.3.6",
8181
"rimraf": "^3.0.2",
8282
"rollup": "^2.79.1",
83-
"semver": "^7.6.2"
83+
"semver": "^7.6.2",
84+
"tap-parser": "11.0.2"
8485
},
8586
"scripts": {
8687
"build": "rollup -c && grunt copy:src-css",

src/reporters/TapReporter.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { annotateStacktrace } from '../core/stacktrace';
3535
* Objects with cyclical references will be stringifed as
3636
* "[Circular]" as they cannot otherwise be represented.
3737
*/
38-
function prettyYamlValue (value, indent = 4) {
38+
function prettyYamlValue (value, indent = 2) {
3939
if (value === undefined) {
4040
// Not supported in JSON/YAML, turn into string
4141
// and let the below output it as bare string.
@@ -94,7 +94,7 @@ function prettyYamlValue (value, indent = 4) {
9494

9595
// See also <https://yaml-multiline.info/>
9696
// Support IE 9-11: Avoid ES6 String#repeat
97-
const prefix = (new Array(indent + 1)).join(' ');
97+
const prefix = (new Array((indent * 2) + 1)).join(' ');
9898

9999
const trailingLinebreakMatch = value.match(/\n+$/);
100100
const trailingLinebreaks = trailingLinebreakMatch
@@ -126,8 +126,13 @@ function prettyYamlValue (value, indent = 4) {
126126
}
127127
}
128128

129+
const prefix = (new Array(indent + 1)).join(' ');
130+
129131
// Handle null, boolean, array, and object
130-
return JSON.stringify(decycledShallowClone(value), null, 2);
132+
return JSON.stringify(decycledShallowClone(value), null, 2)
133+
.split('\n')
134+
.map((line, i) => i === 0 ? line : prefix + line)
135+
.join('\n');
131136
}
132137

133138
/**
@@ -223,11 +228,11 @@ export default class TapReporter {
223228
this.log(`ok ${this.testCount} ${test.fullName.join(' > ')}`);
224229
} else if (test.status === 'skipped') {
225230
this.log(
226-
`ok ${this.testCount} ${kleur.yellow(`# SKIP ${test.fullName.join(' > ')}`)}`
231+
`ok ${this.testCount} ${kleur.yellow(test.fullName.join(' > '))} # SKIP`
227232
);
228233
} else if (test.status === 'todo') {
229234
this.log(
230-
`not ok ${this.testCount} ${kleur.cyan(`# TODO ${test.fullName.join(' > ')}`)}`
235+
`not ok ${this.testCount} ${kleur.cyan(test.fullName.join(' > '))} # TODO`
231236
);
232237
test.errors.forEach((error) => this.logAssertion(error, 'todo'));
233238
} else {

0 commit comments

Comments
 (0)