0

I'm using emacs to develop javascript (Node.js). Mocha for testing. I run mocha with make and here's my Makefile:

REPORTER=spec
MOCHA_OPTS=--ui bdd --timeout 2000 --colors

test:
    @NODE_ENV=test \
    ./node_modules/mocha/bin/mocha \
    --reporter $(REPORTER) \
    $(MOCHA_OPTS) \
    test/*.js

With emacs compile it runs the test nice but here's the output:

  #Category API
[0G    ✓ should create a category (378ms)
[0G    ✓ should get category list (282ms)
[0G    ✓ should get category (213ms)
[0G    ✓ should verify category permissions (211ms)
[0G    ✓ should edit category (454ms)
[0G    ✓ should verify category (218ms)
[0G    ✓ should remove category (242ms)

Is there any way to remove those ugly [0G from the output?

jvillasante
  • 89
  • 1
  • 5
  • Those `[0G` are probably part of escape sequences sent to Emacs, under the incorrect assumption that mocha is running in a terminal emulator, which is not the case. You could probably arrange for the compilation buffer to recognize those escape sequences and drop them. This said, why do you have `--colors` in your `MOCHA_OPTS`? This might be the reason why mocha sends those escape sequences. – Stefan Sep 15 '15 at 21:25
  • I think these are ansi escape sequences and what you're looking for is this: http://stackoverflow.com/questions/13397737/ansi-coloring-in-compilation-mode – andygavin Sep 15 '15 at 22:46
  • `--colors` is not a problem, I colorize the compilation buffer. Those escape sequences are the problem. I think I had to manually get rid of them. – jvillasante Sep 16 '15 at 14:23

1 Answers1

0

Mocha tries to detect whether it is running with a tty and if so it will allow the reporters to output ANSI sequences. Changing --colors to --no-colors would help but only partially. The fact is that some reporters try to move the tty cursor around and will still output ANSI sequences even with colors turned off. There is no flag to force Mocha to consider its output to be a non-tty. However, you can achieve the same result with:

$ mocha | cat

If you want a Makefile that won't output ANSI sequences when invoked inside Emacs but will work "normally" outside, you could do this:

REPORTER=spec
MOCHA_OPTS=--ui bdd --timeout 2000 $(if $(INSIDE_EMACS),--no-colors,--colors)

.PHONY: test
test:
    @NODE_ENV=test \
    ./node_modules/mocha/bin/mocha \
    --reporter $(REPORTER) \
    $(MOCHA_OPTS) \
    test/*.js $(and $(INSIDE_EMACS),| cat)

INSIDE_EMACS is defined by Emacs.

Louis
  • 146,715
  • 28
  • 274
  • 320
  • This work perfectly. One question though. This tests are ment to be run by the team and no one here uses emacs, is there a way to recognize that make is currently called inside emacs and add the `| cat` filter only inside emacs? Thank you for your answer. – jvillasante Sep 16 '15 at 14:26
  • I've edited my answer. Note that my earlier answer had a mistake: `--color` forces Mocha to output colors even if you use `| cat`. The makefile above takes care of this though by changing `MOCHA_OPTS`. – Louis Sep 16 '15 at 14:40