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

docs(wiki/stories): code coverage documentation #5703

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/documentation/stories.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
- [Corporate Proxy](stories/using-corporate-proxy)
- [Internationalization (i18n)](stories/internationalization)
- [Serve from Disk](stories/disk-serve)
- [Code Coverage](stories/code-coverage)
32 changes: 32 additions & 0 deletions docs/documentation/stories/code-coverage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Code Coverage

With the Angular CLI we can run unit tests as well as create code coverage reports. Code coverage reports allow us to see any parts of our code base that may not be properly tested by our unit tests.

To generate a coverage report run the following command in the root of your project

```bash
ng test --watch=false --code-coverage
```

Once the tests complete a new `/coverage` folder will appear in the project. In your Finder or Windows Explorer open the `index.html` file. You should see a report with your source code and code coverage values.

Using the code coverage percentages we can estimate how much of our code is tested. It is up to your team to determine how much code should be unit tested.

## Code Coverage Enforcement

If your team decides on a set minimum amount to be unit tested you can enforce this minimum with the Angular CLI. For example our team would like the code base to have a minimum of 80% code coverage. To enable this open the `karma.conf.js` and add the following in the `coverageIstanbulReporter:` key

```javascript
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true,
thresholds: {
statements: 80,
lines: 80,
branches: 80,
functions: 80
}
}
```

The `thresholds` property will enforce a minimum of 80% code coverage when the unit tests are run in the project.