Skip to content

Commit

Permalink
feat: failing tests are now all grouped at bottom in output
Browse files Browse the repository at this point in the history
  • Loading branch information
mhweiner committed Aug 19, 2024
1 parent 87f0aa9 commit 6810c65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
37 changes: 20 additions & 17 deletions src/output.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import kleur from 'kleur';
import {TestResultsByFile, FinalResults} from './run';
import {isTestPassing} from './isTestPassing';
import {Assertion} from './test';
import {Assertion, TestResults} from './test';
import {deserializeError, ErrorObject} from 'serialize-error';

const log = console.log;
Expand All @@ -17,31 +17,34 @@ The following spec files do not have any attempted or completed tests:
${files.join(', ')}
`);

export function printFileResults(resultsByFile: TestResultsByFile) {
export function printResultsByFile(resultsByFile: TestResultsByFile) {

const files = Object.entries(resultsByFile);
const passedFiles = Object.entries(resultsByFile).filter(([, tests]) => tests.every(isTestPassing));
const failedFiles = Object.entries(resultsByFile).filter(([, tests]) => tests.some((test) => !isTestPassing(test)));

files.forEach((file) => {
passedFiles.forEach(([filename, tests]) => printFileResults(filename, tests));
failedFiles.forEach(([filename, tests]) => printFileResults(filename, tests));

const [filename, tests] = file;
const header = `${kleur.underline().blue(filename)}\n`;
}

export function printFileResults(filename: string, tests: TestResults[]) {

log(header);
tests.forEach(((test) => {
const header = `${kleur.underline().blue(filename)}\n`;

log(`${test.description} ${isTestPassing(test) ? successSymbol : failureSymbol}`);
test.assertions.forEach((assertion) => {
log(header);
tests.forEach(((test) => {

log(kleur.gray(` ${assertion.description} ${assertion.pass ? successSymbol : failureSymbol}`));
!assertion.pass && printFailedAssertionDiag(assertion);
log(`${test.description} ${isTestPassing(test) ? successSymbol : failureSymbol}`);
test.assertions.forEach((assertion) => {

});
test.error && printError(test.error);
log('');
log(kleur.gray(` ${assertion.description} ${assertion.pass ? successSymbol : failureSymbol}`));
!assertion.pass && printFailedAssertionDiag(assertion);

}));
});
test.error && printError(test.error);
log('');

});
}));

}

Expand Down
4 changes: 2 additions & 2 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {TestResults} from './test';
import ora from 'ora';
import {printFileResults, printSummary} from './output';
import {printResultsByFile, printSummary} from './output';
import {calculateFinalResults} from './calculateFinalResults';
import {workerPool} from './workerPool';
import {shouldExitWithError} from './shouldExitWithError';
Expand Down Expand Up @@ -49,7 +49,7 @@ function finish(specFiles: string[]) {

const finalResults = calculateFinalResults(specFiles, testResultsByFile);

printFileResults(testResultsByFile);
printResultsByFile(testResultsByFile);
printSummary(finalResults);
if (shouldExitWithError(finalResults)) process.exit(1);

Expand Down

0 comments on commit 6810c65

Please sign in to comment.