-
-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read initial data from pre-instrumented files in "noop" instrumenter #420
Conversation
@motiz88 slick, I like that we ultimately take advantage of
This isn't a blocker, but I bet this is a bug we could put some tests around and squash in the near future. |
@motiz88 this will work fine if my project doesn't use babel, and we use We should also try to add a test for the new |
One thing to think about is that all the parsing and traversing is costly. And with this PR we walk the entire directory structure and parse every bit of JS we find (though actually I think |
@motiz88 it would be neat if we could get the best of both worlds; turn on the instrumenter hack for |
@bcoe Hmm. I can't think of anything that I would want I kind of take back my concern about doing completely unintended work: If this applies only to I can imagine, however, still wanting to limit that crawl to a known location. If my sources are in |
@motiz88 this line of reasoning seems reasonable; If I've gone to the trouble of turning off the instrumenter, there's about a Let's try to avoid adding more configuration dials and knobs if possible -- would love for things to feel magic. One thing I've been meaning to ask; this approach will work well with |
@bcoe That's an interesting question. Due to how The one thing I can see being a problem is the |
Okay, so with the two blocking PRs merged and released, this just needs tests, right? @bcoe I won't get around to it until at least tomorrow, sadly. |
I am having multiple issues trying to set up a working test env on my Windows box. I don't believe I'll be able to write tests here any time soon. Maybe someone else can step in and complete this PR? (It's now functionally complete) |
Changes Unknown when pulling 06262f6 on motiz88:read-initial-coverage into * on istanbuljs:master*. |
@motiz88 I can step up to the plate this weekend; I was hoping to test behavior with |
@@ -233,7 +238,7 @@ NYC.prototype.walkAllFiles = function (dir, visitor) { | |||
} | |||
|
|||
NYC.prototype._maybeInstrumentSource = function (code, filename, relFile) { | |||
var instrument = this.exclude.shouldInstrument(filename, relFile) | |||
var instrument = (!this.instrument && this.all) || this.exclude.shouldInstrument(filename, relFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want this bit of logic (!this.instrument && this.all)
, we still want to avoid instrumenting files that are hit by our exclude
rule, otherwise we'll end up instrumenting a huge chunk of the node_modules
folder, which slows coverage to a crawl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I mentioned this above in a comment:
I can imagine, however, still wanting to limit that crawl to a known location. If my sources are in
src/
and my transpiled+instrumented files are indist/
, I want to be able to say so via something likeinclude
andexclude
, rather than letnyc
loose on my entire directory tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But users may be surprised/confused at the need to include
their generated files, especially if the mechanism for doing so is conflated with the one for their source files. Anyway, for a "magic" workflow, node_modules
should probably be blacklisted by default no matter what the fine-tuning options are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But users may be surprised/confused at the need to include their generated files
I think the logic is correct if we just call this.exclude.shouldInstrument(filename, relFile)
without any changes. Keep in mind that when we run nyc --all
we iterate over all the files in the project using glob
:
glob.sync(pattern, {cwd: dir, nodir: true, ignore: this.exclude.exclude}).forEach(function (filename) {
visitor(filename)
})
As long as folks setup their include
/exlude
rules appropriately, this means that we'll pull in the coverage headers regardless of whether they've been pre-generated and stored to disk, or in the case of babel-register
are being plopped in on the fly.
So far folks have been having good luck playing with this new feature:
istanbuljs/babel-plugin-istanbul#4
Great work @motiz88
@motiz88 released in:
This is a pretty big change, so would love the extra help testing against a few of your libraries. |
This is part of my fix for using
--all
on externally instrumented files, as when using babel-plugin-istanbul (istanbuljs/babel-plugin-istanbul#4). I laid out the idea for this part here.Requires istanbuljs-archived-repos/istanbul-lib-instrument#28 and babel/babel#4746 (update: now both released, in istanbul-lib-instrument v1.2.0 and Babel v6.18.0 respectively).
To see the results and/or test this yourself, see the repo I've put up at https://github.com/motiz88/nyc-all-demo.
Known problems/kludges:
_maybeInstrumentSource
for!this.instrument && this.all
, in which case it will always go on to "instrument" the file (actually read the existing data in thenoop
instrumenter). This is because we can't know until we've read the file whether it is a transpiled version of a file we're interested in.process.cwd()
is a symlink causes problems at the moment, such as covered files being reported twice with different paths: one with 0% coverage and one with the actual coverage.