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

"ng test" - no code coverage report if --code-coverage and --reporters options used together #5685

Closed
alistairmgreen opened this issue Mar 27, 2017 · 15 comments
Labels
needs: more info Reporter must clarify the issue

Comments

@alistairmgreen
Copy link

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.0 (Problem was first discovered using version 1.0.0.rc1)
node: 6.9.4
os: win32 x64 (Windows 7 Enterprise)

Repro steps.

  1. ng new coverage-test
  2. npm install --save-dev karma-teamcity-reporter
  3. Add require('karma-teamcity-reporter') to list of plugins in karma.conf.js
  4. ng test --single-run --code-coverage --reporters teamcity - the tests run with TeamCity reporting as expected.
  5. ls coverage - the coverage folder is missing.
  6. Try again with a different reporter: ng test --single-run --code-coverage --reporters progress - same result, tests pass but there is no coverage report.
  7. Try again with no reporter: ng test --single-run --code-coverage - works as expected and generates a coverage report.

The log given by the failure.

No error messages displayed. It just silently fails to produce a coverage report.

Desired functionality.

When running the unit tests on a TeamCity build server, I want to get both a test results summary in TeamCity and a code coverage report.

At present I can only do this by running the tests twice: first with --reporters teamcity to get the results summary, and then again with --code-coverage but no TeamCity reporting.

Mention any other details that might be useful.

I asked a question about this on Stack Overflow but got no replies.

@filipesilva
Copy link
Contributor

Does ng test --code-coverage --reporters=teamcity,coverage-istanbul work?

The --reporters option doesn't add to the existing list, but rather replaces it. If you only add the teamcity reporter, coverage-instanbul is not there.

@filipesilva filipesilva added the needs: more info Reporter must clarify the issue label Mar 27, 2017
@alistairmgreen
Copy link
Author

Yes, that does work, thanks!

It would be helpful if the documentation could be updated to indicate explicitly that the list of reporters is comma-separated, and that the --code-coverage switch depends upon a reporter being present.

@alistairmgreen
Copy link
Author

Would it be possible for ng test to produce a warning if --code-coverage is supplied without a suitable reporter?

Because it fails silently, and the code coverage report is left behind from the previous build, it took me several days to realize that I had broken the coverage report by turning on TeamCity reporting.

@filipesilva
Copy link
Contributor

Fixed in #6160, we now add the reporter dynamically on top of the other reporters.

@ghost
Copy link

ghost commented Jun 12, 2017

Ok great, now that I found something that works from within the last year, it's incomplete. What does a proper karma.conf look like? Why do I need to specify karma.conf in angular-cli.json?

@filipesilva
Copy link
Contributor

@megamindbrian Karma is the test runner that runs your unit tests. Angular CLI is, overall, a collection of tools that are configured to give you a good out-of-the-box experience.

It doesn't aim at completely replacing existing tools now providing full abstraction. The Karma ecosystem can still be used to extend functionality.

If you are unsure what Karma configuration ships now with ng new, the easiest way is to make a new project without installing dependencies: ng new new-proj --skip-install.

@playground
Copy link

ng test is not showing code coverage report. What do I need to do so code coverage report will show locally, travis-ci and in coveralls?

@ghost
Copy link

ghost commented Jul 11, 2017

@playground I ended up adding to webpack:

module: {
        loaders: [
            .... all other loaders for angular
            {
                test: /\.ts/,
                include: helpers.root('src', 'app'),
                loader: 'istanbul-instrumenter-loader',
                enforce: 'post',
                exclude: /(testing|node_modules|\.spec\.ts$)/
            },
    }
}

And adding coverage to karma.conf.js:

coverageReporter: {
            dir: './coverage/',
            exclude: [
                "node_modules",
                "**/*.spec.ts"
            ],
            includeAllSources: true,
            reporters: [
                {type: 'text-summary'},
                {type: 'text'},
           ],
},

What tripped me up for a day was if you use plugins: ['karma-coverage'], you have to specify all the plugins. Removing plugins: entirely and the plugins starting with karma- are loaded automatically. Including karma-coverage-istanbul-reporter and karma-coverage.

I've submitted a PR for improving Angular 2 documentation but I have to remove some parts of the commit because they don't want to accept in karma-spec-reporter as a default provided reporter.

Still working on feedback but my instructions are here:
https://github.com/megamindbrian/karma/blob/81b498d4795949a2dc45089e8abc602f53d54f58/docs/plus/06-angular.md

And the PR:
karma-runner/karma#2742

Does that help?

@ghost
Copy link

ghost commented Jul 11, 2017

@filipesilva I asked what a valid Karma config is. After digging in to other people's code, I found this: https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/tasks/test.ts

Which would lead to a 1 to 1 relationship between the input settings and these karma based settings;
https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/tasks/test.ts#L32

Not sure what the point of packing this all in to a CLI is. Might be better to just direct people to learning how karma-runner works?

@playground
Copy link

@megamindbrian thanks, I currently do not have a webpack config in my project. What does your webpack look like?

@ghost
Copy link

ghost commented Jul 11, 2017 via email

@playground
Copy link

What about the existing section?
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true,
thresholds: {
statements: 50,
lines: 50,
branches: 50,
functions: 50
}
},

Does coverageReporter replace coverageIstanbulReporter?

@ghost
Copy link

ghost commented Jul 11, 2017 via email

@ghost
Copy link

ghost commented Jul 11, 2017 via email

@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
needs: more info Reporter must clarify the issue
Projects
None yet
Development

No branches or pull requests

3 participants