Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cover -x exclude directory not working #28

Closed
damusnet opened this issue Oct 19, 2015 · 7 comments
Closed

cover -x exclude directory not working #28

damusnet opened this issue Oct 19, 2015 · 7 comments

Comments

@damusnet
Copy link

Hello,

This works:
babel-node node_modules/.bin/babel-istanbul cover --include-all-sources --root 'src/app' node_modules/.bin/_mocha

While this doesn't:
babel-node node_modules/.bin/babel-istanbul cover --include-all-sources --root 'src/app' -x '**/lib/**' node_modules/.bin/_mocha

It fails with this error:

(function (exports, require, module, __filename, __dirname) { import Chai, { expect } from 'chai';
                                                              ^^^^^^

SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Object.Module._extensions.(anonymous function) [as .js] (/Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/lib/hook.js:109:37)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at /Users/damien/Sites/voxeet/web-client/node_modules/mocha/lib/mocha.js:216:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/damien/Sites/voxeet/web-client/node_modules/mocha/lib/mocha.js:213:14)
    at Mocha.run (/Users/damien/Sites/voxeet/web-client/node_modules/mocha/lib/mocha.js:453:10)
    at Object.<anonymous> (/Users/damien/Sites/voxeet/web-client/node_modules/mocha/bin/_mocha:393:18)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Object.Module._extensions.(anonymous function) [as .js] (/Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/lib/hook.js:109:37)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at runFn (/Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/lib/command/common/run-with-cover.js:135:16)
    at /Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/lib/command/common/run-with-cover.js:269:17
    at /Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/lib/util/file-matcher.js:68:16
    at /Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/node_modules/async/lib/async.js:52:16
    at /Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/node_modules/async/lib/async.js:363:13
    at /Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/node_modules/async/lib/async.js:52:16
    at done (/Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/node_modules/async/lib/async.js:248:21)
    at /Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/node_modules/async/lib/async.js:44:16
    at /Users/damien/Sites/voxeet/web-client/node_modules/babel-istanbul/node_modules/async/lib/async.js:360:17
    at LOOP (fs.js:1539:14)
    at doNTCallback0 (node.js:417:9)
    at process._tickDomainCallback (node.js:387:13)

Do you have any idea what is happening?

@jeffrifwald
Copy link
Owner

Are you excluding something that needs to be transpiled by accident? Maybe try excluding something with a very distinct name, other than libs and see if you have the same problem.

@damusnet
Copy link
Author

I also tried with another directory named shims that contains nothing of importance, and the error is the same. It does not seem related to me. I more feels like the -x deactivates babel at some level (cf SyntaxError: Unexpected reserved word => import).

@jeffrifwald
Copy link
Owner

Yeah that is weird, I'm seeing the same problem. I don't know enough about istanbul to know why it would do that. It might be doing some really weird stuff with the excludes. I've always had trouble with Istanbul and exludes/includes in general. I've just learned to structure my code so the built in excludes work.

@damusnet
Copy link
Author

The other weird stuff is that the same -x '**/lib/**' worked fine without babel-node but then I had coverage on the transpiled code instead of the ES6 code.

@lukescott
Copy link

I think the issue is that babel isn't being run on the excluded files.

I have my test files in same directory as the app as *.spec.js files. Where I'm running into the issue is trying to exclude my tests from the report. Since my tests are also written in ES6 it fails because my tests don't get compiled.

@lukescott
Copy link

I figured out how to get this to work. A bit of a crude work-around, bit it works. This is what I'm doing now:

.istanbul.yml:

verbose: false
instrumentation:
    root: ./app
    excludes: ["*.spec.js"]
    include-all-sources: true
reporting:
    reports:
        - html

test/mocha.opts:

-r ./test/babel-register.js
--recursive
./app/**/*.spec.js

test/babel-register.js:

if (/\bin\/_mocha/.test(process.argv[1])) {
    require("babel-core/register")({
        only: /\.spec\.js$/
    });
} else {
    require("babel-core/register");
}

Both mocha and babel-istanbul cover -- ./node_modules/.bin/_mocha work.

@damusnet
Copy link
Author

The following .istanbul.yml also did the trick for me:

verbose: false
instrumentation:
  root: ./src/app
  excludes: ["**/lib/**"]
  include-all-sources: true
reporting:
  reports:
    - html

I discarded this possibility too early because it wasn't clear to me how to turn on the include-all-sources setting from the documentation. Weird though that this would work, and not the inline command line solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants