Skip to content
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

Instrumented code for code coverage is not getting parsed correclty #571

Closed
hiaux0 opened this issue May 10, 2022 · 2 comments · Fixed by #578
Closed

Instrumented code for code coverage is not getting parsed correclty #571

hiaux0 opened this issue May 10, 2022 · 2 comments · Fixed by #578

Comments

@hiaux0
Copy link
Member

hiaux0 commented May 10, 2022

#547 addresses a related issue.
(other related: aurelia/testing#94)

Problem

What I found, is that the instrumented code (maybe special to this lib @jsdevtools/coverage-istanbul-loader) is using methods instead of simple properties

⚠️ There is a bug when parsing code, that has coverage-helper-code.
More specifically, aurelia-validation does not parse the helper code correctly aurelia/testing#94.
I found a fix, but would need to PR to the aurelia repo and stuff.
(Maybe we just fork ourselves, will create a ticket)
image

function (a) {
-    cov_2n0ovlwwxg.f[2]++;    // "normally"
+    cov_2n0ovlwwxg().f[2]++;   // maybe only @jsdevtools/coverage-istanbul-loader?
    return a.message;
}

Suggested fix

A fix I found is to update the parts of the regex by including () (open and close paren)

export function getAccessorExpression(fn: string): string {
  /* tslint:disable:max-line-length */
-  const classic = /^function\s*\([$_\w\d]+\)\s*\{(?:\s*"use strict";)?(?:[$_\s\w\d\/\*.['"\]+;]+)?\s*return\s+[$_\w\d]+\.([$_\w\d]+)\s*;?\s*\}$/;
+  const classic = /^function\s*\([$_\w\d]+\)\s*\{(?:\s*"use strict";)?(?:[$_\s\w\d\/\*.['"\]+();]+)?\s*return\s+[$_\w\d]+\.([$_\w\d]+)\s*;?\s*\}$/;
                                                                                              ^ actual change here

Keywords:
@jsdevtools/coverage-istanbul-loader
code coverage instrumented code

@bigopon
Copy link
Member

bigopon commented May 12, 2022

@hiaux0 there @hiaux0 there are existing tests here

expect(parse('function(a){__gen$field.f[\'10\']++;__aGen$field.g[\'10\']++;return a.b;}'))
.toEqual('b');
// tslint:disable-next-line:max-line-length
expect(parse('function(a){"use strict";_gen$field.f[\'10\']++;_aGen$field.g[\'10\']++;return a.b;}'))
.toEqual('b');
// tslint:disable-next-line:max-line-length
expect(parse('function(a){/* istanbul ignore next */ cov_1wjh4ld5ut.f[9]++;cov_1wjh4ld5ut.s[50]++;return a.b;}'))
.toEqual('b');

It seems the fix is already figured out, can you help create a PR with some tests @hiaux0 ?

@hiaux0
Copy link
Member Author

hiaux0 commented May 12, 2022

@bigopon

existing tests

Afai can see, it fixes just for normal properties, and not methods, ie.

- __gen$field.f[\'10\']
+ __gen$field().f[\'10\'] // I'm expecting `()`

create a PR

yeah, I planned to when I find some spare time

bigopon pushed a commit that referenced this issue Feb 2, 2023
* fix: property accessor ignore instrumenter

This supports instrumentation code from @jsdevtools/coverage-istanbul-loader.

Fixes #571

* cleanup

---------

Co-authored-by: Pal, Sayan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants