8000 feat: support for mode to show only failed output by mhweiner · Pull Request #14 · mhweiner/kizu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: support for mode to show only failed output #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ts-node

require('../dist/run');
require('../dist/cli');
85 changes: 52 additions & 33 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"node-tap"
],
"dependencies": {
"commander": "14.0.0",
"deep-object-diff": "^1.1.0",
"diff": "^5.0.0",
"kleur": "^4.1.4",
Expand Down
21 changes: 21 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {Command} from 'commander';
import {Flags, run} from './run';

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const packageJson = require('../package.json');
const program = new Command();

program
.name('kizu')
.version(packageJson.version, '-v, --version')
.description('⚫️ kizu\n\nAn easy-to-use, fast, and defensive Typescript/Javascript test runner designed to help you to write simple, readable, and maintainable tests.')
.option('--fail-only, -f', 'Only show failures in the output.', false)
.argument('<glob>', 'Glob pattern to match files to run tests on.')
.parse(process.argv);

const flags = program.opts() as Flags;
const filesGlob = program.args[0];

run(flags, filesGlob).catch(console.log.bind(console));


4 changes: 2 additions & 2 deletions src/getSpecFiles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import glob from 'tiny-glob';

export async function getSpecFiles() {
export async function getSpecFiles(arg: string) {

return glob(process.argv[2]);
return glob(arg);

}
21 changes: 16 additions & 5 deletions src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,40 @@ The following spec files do not have any attempted or completed tests:
${files.join(', ')}
`);

export function printResultsByFile(resultsByFile: TestResultsByFile) {
export function printResultsByFile(resultsByFile: TestResultsByFile, showOnlyFailures: boolean = false) {

const sortedResults = sortTestResults(resultsByFile);

for (const [filename, tests] of sortedResults) {

printFileResults(filename, tests);
printFileResults(filename, tests, showOnlyFailures);

}

}

export function printFileResults(filename: string, tests: TestResults[]) {
export function printFileResults(
filename: string,
tests: TestResults[],
showOnlyFailures: boolean = false
) {

const doesFileHaveFailures = tests.some((test) => !isTestPassing(test));
const header = `${kleur.underline().blue(filename)} ${doesFileHaveFailures ? failureSymbol : successSymbol}\n`;
const hasFailure = tests.some((test) => !isTestPassing(test));

if (showOnlyFailures && !hasFailure) return;

const header = `${kleur.underline().blue(filename)} ${hasFailure ? failureSymbol : successSymbol}\n`;

log(header);
tests.forEach(((test) => {

if (showOnlyFailures && isTestPassing(test)) return;

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

if (showOnlyFailures && assertion.pass) return;

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

Expand Down
15 changes: 8 additions & 7 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {getSpecFiles} from './getSpecFiles';
const testResultsByFile: TestResultsByFile = {};
let numCompletedTests = 0;

export type Flags = {
failOnly: boolean
};
export type TestResultsByFile = {[file: string]: TestResults[]};
export type FinalResults = {
numFiles: number
Expand All @@ -21,14 +24,14 @@ export type FinalResults = {

const status = ora();

async function start() {
export async function run(flags: Flags, filesGlob: string) {

const specFiles = await getSpecFiles();
const specFiles = await getSpecFiles(filesGlob);

console.log(`Found ${specFiles.length} spec files.\n`);
status.start('Running tests...');
await workerPool(specFiles, addTestResults);
finish(specFiles);
showResults(flags, specFiles);

}

Expand All @@ -45,16 +48,14 @@ function addTestResults(file: string, results: TestResults) {

}

function finish(specFiles: string[]) {
function showResults(flags: Flags, specFiles: string[]) {

status.stop();

const finalResults = calculateFinalResults(specFiles, testResultsByFile);

printResultsByFile(testResultsByFile);
printResultsByFile(testResultsByFile, flags.failOnly);
printSummary(finalResults);
if (shouldExitWithError(finalResults)) process.exit(1);

}

start().catch(console.log.bind(console));
0