简体   繁体   中英

emacs compile for Javascript tests

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM