babel-plugin-istanbul being run twice, when executed in conjunction with babel-plugin-rewire
Opened this issue · 1 comments
I've had a couple issues opened on babel-plugin-istanbul
related to incompatibility with babel-plugin-rewire
; In a debugging session today, I finally figured out what was happening.
When both plugins are used together, an attempt is made to instrument source code files multiple times for test coverage; This results in a second line counter being added to each line in the file, but the source-code tracking object is not updated... tldr; we end up counting the wrong lines, and the counts are off by one; this results in some extremely strange behavior, see:
and
https://github.com/MartinDawson/istanbulBug
I could potentially use the following workaround:
// the plugin rewire, as a side-effect, seems to cause
// the program visitor to be run twice; in this
// scenario, we should avoid instrumentinga second time.
function alreadyInstrumented(path, visitState) {
return path.scope.hasBinding(visitState.varName);
}
But it feels a bit weird to have to do this; any ideas as to what might be going on -- @hzoo I know you're super busy, but perhaps you could give some insight?
@bcoe Thanks for bringing this up. We had the same problem and have therefore added a similar mechanism like the alreadyInstrumented operation in your case.
In our case it is the wasProcessed method in https://github.com/speedskater/babel-plugin-rewire/blob/master/src/RewireHelpers.js
@hzoo do you have a suggestion how to solve this in a more generic way?