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
Implement function to extract empty coverage data from an instrumented file #28
Conversation
…rumented file In support of finally fixing istanbuljs/babel-plugin-istanbul#4. Blocked on a babel-traverse release that includes babel/babel#4746
CLA is valid! |
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.
This is looking really slick, however I'm not quite picturing how we'll handle walking every file yet.
Is the idea that nyc would apply its all logic, read in the raw un-compiled file, and then invoke readInitialCoverage
and merge this onto its __coverage__
object?
const varName = genVar(filename); | ||
let covPath; | ||
traverse(ast, { | ||
VariableDeclarator: function (path) { |
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'm I'm reading this correctly:
- you stop the parse early as soon as you see an assignment with the variable matching
genVar
. - you're updating babel-traverse such that it now evaluates the object on the fly, allowing you to pluck this off the node as we traverse the tree.
This is quite clever and I dig it 👍
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.
😀
Just to be more precise here:
We parse the entire file, then stop traversing the AST the moment we find a variable declaration whose name is equal to genVar
. Then we use babel-traverse
's robust understanding of scopes and ability to statically evaluate nodes (much the opposite of valueToNode
used here) to extract the value of coverageData
from within that IIFE.
The change to babel-traverse
merely adds support for evaluating object literals, which was a long-standing TODO
in Babel and of course is essential here.
So my plan is for |
This actually gives me an idea: How about, instead of looking for the
@bcoe I would love feedback on this direction as I now prefer it to what I implemented yesterday 😄 |
This just leaves I'll sketch out a PR to EDIT: |
I'm currently working on a new Karma Coverage Reporter plugin base on new Istanbul API, say v1?
Is a little hacky ... I stop add |
@bySabi sounds like the perfect use case for this. You're doing essentially the duplicated/brittle work I was worried about - having to look at .babelrc, instrumenting twice, etc. With this new feature you should be able to just You would probably still need to grab hold of nyc's include/exclude config somehow, to best emulate nyc's part of the task. |
Ah! fine this is wonderful @motiz88 ... I´m still trying to figure out the "correct way" to grab hold include/exclude rules settings in order of not duplicate it all over the place. Parsing include/exclude from babelrc need to take in consideration |
@motiz88 now all included files will be instrumented by default. Thats right? |
No, that's not exactly right. The exact same files will be instrumented as |
But babel-plugin-istanbul will instrument not |
That depends on how you run the plugin. If you compile an entire directory However, bundler integrations are out of scope for what I'm personally |
Ok, I got it now! ... Let this is finnished/merged to see what more is needed to do with bundlers. I will be watching it. Thanks. |
This adds `cross-env` and modifies the `documentation build` invocation to not rely on shell globbing, which is not available on Windows.
This is to support Node < 4 (istanbuljs-archived-repos#29 (comment))
So this essentially works - see this test repo I made and the caveats on istanbuljs/nyc#420. As for this specific PR, the new implementation is still not entirely robust - it expects certain local variable names to be used in the coverage initialization function, which won't survive e.g. minification. This can definitely be fixed if we identify the variables by order and/or content shape instead (at least if they're not found by name). (Note: I've accidentally pulled in #29 but I'm going to leave it in unless you object, @bcoe, on the assumption that #29 will get merged soon anyhow) |
I wonder is there any convention for making that a line should be skipped by a minifier, e.g., `/* skipNextLine */. This is looking good, are we still waiting on the changes to |
Anxiously looking forward to this, boys. Keep up the good work. |
@bcoe Yeah, there's a Babel release being worked on right now which should include the updated |
@motiz88 just happened to notice a new babel release go out, does that mean we can rebase this and it will work :D |
This is in support of fixing istanbuljs/babel-plugin-istanbul#4. Next step would be to consume this new function in
nyc
when not instrumenting.This won't build until a
babel-traverse
release is made with babel/babel#4746. PRing early so the code can be reviewed until then.