2

I start Karma with, basically, node wrapper.js. That wrapper sets up the configuration including calling karma-coverage, starting Karma with require('karma').runner.run. karma-coverage calls out to Istanbul. (phew!)

I'd like to configure Istanbul with an .istanbul.yml file, mostly because I want to change the 'reporting watermarks'. Here's what my file looks like.

reporting:
  watermarks:
    statements: [90, 97]
    lines: [90, 97]
    functions: [90, 97]
    branches: [90, 97]

That looks correct, from what I've seen. But.. it doesn't work. I assume the problem is that istanbul doesn't know the current working directory or somehow this needs to be specified through karma-coverage.

If it helps, my Karma config.basePath is simply ''.

I've attempted to find discussion of this specific problem. Sadly, this question is the closest to my problem, but it's a FAQ entry about "how to name the file". Here's a question/answer discussing this in Grunt, but I wasn't able to extract anything useful.

I also trawled through the karma-runner issues on github, both open and closed. Looking at the source to karma-runner and combining it with this issue from Istanbul, I assume it's not possible because of this line. Am I correct?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
tedder42
  • 23,519
  • 13
  • 86
  • 102

1 Answers1

0

Use the following process:

  • Go to the istanbul directory within the karma-coverage module:

    cd node_modules/karma-coverage/node_modules/istanbul
    
  • Go to the lib directory:

    cd lib
    
  • Add the .istanbul.yml file there

The config.js script in the lib directory finds the path to the .istanbul.yml file via the following line:

 path.resolve('.istanbul.yml')

That's it.

The path.resolve method works as follows:

If after using all from paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.

References

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265