From ce214cb4c49b55c8dc75dcbc3c33450865fcb58b Mon Sep 17 00:00:00 2001 From: "Colin T.A. Gray" Date: Fri, 22 Nov 2024 23:36:33 -0500 Subject: [PATCH] Adds '--cls' option to clear screen between watch runs --- lib/cli.js | 7 +++++++ lib/reporters/default.js | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/lib/cli.js b/lib/cli.js index dd0c9feb2..d744e457a 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -91,6 +91,12 @@ const FLAGS = { description: 'Re-run tests when files change', type: 'boolean', }, + cls: { + alias: 'C', + coerce: coerceLastValue, + description: 'Clears the screen between test runs', + type: 'boolean', + }, }; export default async function loadCli() { // eslint-disable-line complexity @@ -465,6 +471,7 @@ export default async function loadCli() { // eslint-disable-line complexity reportStream: process.stdout, stdStream: process.stderr, watching: argv.watch, + cls: argv.cls, }); } diff --git a/lib/reporters/default.js b/lib/reporters/default.js index a70f24e4e..1ff1f25a6 100644 --- a/lib/reporters/default.js +++ b/lib/reporters/default.js @@ -73,12 +73,14 @@ export default class Reporter { stdStream, projectDir, watching, + cls, durationThreshold, }) { this.extensions = extensions; this.reportStream = reportStream; this.stdStream = stdStream; this.watching = watching; + this.cls = cls; this.relativeFile = file => { if (file.startsWith('file://')) { file = fileURLToPath(file); @@ -128,6 +130,10 @@ export default class Reporter { } startRun(plan) { + if (this.cls) { + this.lineWriter.write('\x1b[2J\x1b[H\x1b[3J'); + } + if (plan.bailWithoutReporting) { return; }