build: add size-tracking bazel test (#30070)
Introduces a new Bazel test that allows us to inspect what source-files contribute to a given bundled file and how much bytes they contribute to the bundle size. Additionally the size-tracking rule groups the size data by directories. This allows us to compare size changes in the scope of directories. e.g. a lot of files in a directory could increase slightly in size, but in the directory scope the size change could be significant and needs to be reported by the test target. Resolves FW-1278 PR Close #30070
This commit is contained in:

committed by
Andrew Kushnir

parent
a44b510087
commit
2945f47977
92
tools/size-tracking/file_size_compare_spec.ts
Normal file
92
tools/size-tracking/file_size_compare_spec.ts
Normal file
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {compareFileSizeData} from './file_size_compare';
|
||||
|
||||
describe('file size compare', () => {
|
||||
|
||||
it('should report if size entry differ by more than the specified threshold', () => {
|
||||
const diffs = compareFileSizeData(
|
||||
{
|
||||
unmapped: 0,
|
||||
files: {
|
||||
size: 50,
|
||||
'a.ts': 50,
|
||||
}
|
||||
},
|
||||
{
|
||||
unmapped: 0,
|
||||
files: {
|
||||
size: 75,
|
||||
'a.ts': 75,
|
||||
}
|
||||
},
|
||||
0);
|
||||
|
||||
expect(diffs.length).toBe(2);
|
||||
expect(diffs[0].filePath).toBe('/');
|
||||
expect(diffs[0].message).toMatch(/40.00% from the expected size/);
|
||||
expect(diffs[1].filePath).toBe('/a.ts');
|
||||
expect(diffs[1].message).toMatch(/40.00% from the expected size/);
|
||||
});
|
||||
|
||||
it('should not report if size percentage difference does not exceed threshold', () => {
|
||||
const diffs = compareFileSizeData(
|
||||
{
|
||||
unmapped: 0,
|
||||
files: {
|
||||
size: 50,
|
||||
'a.ts': 50,
|
||||
}
|
||||
},
|
||||
{
|
||||
unmapped: 0,
|
||||
files: {
|
||||
size: 75,
|
||||
'a.ts': 75,
|
||||
}
|
||||
},
|
||||
40);
|
||||
|
||||
expect(diffs.length).toBe(0);
|
||||
});
|
||||
|
||||
|
||||
it('should report if expected file size data misses a file size entry', () => {
|
||||
const diffs = compareFileSizeData(
|
||||
{
|
||||
unmapped: 0,
|
||||
files: {
|
||||
size: 101,
|
||||
'a.ts': 100,
|
||||
'b.ts': 1,
|
||||
}
|
||||
},
|
||||
{unmapped: 0, files: {size: 100, 'a.ts': 100}}, 1);
|
||||
|
||||
expect(diffs.length).toBe(1);
|
||||
expect(diffs[0].filePath).toBe('/b.ts');
|
||||
expect(diffs[0].message).toMatch(/Unexpected file.*not part of golden./);
|
||||
});
|
||||
|
||||
it('should report if actual file size data misses an expected file size entry', () => {
|
||||
const diffs = compareFileSizeData(
|
||||
{
|
||||
unmapped: 0,
|
||||
files: {
|
||||
size: 100,
|
||||
'a.ts': 100,
|
||||
}
|
||||
},
|
||||
{unmapped: 0, files: {size: 101, 'a.ts': 100, 'b.ts': 1}}, 1);
|
||||
|
||||
expect(diffs.length).toBe(1);
|
||||
expect(diffs[0].filePath).toBe('/b.ts');
|
||||
expect(diffs[0].message).toMatch(/Expected file.*not included./);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user