Typescript: Emitted code for super() results in 'Branch not covered' in coverage reports.

Created on 19 Dec 2016  路  10Comments  路  Source: microsoft/TypeScript

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.

Question

Most helpful comment

@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.

All 10 comments

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

@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.

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

Also linking to https://github.com/SitePen/remap-istanbul/issues/106 in case that can fix the issue.

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 ',"

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

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

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

As mentioned in https://github.com/Microsoft/TypeScript/issues/13455#issuecomment-287900758, instead of the various workarounds proposed, it is better to simply stick to es6 when producing the coverage report. Here is an example how.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blakeembrey picture blakeembrey  路  171Comments

metaweta picture metaweta  路  140Comments

quantuminformation picture quantuminformation  路  273Comments

Gaelan picture Gaelan  路  231Comments

kimamula picture kimamula  路  147Comments