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

constructor coverage for angular is not correct anymore #12132

Closed
bulldog98 opened this issue Sep 20, 2022 · 12 comments
Closed

constructor coverage for angular is not correct anymore #12132

bulldog98 opened this issue Sep 20, 2022 · 12 comments
Assignees
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@bulldog98
Copy link
Contributor

Current Behavior

If you have an angular lib/app with an injection in the constructor then jest reports it as a not covered branch

Expected Behavior

This is a regression I remember it working around 1-2 weeks ago (was 14.6.5 I think).

Steps to Reproduce

Reproduction: nrwl/nx-examples#229

  • run yarn nx products:test
  • observe the coverage info
@AgentEnder AgentEnder added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Sep 23, 2022
@Blackbaud-SteveBrush
Copy link

I'm seeing this too.
I'm on Nx version 14.7.13.
Coverage is correct when using @angular/[email protected], but coverage drops (constructor, specifically) when I update to @angular/compiler-cli@^14.2.1. Any ideas?

@abaran30
Copy link

We're also experiencing this issue with Nx 14.8.0. Downgrading @angular/compiler-cli does not change anything for us, unfortunately.

@abaran30
Copy link

abaran30 commented Sep 29, 2022

Update: in our case, downgrading jest-preset-angular from 12.2.2 to 12.2.0 resulted in the following behaviors (12.1.0 is not usable):

  • constructor params (dependency injection) are no longer marked as branches for coverage
  • Code coverage is not collected from all files (perhaps fixed in 12.2.2)
  • Not all tests are able to run, as some result in errors like the following (perhaps also fixed in 12.2.2):
    Component 'AppComponent' is not resolved:
     - templateUrl: ./app.component.html
     - styleUrls: ["./app.component.scss"]
    Did you run and wait for 'resolveComponentResources()'?

Going to look deeper into jest-preset-angular to see why this might be the case.

Edit: [Bug]: 12.2.2 breaks branch coverage

@Blackbaud-SteveBrush
Copy link

I'll add that we're using Karma as our test runner. Unsure why downgrading @angular/compiler-cli works in our case.

@willyboy
Copy link
Contributor

willyboy commented Oct 4, 2022

Removing emitDecoratorMetadata from tsconfig.base.json did it for me - I also removed some hardcoded istanbul/karma/jasmine deps

@abaran30
Copy link

abaran30 commented Oct 5, 2022

Removing emitDecoratorMetadata from tsconfig.base.json also works for us as a workaround for this issue (hesitant to call this a fix).

@Blackbaud-SteveBrush
Copy link

According to this article, it appears Angular 12+ no longer requires emitDecoratorMetadata to be set. 🤷‍♂️

The TS option emitDecoratorMetadata is no longer needed by Angular, and can be safely removed from tsconfig.json.

@Blackbaud-SteveBrush
Copy link

The problem with disabling emitDecoratorMetadata, however, is that /* istanbul ignore next */ on decoratored functions no longer works.

@Blackbaud-SteveBrush
Copy link

FYI, to reproduce the issue, run the following:

npx [email protected] --ci=github --nxCoud=true --preset=angular
npx nx g @nrwl/angular:lib ui --publishable --importPath=@skyux/ui --unitTestRunner=karma
npx nx g component todos --project=ui --export    

Add an injectable to the component's constructor (anything, really). For example:

  constructor(title: Title) {
    title.setTitle('foobar');
  }

Then, run the tests:

npx nx test ui --code-coverage   

You'll see the Branches coverage is at 75%, but when you look at the coverage report, it's highlighting something incorrectly.

Screen Shot 2022-11-21 at 9 52 42 AM

@dolphinigle
Copy link

Can confirm this issue still exists in 15.2.4. Removing emitDecoratorMetadata everywhere in our code fixes this.

@barbados-clemens
Copy link
Contributor

Hi all, this isn't really an Nx thing but an issue with istabul coverage reporter. @mandarini has an execllent write up over steps you can take to help resolve the issue. mandarini/isolatedm-jest

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

7 participants