Skip to content

@angular/cli - eject command - testing does not output any coverage reports #5553

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

Closed
jgodi opened this issue Mar 21, 2017 · 6 comments
Closed

Comments

@jgodi
Copy link

jgodi commented Mar 21, 2017

Bug Report or Feature Request (mark with an x)

- [x] bug report
- [ ] feature request

Versions

@angular/cli: 1.0.0-rc.4 (e)
node: 6.10.0
os: darwin x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0-rc.4
@angular/compiler-cli: 2.4.10

Repro steps.

ng new testerino
cd testerino
ng eject -aot -prod
npm test

The log given by the failure.

No failure, but there is no coverage numbers outputted.

Desired functionality.

A coverage folder is created and coverage reports populated.

Mention any other details that might be useful.

The ejected reporters in the karma.conf.js are:

reporters: config.angularCli && config.angularCli.codeCoverage
              ? ['progress', 'coverage-istanbul']
              : ['progress', 'kjhtml'],

I even updated these to reporters: ['progress', 'coverage-istanbul', 'kjhtml'] and still have the same results (as per #5514).

Has anyone else ran across this?

@jgodi jgodi changed the title ng eject - Code Coverage @angular/cli - eject command - testing does not output any coverage reports Mar 21, 2017
@jgodi
Copy link
Author

jgodi commented Mar 22, 2017

SOLVED! Here is what you have to do when you eject the config and get want to get code-coverage. Apologies if this is documented somewhere. Let me know if its not and I can document it.

In your karma.conf.js you have to add:

 angularCli: {
   environment: 'dev',
   codeCoverage: true
 }

The codeCoverage: true is what tells the @angular/cli/plugins/karma to use the post loaders for instanbul. Now, I am able to get proper coverage using the fix from #5514 as well.

@jgodi jgodi closed this as completed Mar 22, 2017
@dreamerkumar
Copy link

dreamerkumar commented Jun 9, 2017

Thanks for your input @jgodi Setting up the 'codeCoverage' property actually does make the reporter work in a project where ng eject has been applied.

But it only works if we still use the angular-cli in the list of karma frameworks.

I need to use a different framework with the ejected webpack config. Essentially removing all relationships with angular-cli from the karma config. But still using the same webpack.

There is definitely some config that I am missing in the webpack to make the reporter work. Anyone has some clues?

@dreamerkumar
Copy link

dreamerkumar commented Jun 12, 2017

Found out the extra configuration that was missing by going to the angular-cli source code: https://github.com/angular/angular-cli/blob/1cd0a0811df2b7a45cbffb413dd56e3ac21a96e4/packages/%40angular/cli/models/webpack-configs/test.ts

Needed to add this configuration in the webpack to make code-coverage to work with zero dependency on angular-cli

      {
        test: /\.(js|ts)$/, 
        loader: 'istanbul-instrumenter-loader',
        enforce: 'post',
        query: {
          esModules: true
        },
        exclude: [
          /\.(e2e|spec)\.ts$/,
          /node_modules/
        ]
      }

@hikumealan
Copy link

@dreamerkumar any insight into where you added this in the webpack.config.js?

@gnomeontherun
Copy link

gnomeontherun commented Feb 9, 2018

@hikumealan it would be in the module.rules array.

module.rules[
  // other rules probably already exist
  {
      test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader',
      enforce: 'post',
      exclude: [
        /\.(e2e|spec)\.ts$/,
        /node_modules/
      ]
    }
]```

@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 Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants