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

Excluding files with custom loader not working #65

Closed
JaKXz opened this issue Nov 3, 2015 · 6 comments
Closed

Excluding files with custom loader not working #65

JaKXz opened this issue Nov 3, 2015 · 6 comments
Assignees

Comments

@JaKXz
Copy link

JaKXz commented Nov 3, 2015

My coffee-coverage-loader.coffee looks like this:

coffeeCoverage = require "coffee-coverage"
coverageVar = coffeeCoverage.findIstanbulVariable()
writeOnExit = if coverageVar == null then "#{__dirname}/coverage/coverage-coffee.json" else null

coffeeCoverage.register
  instrumentor: "istanbul"
  basePath: "#{__dirname}/src/"
  exclude: [
    "*cli.coffee"
    "*conf.coffee"
  ]
  coverageVar: coverageVar
  writeOnExit: writeOnExit
  initAll: true

and I've tried all manner of globs for the exclude paths. For this library I've just got one file I want to instrument, and a -cli.coffee that I would like to ignore. My mocha.opts looks like this:

--compilers coffee:coffee-script/register
--require coffee-coverage-loader.coffee
--require mocha.conf.coffee

The problem could be because of istanbul ignoring the basePath, but I'm not sure.

I'm using the given npm test command from the Travis CI tutorial.

I also tried using an .istanbul.yml file with no luck, mostly because I wasn't sure which options applied to instrumenting coffeescript...

@jwalton
Copy link
Contributor

jwalton commented Nov 3, 2015

Excludes don't use globs, just prefix matching. You're certainly not the first to ask for this, though. I can probably hack up a fix, but not 'till later in the week. If you're really interested, I'd welcome a PR, although ideally one that's backwards compatible.

@jwalton jwalton self-assigned this Nov 3, 2015
@jwalton
Copy link
Contributor

jwalton commented Nov 3, 2015

If you've just got one file you want to exclude, then exclude: ['-cli.coffee'] ought to do it (assuming this file is in "#{__dirname}/src/".) You can read the exclude code here.

@JaKXz
Copy link
Author

JaKXz commented Nov 3, 2015

@jwalton thanks for the response. I am doing exclude: ['-cli.coffee'] with no luck unfortunately. There's also a conf.coffee file in #{__dirname}/ that's being instrumented as well (which shouldn't be).

I read through the exclude code last night and wasn't really sure how it actually determines the file path from the register method. It looks at options.exclude, the array, but then never really does anything with it... I just assumed I'm misreading something.

@jwalton
Copy link
Contributor

jwalton commented Nov 3, 2015

The magic happens here, where we call into excludeFile(), and then if it returns true, compile the file without any instrumentation. (There's also a little bit of magic over here for when we walk through all the files in the world to generate initialization, if the initAll option is true.) Some well place console.logs in excludeFile() would probably go a long way towards figuring out what's going on.

@JaKXz
Copy link
Author

JaKXz commented Nov 3, 2015

Interesting - so they are being excluded when I use initAll: false, but the coverage summary is not being updated with the istanbul report text-summary lcov command. That's kinda strange.

@jwalton
Copy link
Contributor

jwalton commented Jan 13, 2016

Excludes now us globs! I'll close this, but feel free to raise another issue if you're still having problems.

@jwalton jwalton closed this as completed Jan 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants