Skip to content
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

Adds '--clear-screen' option to clear screen between watch runs #3355

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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 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 @@
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 @@
}

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