mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Tests: add actual and expected messages to test reporter
Close gh-5443
This commit is contained in:
parent
60f11b58bf
commit
1e84908baf
@ -10,28 +10,28 @@ export function reportTest( test, reportId, { browser, headless } ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let message = `Test ${ test.status } on ${ chalk.yellow(
|
let message = `${ chalk.bold( `${ test.suiteName }: ${ test.name }` ) }`;
|
||||||
|
message += `\nTest ${ test.status } on ${ chalk.yellow(
|
||||||
getBrowserString( browser, headless )
|
getBrowserString( browser, headless )
|
||||||
) } (${ chalk.bold( reportId ) }).`;
|
) } (${ chalk.bold( reportId ) }).`;
|
||||||
message += `\n${ chalk.bold( `${ test.suiteName }: ${ test.name }` ) }`;
|
|
||||||
|
|
||||||
// Prefer failed assertions over error messages
|
// test.assertions only contains passed assertions;
|
||||||
if ( test.assertions.filter( ( a ) => !!a && !a.passed ).length ) {
|
// test.errors contains all failed asssertions
|
||||||
test.assertions.forEach( ( assertion, i ) => {
|
if ( test.errors.length ) {
|
||||||
if ( !assertion.passed ) {
|
|
||||||
message += `\n${ i + 1 }. ${ chalk.red( assertion.message ) }`;
|
|
||||||
message += `\n${ chalk.gray( assertion.stack ) }`;
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
} else if ( test.errors.length ) {
|
|
||||||
for ( const error of test.errors ) {
|
for ( const error of test.errors ) {
|
||||||
message += `\n${ chalk.red( error.message ) }`;
|
message += "\n";
|
||||||
|
message += `\n${ error.message }`;
|
||||||
message += `\n${ chalk.gray( error.stack ) }`;
|
message += `\n${ chalk.gray( error.stack ) }`;
|
||||||
|
if ( error.expected && error.actual ) {
|
||||||
|
message += `\nexpected: ${ JSON.stringify( error.expected ) }`;
|
||||||
|
message += `\nactual: ${ chalk.red( JSON.stringify( error.actual ) ) }`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log( "\n\n" + message );
|
console.log( "\n\n" + message );
|
||||||
|
|
||||||
|
// Only return failed messages
|
||||||
if ( test.status === "failed" ) {
|
if ( test.status === "failed" ) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user