benbria / coffee-coverage

Istanbul and JSCoverage-style instrumentation for CoffeeScript files.
MIT License
145 stars 31 forks source link

Excluding files with custom loader not working #65

Closed JaKXz closed 8 years ago

JaKXz commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

@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 commented 9 years ago

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 commented 9 years ago

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 commented 8 years ago

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