Skip to content

Commit 7332ca1

Browse files
committed
test(@angular/build): add spec for the unit-test coverageWatermarks option
The `coverageWatermarks` option had no test. Run coverage with the HTML reporter using watermarks that classify any result as high (`[0, 0]`) or low (`[101, 101]`) and check the report's status class.
1 parent 193abc0 commit 7332ca1

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import { execute } from '../../index';
10+
import {
11+
BASE_OPTIONS,
12+
describeBuilder,
13+
UNIT_TEST_BUILDER_INFO,
14+
setupApplicationTarget,
15+
} from '../setup';
16+
17+
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
18+
describe('Option: "coverageWatermarks"', () => {
19+
beforeEach(async () => {
20+
setupApplicationTarget(harness);
21+
});
22+
23+
// Any coverage percentage is at or above a 0% high watermark and below a 101% low watermark.
24+
for (const [watermark, level] of [
25+
[[0, 0], 'high'],
26+
[[101, 101], 'low'],
27+
] as const) {
28+
it(`should mark coverage as "${level}" in the HTML report with ${watermark} watermarks`, async () => {
29+
harness.useTarget('test', {
30+
...BASE_OPTIONS,
31+
coverage: true,
32+
coverageReporters: ['html'] as any,
33+
coverageWatermarks: {
34+
statements: [...watermark],
35+
branches: [...watermark],
36+
functions: [...watermark],
37+
lines: [...watermark],
38+
},
39+
});
40+
41+
const { result } = await harness.executeOnce();
42+
expect(result?.success).toBeTrue();
43+
harness.expectFile('coverage/test/index.html').content.toContain(`status-line ${level}`);
44+
});
45+
}
46+
});
47+
});

0 commit comments

Comments
 (0)