Skip to content

Commit

Permalink
Adds '--cls' option to clear screen between watch runs
Browse files Browse the repository at this point in the history
  • Loading branch information
colinta committed Nov 23, 2024
1 parent 024de32 commit 53642ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ const FLAGS = {
description: 'Re-run tests when files change',
type: 'boolean',
},
'clear-screen': {
alias: 'C',
coerce: coerceLastValue,
description: 'Clears the screen before every test run',
type: 'boolean',
},
};

export default async function loadCli() { // eslint-disable-line complexity
Expand Down Expand Up @@ -465,6 +471,7 @@ export default async function loadCli() { // eslint-disable-line complexity
reportStream: process.stdout,
stdStream: process.stderr,
watching: argv.watch,
clearScreen: argv['clear-screen'],
});
}

Expand Down
7 changes: 7 additions & 0 deletions lib/reporters/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'node:path';
import stream from 'node:stream';
import {fileURLToPath} from 'node:url';

import ansiEscapes from 'ansi-escapes';
import figures from 'figures';
import indentString from 'indent-string';
import plur from 'plur';
Expand Down Expand Up @@ -73,12 +74,14 @@ export default class Reporter {
stdStream,
projectDir,
watching,
clearScreen,
durationThreshold,
}) {
this.extensions = extensions;
this.reportStream = reportStream;
this.stdStream = stdStream;
this.watching = watching;
this.clearScreen = clearScreen;
this.relativeFile = file => {
if (file.startsWith('file://')) {
file = fileURLToPath(file);
Expand Down Expand Up @@ -128,6 +131,10 @@ export default class Reporter {
}

startRun(plan) {
if (this.clearScreen) {
this.lineWriter.write(ansiEscapes.clearTerminal);
}

Check warning on line 136 in lib/reporters/default.js

View check run for this annotation

Codecov / codecov/patch

lib/reporters/default.js#L135-L136

Added lines #L135 - L136 were not covered by tests

if (plan.bailWithoutReporting) {
return;
}
Expand Down

0 comments on commit 53642ae

Please sign in to comment.