Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Running mocha with istanbul ignores the --use_strict option #538

Closed
vitorbaptista opened this issue Feb 12, 2016 · 2 comments
Closed

Running mocha with istanbul ignores the --use_strict option #538

vitorbaptista opened this issue Feb 12, 2016 · 2 comments

Comments

@vitorbaptista
Copy link

I have the following structure:

test
    mocha.opts
    sum.js
package.json

mocha.opts just has --use_strict. sum.js has:

const assert = require('assert');

it('foo', () => {
  let result = 4;
  assert(2 + 2 == result);
});

In my package.json, I've added:

"scripts": {
    "test": "mocha",
    "coverage": "istanbul cover _mocha"
}

If I run npm test, everything works fine. If I run npm run coverage, I get:

> [email protected] coverage /tmp/foo
> istanbul cover _mocha

No coverage information was collected, exit without writing coverage information
/tmp/foo/test/sum.js:4
  let result = 4;
  ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Object.Module._extensions.(anonymous function) [as .js] (/tmp/foo/node_modules/istanbul/lib/hook.js:109:37)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at /tmp/foo/node_modules/mocha/lib/mocha.js:219:27
    at Array.forEach (native)
    at Mocha.loadFiles (/tmp/foo/node_modules/mocha/lib/mocha.js:216:14)
    at Mocha.run (/tmp/foo/node_modules/mocha/lib/mocha.js:468:10)
    at Object.<anonymous> (/tmp/foo/node_modules/mocha/bin/_mocha:403:18)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Object.Module._extensions.(anonymous function) [as .js] (/tmp/foo/node_modules/istanbul/lib/hook.js:109:37)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at runFn (/tmp/foo/node_modules/istanbul/lib/command/common/run-with-cover.js:122:16)
    at /tmp/foo/node_modules/istanbul/lib/command/common/run-with-cover.js:251:17
    at /tmp/foo/node_modules/istanbul/lib/util/file-matcher.js:68:16
    at /tmp/foo/node_modules/async/lib/async.js:52:16
    at /tmp/foo/node_modules/async/lib/async.js:361:13
    at /tmp/foo/node_modules/async/lib/async.js:52:16
    at async.forEachOf.async.eachOf (/tmp/foo/node_modules/async/lib/async.js:236:30)
    at _asyncMap (/tmp/foo/node_modules/async/lib/async.js:355:9)
    at Object.map (/tmp/foo/node_modules/async/lib/async.js:337:20)
    at /tmp/foo/node_modules/istanbul/lib/util/file-matcher.js:44:15
    at Object.next (/tmp/foo/node_modules/fileset/lib/fileset.js:43:14)
    at emitOne (events.js:90:13)
    at Fileset.emit (events.js:182:7)
    at Fileset.Glob._finish (/tmp/foo/node_modules/glob/glob.js:172:8)
    at done (/tmp/foo/node_modules/glob/glob.js:159:12)
    at Fileset.Glob._processGlobStar2 (/tmp/foo/node_modules/glob/glob.js:601:12)
    at /tmp/foo/node_modules/glob/glob.js:590:10
    at RES (/tmp/foo/node_modules/inflight/inflight.js:23:14)
    at f (/tmp/foo/node_modules/once/once.js:17:25)
    at lstatcb_ (/tmp/foo/node_modules/glob/glob.js:491:7)
    at RES (/tmp/foo/node_modules/inflight/inflight.js:23:14)
    at f (/tmp/foo/node_modules/once/once.js:17:25)
    at FSReqWrap.oncomplete (fs.js:82:15)

I'm running [email protected] and [email protected] with NodeJS 5.5.0.

If I change my coverage script to run node --use_strict ./node_modules/.bin/istanbul cover _mocha, everything runs fine.

This seems related to #44.

vitorbaptista added a commit to opentrials/api that referenced this issue Feb 12, 2016
This seems like a bug in istanbul. I've created an issue at
gotwarlost/istanbul#538.
vitorbaptista added a commit to opentrials/opentrials that referenced this issue Feb 12, 2016
This seems like a bug in istanbul. I've created an issue at
gotwarlost/istanbul#538.
@gotwarlost
Copy link
Owner

Yup, that's the correct fix. And not, it's not a bug. The way mocha works is that it accepts all sorts of options and then launches a subprocess with those options enabled for the node executable.

istanbul doesn't do any of that.

@vitorbaptista
Copy link
Author

Fair enough. Thanks for the quick answer 👍_

cnadeau pushed a commit to cnadeau/coterminous-js that referenced this issue Sep 15, 2016
Tried to get istanbul to properly run (runs, still not coverage) : gotwarlost/istanbul#538 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants