Skip to content

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

Closed
@tamagosante

Description

@tamagosante

#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions