1

Hiho,

I've got a problem with my Mocha configuration. I've got ES6 code which should be compiled by Babel and then I want to get coverage (in LCOV format) of this ES6 code.

My approach to this problem was to use mocha, mocha-lcov-reporter, babel and blanket packages. Code structure is:

-- src
----- ...
-- test
----- spec
-------- something.spec.js
-------- ...
----- blanket.js

Where specs are in test/spec directory (matches also *.spec.js pattern) and blanket.js is:

require('blanket')({
    pattern: require('path').join(__dirname, '..', 'src')
});

Command which I prepared is:

./node_modules/.bin/mocha $(find test -name '*.spec.js') --recursive --compilers js:babel/register -r test/blanket -R mocha-lcov-reporter

So, it should run Mocha tests for all *.spec.js files, compiling them by Babel and starting test/blanket.js file before.

After starting this command I get Error: Line 1: Unexpected reserved word error from esprima.js. When I run it without requiring test/blanket file it run without problems, but ofc I haven't coverage.

Has anyone tried to do so? Do you have any ideas how to do it?

John
  • 2,820
  • 3
  • 30
  • 50
Dawid Rusnak
  • 527
  • 3
  • 13

1 Answers1

2

Okey, problem already resolved, but without Babel (native ES6 instead); I've done it another way. I've used istanbul-harmony and mocha packages. Then the command is:

./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- $(find test -name '*.spec.js') -R spec -u exports
Dawid Rusnak
  • 527
  • 3
  • 13
  • You shouldn't even need `istanbul-harmony` at this point. See [this question](http://stackoverflow.com/questions/33621079/running-mocha-istanbul-babel) for more info. – boneskull Jul 26 '16 at 18:52