pghalliday / grunt-mocha-test

https://www.npmjs.com/package/grunt-mocha-test
MIT License
362 stars 61 forks source link

Mocha exploded when generating coverage reports #129

Open joanvila opened 7 years ago

joanvila commented 7 years ago

I'm following the readme to generate the coverage reports. I have a grunt task like this:

mochaTest: {
    test: {...},
    coverage: {...}
}

As it is in the readme.

I also created the blanket.js file changing the src dir to lib dir as I am testing the js files that I have inside the lib dir.

The problem comes when I run the grunt task. It says to me:

Running "mochaTest:test" (mochaTest) task
>> Mocha exploded!
>> SyntaxError: Unexpected token (3:6)
>> ...

The problem seems to be in a javascript test file. In a require(../lib/jsfile.js). There, I'm requiring the actual js file from the lib folder to test.

Any thoughts on this? Thanks :)

pghalliday commented 7 years ago

I don't know if you copy pasted or if this is a transcribing issue but

require(../lib/jsfile.js)

should be

require('../lib/jsfile.js')

note the quotes as the path should be a string

joanvila commented 7 years ago

Yes, sorry, I was writting it manually here and I forgot the quotes. It's actually const endpointBuilder = require('../lib/endpoint-builder');. Also without the js extension.

However, when I run the tests without trying to generate the coverage report, they work fine.

Maybe I'm missing something about Blanket? I've only installed it as a dev dependency and created the coverage/blanket.js file.

joanvila commented 7 years ago

Looking at the open PR in the repo, I've seen some discussion around the 'use strict'. I'm using it everywhere. Is this a problem? I'm also using the const and let keywords for defining variables.

I have tried to remove all the use strict, const and let and now It's giving me a different error in the same line of the require:

SyntaxError: Assigning to rvalue (9:37)

Moving away this test, the rest of them are working now so it's a problem with the require. I must be doing something wrong. The only problem it's giving now to me is:

Running "mochaTest:coverage" (mochaTest) task
"html-cov" reporter not found

It seems that html-cov is not included any more in mocha https://github.com/mochajs/mocha/issues/2356

pghalliday commented 7 years ago

I don't think it would be related to use strict. And yes html-cov is no longer supported. I have been migrating everything to istanbul for coverage. At some point I'll change the docs here to recommend istanbul instead

joanvila commented 7 years ago

Perfect, meanwhile I'm using Istanbul with it's commands as a workaround while grunt-mocha-test is being updated :)

yuwu9145 commented 7 years ago

Can someone show a demo on how to generate coverage report withistanbul?