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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect coverage code w/ TS private arguments #8553

Closed
arcanis opened this issue Jun 12, 2019 · 5 comments
Closed

Incorrect coverage code w/ TS private arguments #8553

arcanis opened this issue Jun 12, 2019 · 5 comments

Comments

@arcanis
Copy link
Contributor

arcanis commented Jun 12, 2019

馃悰 Bug Report

The code executed by Jest with --coverage is incorrect when using TS private arguments. It seems to be transpiled as such, which isn't valid because this can only be used after the super call:

class Bar {}

/* istanbul ignore next */
cov_s64sx2cd4.s[0]++;
exports.Foo = class Foo extends Bar {
  constructor(arg) {
    /* istanbul ignore next */
    this.arg = arg;
    cov_s64sx2cd4.f[0]++;
    cov_s64sx2cd4.s[1]++;
    super();
  }
};

Without --coverage it gets transpiled as such:

class Bar {}

exports.Foo = class Foo extends Bar {
  constructor(arg) {
    super();
    this.arg = arg;
  }
};

Interestingly, it works if I "transpile" the construct myself. The generated code becomes:

class Bar {}

/* istanbul ignore next */
cov_s64sx2cd4.s[0]++;
exports.Foo = class Foo extends Bar {
  constructor(arg) {
    /* istanbul ignore next */
    cov_s64sx2cd4.f[0]++;
    cov_s64sx2cd4.s[1]++;
    super();

    /* istanbul ignore next */
    cov_s64sx2cd4.s[2]++;
    this.arg = arg;
  }
};

To Reproduce

Code that triggers the bug:

class Bar {
}

class Foo extends Bar {
    constructor(
        private arg: number,
    ) {
        super();
    }
}

Expected behavior

Should work, but doesn't

Link to repl or repo (highly encouraged)

https://github.com/arcanis/jest-coverage-ts

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
  Binaries:
    Node: 12.3.1 - ~/.nodenv/shims/node
    Yarn: 1.16.0 - ~/.nodenv/shims/yarn
    npm: 6.9.0 - ~/.nodenv/shims/npm
  npmPackages:
    jest: ^24.8.0 => 24.8.0
@SimenB
Copy link
Member

SimenB commented Jun 12, 2019

Is this istanbuljs/istanbuljs#237? If so, it just needs to wait for babel/babel#9610 to be released

@arcanis
Copy link
Contributor Author

arcanis commented Jun 12, 2019

Seems so! I'll close mine as duplicate 馃憣

@arcanis arcanis closed this as completed Jun 12, 2019
@SimenB
Copy link
Member

SimenB commented Jun 12, 2019

You can try to apply that patch locally and see if it fixes the issue? Seems very much to be the same issue though 馃檪

@SimenB
Copy link
Member

SimenB commented Jul 4, 2019

@arcanis wanna verify with 7.5.0?

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants