Skip to content

allow coverage instrumentation of multiple files#125

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

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

Conversation

@bjouhier
Copy link
Copy Markdown
Contributor

@bjouhier bjouhier commented Feb 1, 2016

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

fyockm commented Feb 2, 2016

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 (typeof options.coverage.files === 'string') return file.indexOf(options.coverage) === 0;
        else if (options.coverage.files instanceof RegExp) return options.coverage.test(file);
    }
    return file === options.code.path;
}

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

Comment thread lib/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
Contributor Author

bjouhier commented Feb 2, 2016

@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
Copy link
Copy Markdown
Contributor

kof commented Feb 2, 2016

merged

@bjouhier
Copy link
Copy Markdown
Contributor Author

bjouhier commented Feb 2, 2016

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:master Feb 2, 2016
@bjouhier
Copy link
Copy Markdown
Contributor Author

bjouhier commented Feb 2, 2016

@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
Copy link
Copy Markdown
Contributor

kof commented Feb 2, 2016

thats true, do we really need regexp there?

@kof
Copy link
Copy Markdown
Contributor

kof commented Feb 2, 2016

Can you add some tests?

@bjouhier
Copy link
Copy Markdown
Contributor Author

bjouhier commented Feb 2, 2016

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
Copy link
Copy Markdown
Contributor

kof commented Feb 2, 2016

👍

Sign up for free to 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