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

Emitted code for super() results in 'Branch not covered' in coverage reports. #13029

Closed
Izhaki opened this issue Dec 19, 2016 · 10 comments
Closed
Labels
Question An issue which isn't directly actionable in code

Comments

@Izhaki
Copy link

Izhaki commented Dec 19, 2016

TypeScript Version: 2.1.4

Code

The super() call in the following code, results in 'Branch not covered' with Istanbul (see issue).

constructor( x: number, y: number, w: number, h: number ) {
    super(); // <- Throws 'Branch not covered'.
    this.rect = new Rect( x, y, w, h);
}

In Typescript 1.8 the super() call transpiled to:

_super.call(this);

But in 2.1.4 it transpile to:

var _this = _super.call(this) || this;

Which will obviously yield 'Branch not covered'.

Adding a test - or ignore instructions - just to ensure appropriate coverage does not feel right here, let alone will have to include some comments on the internals of typescript.

@RyanCavanaugh
Copy link
Member

This is to support subclassing classes which themselves return different objects from super

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Dec 19, 2016
@Izhaki
Copy link
Author

Izhaki commented Dec 19, 2016

@RyanCavanaugh. OMG, had she died, Barbara would turn in her grave.

Is this in the ES6 standard? Because this looks to me like OOP on LSD.

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Dec 21, 2016

It's a thing (tm), unfortunately

> class Tricky { constructor() { return { m: 4 } } }
[Function: Tricky]
> let t = new Tricky();
undefined
> t
{ m: 4 }
> class Mine extends Tricky { constructor() { super(); } }
[Function: Mine]
> let m = new Mine();
undefined
> m
{ m: 4 }
> m instanceof Mine
false

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Dec 21, 2016

Also linking to SitePen/remap-istanbul#106 in case that can fix the issue.

@Bnaya
Copy link

Bnaya commented Jan 7, 2017

For the reference,
on babel, i get
screen shot 2017-01-07 at 23 42 00
(when adding to the babel config)
" auxiliaryCommentBefore: ' istanbul ignore next ',"

@mhegazy
Copy link
Contributor

mhegazy commented Jan 11, 2017

@Bnaya, this seems like a good feature to add. do you mind filing a new issue to track it.

@Bnaya
Copy link

Bnaya commented Jan 12, 2017

I don't feel i know enough about it, i just gave the hint:)

@samvloeberghs
Copy link

@Bnaya wouldn't that ignore everything?! Seems so wrong to do :)

@Izhaki
Copy link
Author

Izhaki commented Mar 20, 2017

As mentioned in #13455 (comment), instead of the various workarounds proposed, it is better to simply stick to es6 when producing the coverage report. Here is an example how.

@ben8p
Copy link

ben8p commented Dec 13, 2017

For the one using webpack and TypeScript configured to output ES5,
I made a little webpack loader:
https://www.npmjs.com/package/ts-es5-istanbul-coverage
Using it make sure you won't get the branch marked as not covered.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

7 participants