Tests: show any and all actual/expected values

Close gh-5448
This commit is contained in:
Timmy Willison 2024-03-15 17:44:05 -04:00 committed by GitHub
parent 44fb7fa220
commit f80e78ef3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,9 +21,11 @@ export function reportTest( test, reportId, { browser, headless } ) {
if ( test.errors.length ) { if ( test.errors.length ) {
for ( const error of test.errors ) { for ( const error of test.errors ) {
message += "\n"; message += "\n";
if ( error.message ) {
message += `\n${ error.message }`; message += `\n${ error.message }`;
}
message += `\n${ chalk.gray( error.stack ) }`; message += `\n${ chalk.gray( error.stack ) }`;
if ( error.expected && error.actual ) { if ( "expected" in error && "actual" in error ) {
message += `\nexpected: ${ JSON.stringify( error.expected ) }`; message += `\nexpected: ${ JSON.stringify( error.expected ) }`;
message += `\nactual: ${ JSON.stringify( error.actual ) }`; message += `\nactual: ${ JSON.stringify( error.actual ) }`;
let diff; let diff;
@ -54,6 +56,13 @@ export function reportTest( test, reportId, { browser, headless } ) {
} else { } else {
diff = [ { removed: true, value: `${ value }` } ]; diff = [ { removed: true, value: `${ value }` } ];
} }
} else if (
typeof error.expected === "boolean" &&
typeof error.actual === "boolean"
) {
// Show the actual boolean in red
diff = [ { removed: true, value: `${ error.actual }` } ];
} else { } else {
// Diff everything else as characters // Diff everything else as characters