From 53642ae6ce9174c148de7f962ebc79711875cb5c 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 | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/cli.js b/lib/cli.js index dd0c9feb2..8129b668e 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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 @@ -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'], }); } diff --git a/lib/reporters/default.js b/lib/reporters/default.js index a70f24e4e..14ec9e7f6 100644 --- a/lib/reporters/default.js +++ b/lib/reporters/default.js @@ -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'; @@ -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); @@ -128,6 +131,10 @@ export default class Reporter { } startRun(plan) { + if (this.clearScreen) { + this.lineWriter.write(ansiEscapes.clearTerminal); + } + if (plan.bailWithoutReporting) { return; }