tntim96 / JSCover

JSCover is a JavaScript Code Coverage Tool that measures line, branch and function coverage
GNU General Public License v2.0
399 stars 84 forks source link

"this" is undefined in header.js in strict mode #293

Closed chtheis closed 1 year ago

chtheis commented 4 years ago

I'm trying to instrument an ES6 module (note I speak of client side JS, not Node.js). It looks like the initialization of an instrumented file throws an Exception in header.js line 38, because "this" is undefined here. Unlike plain JS modules seem to be very picky about this ... What is "this" supposed to be in this context?

In a fork I deleted "this." from header.js and with the new jar my test just ran fine.

It may be possible if you add "use strict"; to a file, but I haven't tried that.

chtheis commented 4 years ago

I created PR #294 with some more changes in the .js files but the integration tests fail. I could fix a few failures which were caused by my changes but not all. Currently it fails at "inMemory.js" but I can't find that file. Any help is appreciated.

chtheis commented 4 years ago

Finally I managed to run the integration tests with success ...

It might be better to declare _$jscoverage in header.js instead of touching a couple of places where it is first assigned a value but I don't understand the code good enough to make that decision.

tntim96 commented 1 year ago

Hi @chtheis , sorry for not following up on this sooner. I believe this has been fixed in #311 , commit 0eca598. Can you confirm?

tntim96 commented 1 year ago

I've released it in the 2.0.16 SNAPSHOT if you'd like to test.

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

Or build the latest JAR yourself or download from here.

Let me know if that fixes your issue and I'll build a release.