Karma: add an option to clear console when using autoWatch:true

Created on 4 Apr 2014  路  20Comments  路  Source: karma-runner/karma

This is based on http://stackoverflow.com/questions/22824255/karma-clear-screen-after-running-tests.

Simply adding this in watcher.js at line 91, makes this work (at least on windows). All that is left to do is add the options to the config and pass them to watcher.

var util = require('util');
util.print("\u001b[2J\u001b[0;0H");

Is this something we want to add? I think it's useful.

Maybe we should instead support a beforeRun script that people could use to do that instead.

A workaround is to create a clear-screen-reporter that just overrides this.onRunStart and does

this.onRunStart = function() {
   console.log("\u001b[2J\u001b[0;0H");
};
discuss help wanted backlog feature

Most helpful comment

Should add this feature

All 20 comments

A beforeRun would (imo) be an excellent thing to have.

+1

I like this. Agree with @fhur it should happen BEFORE run (not after).

This should be done in a reporter in onRunStart.
Progress reporter should do this by default.

Yup, +1 for this one as well

Is this going to happen? I'd love to see it. (Before run, not after.)

+1

+1

+1. The ability to clear the terminal screen after every test is so essential it should really have been included originally imo.

The above screen is what you want from test output, and for your re-run to have a point you should be able to see where the new behaviour started.

screen shot 2014-08-05 at 14 05 11

:+1:

Would like to see this happening also.

I like the plugin approach so I through together a small plugin for it at https://github.com/arthurc/karma-clear-screen-reporter as per @sylvain-hamel recommendation.

To install:

  1. npm install https://github.com/arthurc/karma-clear-screen-reporter/tarball/master
  2. Add "clear-screen" to the reporters configuration option in karma.conf.js.

Works excellent on OSX.

Awesome work @arthurc, basically you print console.log("\u001b[2J\u001b[0;0H"); is that an OS X specific string that clears the terminal? I know $ printf "\ec" works with bash.

Thanks, @fhur. I have only verified it on OSX but according to @sylvain-hamel the \u001b[2J\u001b[0;0H character combination should work on Windows :) Don't know about Linux either.

That character escape sequence is the literal 'clear' character. Should be os independent.

EDIT - And thank god @arthuc. I think I owe you my sanity.

Thanks @arthurc.

Closing due to inactivity

any change about this feature ?

@dignifiedquire Why close? It seems to be a very useful feature request.

@mgol because it is over 2 years old and nobody had expressed any interest anymore

Should add this feature

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schippie picture schippie  路  5Comments

kiramclean picture kiramclean  路  4Comments

donaldpipowitch picture donaldpipowitch  路  3Comments

ORESoftware picture ORESoftware  路  4Comments

jambonrose picture jambonrose  路  5Comments