Skip to content

Commit b48aa00

Browse files
coryrylanfilipesilva
authored andcommitted
docs: code coverage documentation
Close angular#5703
1 parent 7de9ab1 commit b48aa00

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

docs/documentation/stories.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
- [Corporate Proxy](stories/using-corporate-proxy)
2323
- [Internationalization (i18n)](stories/internationalization)
2424
- [Serve from Disk](stories/disk-serve)
25+
- [Code Coverage](stories/code-coverage)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Code Coverage
2+
3+
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.
4+
5+
To generate a coverage report run the following command in the root of your project
6+
7+
```bash
8+
ng test --watch=false --code-coverage
9+
```
10+
11+
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.
12+
13+
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.
14+
15+
## Code Coverage Enforcement
16+
17+
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
18+
19+
```javascript
20+
coverageIstanbulReporter: {
21+
reports: [ 'html', 'lcovonly' ],
22+
fixWebpackSourcePaths: true,
23+
thresholds: {
24+
statements: 80,
25+
lines: 80,
26+
branches: 80,
27+
functions: 80
28+
}
29+
}
30+
```
31+
32+
The `thresholds` property will enforce a minimum of 80% code coverage when the unit tests are run in the project.

0 commit comments

Comments
 (0)