Question

In my JS Test Driver configuration file, I'm excluding unit tests from code coverage calculation by putting them under test instead of load.

However, I can't do this for dependencies, like jQuery of Underscore.js, since they need to be loaded before my code.

Is there any way around this? Or do I just deal with the slow code coverage runs and statistic clutter?

Was it helpful?

Solution

Solution 1:

There's a way using the ´args´ parameter as Greg says, but that way unfortunately you have to specify the full path, as this (asuming Windows):

plugin:
- name: "coverage"
  jar: "lib/coverage-1.3.2.jar"
  module: "com.google.jstestdriver.coverage.CoverageModule"
  #Here put the files that have to be ignored by coverage. Non-existent files do not harm.
  args: "
    D:\\apache\\htdocs\\XTIME\\js\\lib\\ext-all.js,
    D:\\apache\\htdocs\\XTIME\\js\\lib\\jquery-1.7.2.min.js,     
  "

For linux filesystems, you don't have to use double slash.

Solution 2:

There's also a patched jar for 1.3.5 on this thread that allows you to exclude files that match a regular expression, so you'd have:

plugin:
- name: "coverage"
  jar: "lib/coverage-1.3.5.serve-patch.jar"  #this patched jar allows to use excludesRegex
  module: "com.google.jstestdriver.coverage.CoverageModule"
  args: "excludesRegex: /js/lib/.*\\.js$"

The /js/lib/.*\.js$ regex means "Exclude all the .js files located inside js/lib". (With this patch you don't have to worry about Windows backslashes)

I prefer this way much more, as it's portable because it does not depend on a specific path for your application.

You can download the patched version here (look for Comment 11 in the thread).

Hope this helps.
Cheers, from La Paz-Bolivia

OTHER TIPS

You can exclude libraries from code coverage by specifying them under "args" in the config. However, note that the paths must be absolute. At the time of writing, the latest jsTestDriver code-coverage plugin will only ignore the libraries if the paths are absolute.

See here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top