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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this down into the if (this.watching && !plan.firstRun) line below? It better connects clearScreen with watch mode plus maybe there's no need to clean the terminal on the first run? Or does that get weird?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had it somewhere down there to start, but then it occurred to me that --clear-screen without --watch had no effect at all, which simply felt "unhandled". Why not have it clear the screen? 🤔

Since then I've been actually using it without the watch flag just as often as with it.


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