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

Branch coverage data is incorrect after upgrading to Angular 13 #22652

Closed
1 of 15 tasks
acieroid opened this issue Feb 4, 2022 · 2 comments
Closed
1 of 15 tasks

Branch coverage data is incorrect after upgrading to Angular 13 #22652

acieroid opened this issue Feb 4, 2022 · 2 comments

Comments

@acieroid
Copy link

acieroid commented Feb 4, 2022

馃悶 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: Angular 12

Description

The coverage produced when running ng test --code-coverage is incorrect, it is missing branches that were previously counted. This applies to if that do not have an else: these used to be counted as two branches, and they are now counted as one. This artificially increases branch coverage.

馃敩 Minimal Reproduction

Starting from a minimal reproduction repository (ng new), make the following changes:

  1. Add src/foo.ts. Note that this function contains two branches to cover: the if, and the (non-explicitly written) else.
export function foo(n: number) {
  if (n % 2 === 0) {
    console.log('hello');
  }
}
  1. Add src/foo.spec.ts:
import { foo } from './foo';

describe('test', () => {
  it('test', () => {
    foo(2);
  });
});
  1. Restrict the test suite to run only foo.spec.ts in src/test.ts:
const context = require.context('./', true, /foo\.spec\.ts$/);
  1. Launch the tests with code coverage: npx ng test --code-coverage
  2. The output reports full coverage, of only one branch:
=============================== Coverage summary ===============================
Statements   : 100% ( 2/2 )
Branches     : 100% ( 1/1 )
Functions    : 100% ( 1/1 )
Lines        : 100% ( 2/2 )

For comparison, downgrading to Angular 12 and to Typescript 4.3.5 results in the correct coverage report, which is:

=============================== Coverage summary ===============================
Statements   : 100% ( 5/5 )
Branches     : 50% ( 1/2 )
Functions    : 100% ( 1/1 )
Lines        : 100% ( 5/5 )

馃實 Your Environment

Everything comes from the default app when running ng new


Angular CLI: 13.2.2
Node: 16.13.2
Package Manager: npm 8.1.2
OS: linux x64

Angular: 13.2.1
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1302.2
@angular-devkit/build-angular   13.2.2
@angular-devkit/core            13.2.2
@angular-devkit/schematics      13.2.2
@angular/cli                    13.2.2
@schematics/angular             13.2.2
rxjs                            7.5.2
typescript                      4.5.5
@alan-agius4
Copy link
Collaborator

alan-agius4 commented Feb 8, 2022

It turned out to be pretty complex to find the root cause. After spending most of yesterday afternoon and today's morning I was able to locate the source of the issue. It turns out that this is caused by this change in istanbul-lib-instrument which is causing incorrect branch coverage for implicit else.

I opened an issue in their repo with a minimal reproduction. I suggest that you subscribe to that issue.

I am going to close this issue, as is not actionable from our end since we don't control which version of istanbul-lib-instrument is used because this is a transitive dependency.

@alan-agius4 alan-agius4 removed the needs: investigation Requires some digging to determine if action is needed label Feb 8, 2022
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 11, 2022
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