From 4674c0d1cbdaf1aadbe991b4c5f7063a70381f4f 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..fe6309742 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) { + process.stderr.write('\x1b[2J\x1b[H\x1b[3J'); + } + if (plan.bailWithoutReporting) { return; }