Skip to content

Commit

Permalink
CLI: Fix TAP compliance for actual/expected indent and skip/todo colors
Browse files Browse the repository at this point in the history
Cherry-picked from adc4493 (3.0.0-dev).
  • Loading branch information
Krinkle committed Jan 25, 2025
1 parent ca5e5ac commit 2a93ad0
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 38 deletions.
111 changes: 110 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"requirejs": "^2.3.6",
"rimraf": "^3.0.2",
"rollup": "^2.79.1",
"semver": "^7.6.2"
"semver": "^7.6.2",
"tap-parser": "11.0.2"
},
"scripts": {
"build": "rollup -c && grunt copy:src-css",
Expand Down
15 changes: 10 additions & 5 deletions src/reporters/TapReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { annotateStacktrace } from '../core/stacktrace';
* Objects with cyclical references will be stringifed as
* "[Circular]" as they cannot otherwise be represented.
*/
function prettyYamlValue (value, indent = 4) {
function prettyYamlValue (value, indent = 2) {
if (value === undefined) {
// Not supported in JSON/YAML, turn into string
// and let the below output it as bare string.
Expand Down Expand Up @@ -94,7 +94,7 @@ function prettyYamlValue (value, indent = 4) {

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

const trailingLinebreakMatch = value.match(/\n+$/);
const trailingLinebreaks = trailingLinebreakMatch
Expand Down Expand Up @@ -126,8 +126,13 @@ function prettyYamlValue (value, indent = 4) {
}
}

const prefix = (new Array(indent + 1)).join(' ');

// Handle null, boolean, array, and object
return JSON.stringify(decycledShallowClone(value), null, 2);
return JSON.stringify(decycledShallowClone(value), null, 2)
.split('\n')
.map((line, i) => i === 0 ? line : prefix + line)
.join('\n');
}

/**
Expand Down Expand Up @@ -223,11 +228,11 @@ export default class TapReporter {
this.log(`ok ${this.testCount} ${test.fullName.join(' > ')}`);
} else if (test.status === 'skipped') {
this.log(
`ok ${this.testCount} ${kleur.yellow(`# SKIP ${test.fullName.join(' > ')}`)}`
`ok ${this.testCount} ${kleur.yellow(test.fullName.join(' > '))} # SKIP`
);
} else if (test.status === 'todo') {
this.log(
`not ok ${this.testCount} ${kleur.cyan(`# TODO ${test.fullName.join(' > ')}`)}`
`not ok ${this.testCount} ${kleur.cyan(test.fullName.join(' > '))} # TODO`
);
test.errors.forEach((error) => this.logAssertion(error, 'todo'));
} else {
Expand Down
Loading

0 comments on commit 2a93ad0

Please sign in to comment.