mochajs / mocha

☕️ simple, flexible, fun javascript test framework for node.js & the browser
https://mochajs.org
MIT License
22.63k stars 3.02k forks source link

🚀 Feature: Add a `--clearscreen` option to go with `--watch` #2312

Open ScottFreeCode opened 8 years ago

ScottFreeCode commented 8 years ago

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.

dNitro commented 8 years ago

+1 for this feature

boneskull commented 8 years ago

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

erikmellum commented 7 years ago

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.

brennancheung commented 7 years ago

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.

boneskull commented 7 years ago

@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.

HoltMansfield commented 7 years ago

+1

justinmchase commented 6 years ago

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.

brentgreeff commented 5 years ago

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 mocha@6.1.4

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.

brentgreeff commented 5 years ago

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

justinmchase commented 5 years ago

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
brentgreeff commented 5 years ago

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

plroebuck commented 5 years ago

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...

justinmchase commented 5 years ago

@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.

justinmchase commented 5 years ago

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
mprinc commented 4 years ago

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

mocha --watch  --reporter mocha-clearscreen-reporter
yslpn commented 1 year ago

+

JoshuaKGoldberg commented 10 months ago

Seems reasonable to me. Maybe, --clear-screen since other Mocha CLI flags use kebab-case (--allow-uncaught, --async-only, etc.)?

Tangentially related: TypeScript had the opposite behavior at first (always clear by default), but then added in a --preserveWatchOutput flag: https://github.com/microsoft/TypeScript/issues/21295.

anodynos commented 9 months ago

I cant believe its 8 years and this is still a (wrong) thing!

JoshuaKGoldberg commented 9 months ago

I cant believe its 8 years and this is still a (wrong) thing!

Believe it, @anodynos 😉. Mocha is a community-run open source project. There's no company employing developers working on it. Until recently there wasn't a consistently active maintenance team for several years.

If you want this issue resolved, send a pull request to implement the feature yourself. Comments expressing unhappiness at the situation don't help the conversation and just spam everyone subscribed to the thread.

In the meantime, https://github.com/mochajs/mocha/issues/2312#issuecomment-488121898 and https://github.com/mochajs/mocha/issues/2312#issuecomment-641172258 include links to community-authored workarounds.