Mocha: Add a `--clearscreen` option to go with `--watch`

Created on 15 Jun 2016  路  15Comments  路  Source: mochajs/mocha

We should add a --clearscreen flag that clears the console before a test run, for use with --watch. This would be handy for reporters other than "min" (which has this effect built in and can be used as an example for implementation). It can currently be done with a global before hook, but that's clumsier than a flag would be (you have to go out of your way to set it up so that you can choose to include it or not as easily as if it were a flag) and could work incorrectly in the unlikely edge case that you have other global before hooks printing stuff.

Inspired by @AshCoolman on Gitter.

feature reporter

Most helpful comment

I want this feature too. Since I guess it has been decided that this won't be added, I just hacked it in by adding console.log('\x1Bc'); to the reporters directly.

Just edit node_modules/mocha/lib/reporters/ and add it manually where you see runner.on('start'....

Obviously it's not permanent, and has to be done for each repo, but it works well enough for me.

All 15 comments

+1 for this feature

A neat idea. I'm loathe to add anything to the "watch" functionality at this point though...

This would be a really great flag because I want to use --reporter min with --clearscreen false (or something similar). Right now using --reporter min always clears the screen and that does not work well for my needs.

I want this feature too. Since I guess it has been decided that this won't be added, I just hacked it in by adding console.log('\x1Bc'); to the reporters directly.

Just edit node_modules/mocha/lib/reporters/ and add it manually where you see runner.on('start'....

Obviously it's not permanent, and has to be done for each repo, but it works well enough for me.

@brennancheung I didn't decide it wasn't to be added :wink: I'd just rather avoid piling features ontop of an already problematic feature.

+1

Or another option would be, if adding a flag is too complicated, to make a new reporter, call it even-more-min, which does the exact same thing as min except for clearing the screen and setting the cursor.

I am running yarn mocha --recursive --watch --reporter min

This did not clear the screen when I saved a file
I upgraded mocha from 3.2.0 to [email protected]

this had no effect. Screen output is not cleared at all.

Coming from Rails where I run Guard all the time with clearing :on - I don't know if I can live without it.

This did not clear the screen when I saved a file

Actually it seems to add a full page of black space which is not the clear command

Maybe yarn blocks the clearing or translates it? I don't think this feature was ever implemented in mocha so the min reporter does still clear last I looked.

Try:

npx mocha --recursive --watch --reporter min

npx mocha --recursive --watch --reporter min
Same result unfortunately. - Must be something project specific - thx anyway.

This did not clear the screen when I saved a file

Actually it seems to add a full page of black space which is not the clear command

@brentgreeff , the "min" reporter does this when run begins:

process.stdout.write('\u001b[2J');

From this documentation on ANSI-X3.64-1979 terminal control sequences, the code above _should_ erase the entire display.

But I don't know the affect of --watch off top of my head...

@plroebuck That just watches for changes to files under test. When a file changes a new test run is kicked off and if you're using the min reporter the screen will be cleared before each test new run.

For posterity...

If you are still looking for a solution to the original problem in this thread, which was to use the min reporter but have it not clear the console, here's the solution I finally came up with:

I created the custom reporter called even-more-min which is a clone of min, sans clearing.

Install

npm install even-more-min --save-dev

Use

npx mocha --reporter even-more-min

This works for me: https://www.npmjs.com/package/mocha-clearscreen-reporter

mocha --watch  --reporter mocha-clearscreen-reporter
Was this page helpful?
0 / 5 - 0 ratings

Related issues

enigmatic00 picture enigmatic00  路  3Comments

adamhooper picture adamhooper  路  3Comments

delta62 picture delta62  路  3Comments

robertherber picture robertherber  路  3Comments

Aarbel picture Aarbel  路  3Comments