Skip to content

allow coverage instrumentation of multiple files - #125

Merged
kof merged 2 commits into
qunitjs:masterfrom
Sage:directory-coverage
Feb 2, 2016
Merged

allow coverage instrumentation of multiple files#125
kof merged 2 commits into
qunitjs:masterfrom
Sage:directory-coverage

Conversation

@bjouhier

Copy link
Copy Markdown
Contributor

This PR is a quick hack to enable code coverage on multiple files. It allows you to set the coverage option to:

  • a string, in which case all source files with an absolute path matching the string will be included in the coverage report.
  • a regexp, in which case all source files with a path that matches the regexp will be included.
  • true, in which case only the file specified with the code option will be included in the coverage report.

@fyockm

Copy link
Copy Markdown
Contributor

Hi @bjouhier!

Instead of overloading the coverage option as a string or Regex, do you think it would make more sense to add a new key for files?
While your proposed change provides flexiblility for specifying the coverage files, it wouldn't allow setting the other coverage options, like dir or reporters.

lib/coverage.js

options={dir: 'coverage',reporters: ['lcov','json'],files: null};

Not quite as clean, but then the matcher function could be something like this:

matcher=function(file){if(options.coverage.files){if(typeofoptions.coverage.files==='string')returnfile.indexOf(options.coverage)===0;elseif(options.coverage.filesinstanceofRegExp)returnoptions.coverage.test(file);}returnfile===options.code.path;}

An even better solution might utilize pattern globbing, but perhaps as a future enhancement.

Comment threadlib/coverage.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of string, we should use an array here, otherwise its fine ...

@bjouhier

Copy link
Copy Markdown
ContributorAuthor

@fyockm Hi Drew!!!

That's a good point. I've followed your suggestion to use options.coverage.files and I've also enabled arrays. So you can specify an array of files or regexps.

@kof

kof commented Feb 2, 2016

Copy link
Copy Markdown
Contributor

merged

@bjouhier

Copy link
Copy Markdown
ContributorAuthor

Thanks @kof

kof added a commit that referenced this pull request Feb 2, 2016
allow coverage instrumentation of multiple files
@kof
kof merged commit b0d6832 into qunitjs:masterFeb 2, 2016
@bjouhier

Copy link
Copy Markdown
ContributorAuthor

@kof@fyockm I just tried the regexp feature and found out that it is completely broken. Problem is that options are serialized between testrunner and child and JSON does not like regexps!

@kof

kof commented Feb 2, 2016

Copy link
Copy Markdown
Contributor

thats true, do we really need regexp there?

@kof

kof commented Feb 2, 2016

Copy link
Copy Markdown
Contributor

Can you add some tests?

@bjouhier

Copy link
Copy Markdown
ContributorAuthor

I can manage without regexps. Looked like a cool and easy-to-implement feature but it's only cool.

I'll remove regexps and add tests but I'll do it a bit later.

@kof

kof commented Feb 2, 2016

Copy link
Copy Markdown
Contributor

👍

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@bjouhier@fyockm@kof