0

Im attempting to make this Code Coverage functionality work from the Sails Documentation so from the project root I run

istanbul cover -x "**/config/**" _mocha -- --timeout 5000

Which returns

Unable to resolve file [_mocha]

So thinking maybe because I am using this generator something is different so I try to use a path that is what is fired when doing 'npm test'

istanbul cover test/bootstrap.js _mocha -- --timeout 5000

and I get

No coverage information was collected, exit without writing coverage information
…myprojectpath/test/bootstrap.js:1
import Sails from 'sails';
^^^^^^

I have little familiarity with Istanbul or mocha so I'm a little off in no man's land right now. For bonus points can someone tell me what the

-x

is doing?

*****EDIT*****

So using @MjZac suggestion below as the command line entry I was able to get it to work AFTER running

npm install -g mocha

However I notice my tests/generator might be more recent as it looks like ...

import Sails from 'sails';
import config from '../config/env/test';

let sails;

before(done => {

  Sails.lift(config, (error, server) => {
    if (error) return done(error);

    sails = server;
    done();
  });
});

after(done => sails.lower(done));

Which is now producing the exception

import Sails from 'sails';
^^^^^^

SyntaxError: Unexpected token import

Which I think is related to ES6 and istanbul?

maehue
  • 505
  • 10
  • 26

1 Answers1

0

I use following command to make coverage in my sails projects.

istanbul cover _mocha test/bootstrap.test.js test/**/*.js && istanbul report html

My project directory looks like

Project directory

My bootstrap.test.js bootstrap.test.js

MjZac
  • 3,476
  • 1
  • 17
  • 28
  • Your configuration looks identical to mine in fact the only difference is the file name ... mine is "test/bootstrap.js" - the bootstrap test file is also identical except that I put the 'timeout' into the mocha.opts file - I am still getting the message "Unable to resolve file [_mocha]" – maehue Dec 15 '15 at 15:13
  • do you have mocha installed? – MjZac Dec 16 '15 at 05:44
  • So this is a little embarrassing but I just now realized this generator is configured to use babel-node and isparta for coverage I think specifically because of ES6 - so I did not know what isparta was after running the generator and overlooked it as I was just attempting to follow the sails docs - thanks for your help – maehue Dec 16 '15 at 13:13