Skip to content

Commit ca5f076

Browse files
clydinfilipesilva
authored andcommitted
test(@angular-devkit/build-angular): add browser builder statsJson option tests
This change adds expanded unit tests for the browser builder's `statsJson` option using the builder test harness.
1 parent cfb3684 commit ca5f076

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. 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.io/license
7+
*/
8+
import { buildWebpackBrowser } from '../../index';
9+
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup';
10+
11+
describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
12+
describe('Option: "statsJson"', () => {
13+
beforeEach(async () => {
14+
// Application code is not needed for stat JSON tests
15+
await harness.writeFile('src/main.ts', '');
16+
});
17+
18+
it('generates a Webpack Stats file in output when true', async () => {
19+
harness.useTarget('build', {
20+
...BASE_OPTIONS,
21+
statsJson: true,
22+
});
23+
24+
const { result } = await harness.executeOnce();
25+
26+
expect(result?.success).toBe(true);
27+
28+
if (harness.expectFile('dist/stats.json').toExist()) {
29+
const content = harness.readFile('dist/stats.json');
30+
expect(() => JSON.parse(content))
31+
.withContext('Expected Webpack Stats file to be valid JSON.')
32+
.not.toThrow();
33+
}
34+
});
35+
36+
it('includes Webpack profiling information', async () => {
37+
harness.useTarget('build', {
38+
...BASE_OPTIONS,
39+
statsJson: true,
40+
});
41+
42+
const { result } = await harness.executeOnce();
43+
44+
expect(result?.success).toBe(true);
45+
46+
if (harness.expectFile('dist/stats.json').toExist()) {
47+
const stats = JSON.parse(harness.readFile('dist/stats.json'));
48+
expect(stats?.chunks?.[0]?.modules?.[0]?.profile?.building).toBeDefined();
49+
}
50+
});
51+
52+
it('does not generate a Webpack Stats file in output when false', async () => {
53+
harness.useTarget('build', {
54+
...BASE_OPTIONS,
55+
statsJson: false,
56+
});
57+
58+
const { result } = await harness.executeOnce();
59+
60+
expect(result?.success).toBe(true);
61+
62+
harness.expectFile('dist/stats.json').toNotExist();
63+
});
64+
65+
it('does not generate a Webpack Stats file in output when not present', async () => {
66+
harness.useTarget('build', {
67+
...BASE_OPTIONS,
68+
});
69+
70+
const { result } = await harness.executeOnce();
71+
72+
expect(result?.success).toBe(true);
73+
74+
harness.expectFile('dist/stats.json').toNotExist();
75+
});
76+
});
77+
});

0 commit comments

Comments
 (0)