Switching to es2015 compile target dropped code coverage
🐞 Bug report
Command (mark with an x)
- [ ] new
- [ ] build
- [ ] serve
- [x] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc
Is this a regression?
Yes, the previous version in which this bug was not present was: ....Description
Switching to es2015 compile target in tsconfig.json dropped our code coverage by ~10%. We are uploading lvoc report to sonarqube.
Does anyone else discovered this by switching to diffrential loading
🔬 Minimal Reproduction
🔥 Exception or Error
🌍 Your Environment
Angular CLI: 8.3.3
Node: 12.3.1
OS: win32 x64
Angular: 8.2.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Package Version------------------------------------------------------------
@angular-devkit/architect 0.803.3
@angular-devkit/build-angular 0.803.5
@angular-devkit/build-optimizer 0.803.5
@angular-devkit/build-webpack 0.803.5
@angular-devkit/core 8.3.3
@angular-devkit/schematics 8.3.3
@angular/cdk 8.1.2
@angular/cli 8.3.3
@angular/flex-layout 8.0.0-beta.26
@angular/material 8.1.3
@angular/material-moment-adapter 8.1.3
@angular/pwa 0.801.3
@ngtools/webpack 8.3.5
@schematics/angular 8.3.3
@schematics/update 0.803.3
rxjs 6.5.3
typescript 3.5.3
webpack 4.39.2
Anything else relevant?
Hi, do you have some code that can demonstrate the difference in code coverage metric between es5 and es2015?
@alan-agius4
here is a simple pipe and the lcov report

Left is before es6 and right is es6 change
here is the code:
import { Pipe, PipeTransform } from '@angular/core';
/**
* Returns color string based on remaining value.
* Example: value = 10;max = 100; => 90% => red
*/
@Pipe({
name: 'indicator'
})
export class IndicatorPipe implements PipeTransform {
transform(percentage: number, treshhold?: number[]): string {
if (!treshhold) {
treshhold = [60, 90]; // default treshhold
} else if (treshhold.length !== 2) {
throw new Error('Treshold parameter should be array of two numbers');
}
if (percentage !== undefined) {
if (percentage >= treshhold[1]) {
return 'red';
} else if (treshhold[0] <= percentage && percentage < treshhold[1]) {
return 'orange';
} else {
return 'gray';
}
} else {
return 'gray';
}
}
}
Spec file
import { TestBed } from '@angular/core/testing';
import { configureTestSuite } from 'ng-bullet';
import { IndicatorPipe } from './indicator.pipe';
describe('IndicatorPipe', () => {
let pipe: IndicatorPipe;
configureTestSuite(() => {
TestBed.configureTestingModule({
providers: [IndicatorPipe]
});
});
beforeEach(() => {
pipe = TestBed.get(IndicatorPipe) as IndicatorPipe;
});
it('should mark as red everything above 90%', () => {
expect(pipe.transform(100)).toEqual('red');
expect(pipe.transform(92)).toEqual('red');
expect(pipe.transform(90)).toEqual('red');
});
it('should mark as gray if value is negative', () => {
expect(pipe.transform(-8)).toEqual('gray');
});
it('should mark as red if value is greater than max', () => {
expect(pipe.transform(888)).toEqual('red');
});
it('should mark as orange everything above 60% and below 90%', () => {
expect(pipe.transform(88)).toEqual('orange');
expect(pipe.transform(60)).toEqual('orange');
});
it('should mark as gray everything below 60%', () => {
expect(pipe.transform(59)).toEqual('gray');
expect(pipe.transform(0)).toEqual('gray');
});
it('should set correct values based on custom treshold', () => {
expect(pipe.transform(15, [20, 80])).toEqual('gray');
expect(pipe.transform(20, [20, 80])).toEqual('orange');
expect(pipe.transform(79, [20, 80])).toEqual('orange');
expect(pipe.transform(80, [20, 80])).toEqual('red');
});
});
(Not sure if I should add to this bug report or start a separate one; opted for the former but let me know if that was the wrong choice.)
I have seen this in my code base as well, precipitated by my upgrade from Angular 6 to Angular 8 three days ago. You can see from the historical graph that we were at almost steady-state (76%) until that moment; now we are again at steady-state, but at 65%!
If the compile target is the key, as seems to be the focus here, my change was from es5 to es2015. Here's the complete diff on tsconfig.json:

My company's code is open source, so everything is available for inspection: https://github.com/chef/automate/tree/master/components/automate-ui
I've observed the same after moving to es2015 module type and only using import/export syntax.
We lost around 5% code coverage and 15% in size when compared to a build with commonjs.
I am not entirely sure but I think that code coverage metrics are calculated based on javascript file and not typescript, hence if output is different - metrics will be different.
same issue for me any updates?
I had a quick look at this, and indeed it seems to be caused by what @FDIM described as the transpilled code which is later instrumented is different.
Left ES5, Right ES2015

I think we can close this issue now as we have found out what's the reason.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.