Skip to content

Commit bb4b3a9

Browse files
committed
corrcet
1 parent 1f58b4e commit bb4b3a9

File tree

2 files changed

+35
-125
lines changed

2 files changed

+35
-125
lines changed

packages/bundle-size-checker/src/renderMarkdownReport.js

Lines changed: 24 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -91,98 +91,39 @@ export function renderMarkdownReportContent(comparison, { track } = {}) {
9191
})
9292
: null;
9393

94-
// If track is specified, calculate totals only for tracked bundles
95-
let displayTotals = comparison.totals;
96-
let displayFileCounts = comparison.fileCounts;
97-
9894
if (trackedEntries) {
99-
// Calculate totals only for tracked bundles
100-
const trackedTotalParsed = trackedEntries.reduce(
101-
(sum, entry) => sum + entry.parsed.absoluteDiff,
102-
0,
103-
);
104-
const trackedTotalGzip = trackedEntries.reduce(
105-
(sum, entry) => sum + entry.gzip.absoluteDiff,
106-
0,
107-
);
108-
109-
// Calculate percentages based on tracked bundles only
110-
const trackedBaseParsed = trackedEntries.reduce((sum, entry) => sum + entry.parsed.previous, 0);
111-
const trackedBaseGzip = trackedEntries.reduce((sum, entry) => sum + entry.gzip.previous, 0);
112-
113-
const trackedTotalParsedPercent =
114-
trackedBaseParsed > 0 ? trackedTotalParsed / trackedBaseParsed : 0;
115-
const trackedTotalGzipPercent = trackedBaseGzip > 0 ? trackedTotalGzip / trackedBaseGzip : 0;
116-
117-
displayTotals = {
118-
totalParsed: trackedTotalParsed,
119-
totalGzip: trackedTotalGzip,
120-
totalParsedPercent: trackedTotalParsedPercent,
121-
totalGzipPercent: trackedTotalGzipPercent,
122-
};
123-
124-
// Count files only for tracked bundles
125-
const trackedAdded = trackedEntries.filter(
126-
(entry) => entry.parsed.relativeDiff === null,
127-
).length;
128-
const trackedRemoved = trackedEntries.filter(
129-
(entry) => entry.parsed.relativeDiff === -1,
130-
).length;
131-
const trackedChanged = trackedEntries.filter(
132-
(entry) =>
133-
entry.parsed.relativeDiff !== null &&
134-
entry.parsed.relativeDiff !== -1 &&
135-
(Math.abs(entry.parsed.absoluteDiff) > 0 || Math.abs(entry.gzip.absoluteDiff) > 0),
136-
).length;
137-
138-
displayFileCounts = {
139-
total: trackedEntries.length,
140-
added: trackedAdded,
141-
removed: trackedRemoved,
142-
changed: trackedChanged,
143-
};
95+
// Show all tracked bundles directly (including unchanged ones)
96+
const trackedChanges = trackedEntries.map(generateEmphasizedChange);
97+
if (trackedChanges.length > 0) {
98+
markdownContent += `${trackedChanges.join('\n')}`;
99+
}
100+
} else {
101+
markdownContent += `**Total Size Change:** ${formatChange(
102+
comparison.totals.totalParsed,
103+
comparison.totals.totalParsedPercent,
104+
)} - **Total Gzip Change:** ${formatChange(
105+
comparison.totals.totalGzip,
106+
comparison.totals.totalGzipPercent,
107+
)}\n`;
108+
109+
markdownContent += `Files: ${comparison.fileCounts.total} total (${
110+
comparison.fileCounts.added
111+
} added, ${comparison.fileCounts.removed} removed, ${comparison.fileCounts.changed} changed)\n\n`;
144112
}
145113

146-
markdownContent += `**Total Size Change:** ${formatChange(
147-
displayTotals.totalParsed,
148-
displayTotals.totalParsedPercent,
149-
)} - **Total Gzip Change:** ${formatChange(
150-
displayTotals.totalGzip,
151-
displayTotals.totalGzipPercent,
152-
)}\n`;
153-
154-
markdownContent += `Files: ${displayFileCounts.total} total (${
155-
displayFileCounts.added
156-
} added, ${displayFileCounts.removed} removed, ${displayFileCounts.changed} changed)\n\n`;
157-
158114
// Filter entries with changes
159-
const changedEntries = comparison.entries.filter(
115+
let changedEntries = comparison.entries.filter(
160116
(entry) => Math.abs(entry.parsed.absoluteDiff) > 0 || Math.abs(entry.gzip.absoluteDiff) > 0,
161117
);
162118

163119
if (trackedEntries) {
164-
const trackedIds = new Set(trackedEntries.map((entry) => entry.id));
165-
// When tracking is enabled, show tracked bundles prominently and others in details
166-
const untrackedEntries = changedEntries.filter((entry) => !trackedIds.has(entry.id));
167-
168-
// Show all tracked bundles prominently (including unchanged ones)
169-
const trackedChanges = trackedEntries.map(generateEmphasizedChange);
170-
if (trackedChanges.length > 0) {
171-
markdownContent += `${trackedChanges.join('\n')}`;
172-
}
120+
// If tracking is enabled, filter to only include tracked entries with changes
121+
changedEntries = changedEntries.filter((entry) =>
122+
trackedEntries.some((tracked) => tracked.id === entry.id),
123+
);
124+
}
173125

174-
// Put untracked bundles in details section
175-
if (untrackedEntries.length > 0) {
176-
const untrackedChanges = untrackedEntries.map(generateEmphasizedChange);
177-
markdownContent += `\n<details>\n<summary>Show ${untrackedEntries.length} other bundle changes</summary>\n\n`;
178-
markdownContent += `${untrackedChanges.join('\n')}\n\n`;
179-
markdownContent += `</details>`;
180-
} else {
181-
markdownContent += `\n<details>\n<summary>No other bundles with changes</summary>\n\n`;
182-
markdownContent += `No untracked bundles have size changes.\n\n`;
183-
markdownContent += `</details>`;
184-
}
185-
} else if (changedEntries.length > 0) {
126+
if (changedEntries.length > 0) {
186127
const allChanges = changedEntries.map(generateEmphasizedChange);
187128
markdownContent += `<details>\n<summary>Show ${changedEntries.length} bundle changes</summary>\n\n`;
188129
markdownContent += `${allChanges.join('\n')}\n\n`;

packages/bundle-size-checker/src/renderMarkdownReport.test.js

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,12 @@ describe('renderMarkdownReport', () => {
292292
});
293293

294294
expect(result).toMatchInlineSnapshot(`
295-
"**Total Size Change:** 🔺+600B<sup>(+1.62%)</sup> - **Total Gzip Change:** 🔺+200B<sup>(+1.82%)</sup>
296-
Files: 2 total (0 added, 0 removed, 2 changed)
295+
"**@mui/material/Button/index.js**&emsp;**parsed:** 🔺+400B<sup>(+2.67%)</sup> **gzip:** 🔺+100B<sup>(+2.22%)</sup>
296+
**@mui/material/TextField/index.js**&emsp;**parsed:** 🔺+200B<sup>(+0.91%)</sup> **gzip:** 🔺+100B<sup>(+1.54%)</sup><details>
297+
<summary>Show 2 bundle changes</summary>
297298
298299
**@mui/material/Button/index.js**&emsp;**parsed:** 🔺+400B<sup>(+2.67%)</sup> **gzip:** 🔺+100B<sup>(+2.22%)</sup>
299300
**@mui/material/TextField/index.js**&emsp;**parsed:** 🔺+200B<sup>(+0.91%)</sup> **gzip:** 🔺+100B<sup>(+1.54%)</sup>
300-
<details>
301-
<summary>Show 1 other bundle changes</summary>
302-
303-
**@mui/icons-material/Add.js**&emsp;**parsed:** 🔺+100B<sup>(+10.00%)</sup> **gzip:** 🔺+50B<sup>(+16.67%)</sup>
304301
305302
</details>
306303
@@ -327,21 +324,13 @@ describe('renderMarkdownReport', () => {
327324
track: ['@mui/material/Button/index.js', '@mui/material/TextField/index.js'],
328325
});
329326

330-
// Should show totals as +800/+300 (only tracked bundles), not +1800/+600 (all bundles)
331-
expect(result).toContain('+800B');
332-
expect(result).toContain('+300B');
333-
expect(result).not.toContain('+1.8KB');
334-
expect(result).not.toContain('+600B');
335327
expect(result).toMatchInlineSnapshot(`
336-
"**Total Size Change:** 🔺+800B<sup>(+2.16%)</sup> - **Total Gzip Change:** 🔺+300B<sup>(+2.73%)</sup>
337-
Files: 2 total (0 added, 0 removed, 2 changed)
328+
"**@mui/material/Button/index.js**&emsp;**parsed:** 🔺+500B<sup>(+3.33%)</sup> **gzip:** 🔺+150B<sup>(+3.33%)</sup>
329+
**@mui/material/TextField/index.js**&emsp;**parsed:** 🔺+300B<sup>(+1.36%)</sup> **gzip:** 🔺+150B<sup>(+2.31%)</sup><details>
330+
<summary>Show 2 bundle changes</summary>
338331
339332
**@mui/material/Button/index.js**&emsp;**parsed:** 🔺+500B<sup>(+3.33%)</sup> **gzip:** 🔺+150B<sup>(+3.33%)</sup>
340333
**@mui/material/TextField/index.js**&emsp;**parsed:** 🔺+300B<sup>(+1.36%)</sup> **gzip:** 🔺+150B<sup>(+2.31%)</sup>
341-
<details>
342-
<summary>Show 1 other bundle changes</summary>
343-
344-
**@mui/icons-material/Add.js**&emsp;**parsed:** 🔺+1KB<sup>(+100.00%)</sup> **gzip:** 🔺+300B<sup>(+100.00%)</sup>
345334
346335
</details>
347336
@@ -368,18 +357,11 @@ describe('renderMarkdownReport', () => {
368357
track: ['@mui/material/Button/index.js'],
369358
});
370359

371-
expect(result).toContain('Show 2 other bundle changes');
372-
expect(result).toContain('<details>');
373360
expect(result).toMatchInlineSnapshot(`
374-
"**Total Size Change:** 🔺+400B<sup>(+2.67%)</sup> - **Total Gzip Change:** 🔺+100B<sup>(+2.22%)</sup>
375-
Files: 1 total (0 added, 0 removed, 1 changed)
361+
"**@mui/material/Button/index.js**&emsp;**parsed:** 🔺+400B<sup>(+2.67%)</sup> **gzip:** 🔺+100B<sup>(+2.22%)</sup><details>
362+
<summary>Show 1 bundle changes</summary>
376363
377364
**@mui/material/Button/index.js**&emsp;**parsed:** 🔺+400B<sup>(+2.67%)</sup> **gzip:** 🔺+100B<sup>(+2.22%)</sup>
378-
<details>
379-
<summary>Show 2 other bundle changes</summary>
380-
381-
**@mui/icons-material/Add.js**&emsp;**parsed:** 🔺+100B<sup>(+10.00%)</sup> **gzip:** 🔺+50B<sup>(+16.67%)</sup>
382-
**@mui/icons-material/Delete.js**&emsp;**parsed:** 🔺+100B<sup>(+8.33%)</sup> **gzip:** 🔺+50B<sup>(+14.29%)</sup>
383365
384366
</details>
385367
@@ -407,17 +389,8 @@ describe('renderMarkdownReport', () => {
407389
});
408390

409391
expect(result).toMatchInlineSnapshot(`
410-
"**Total Size Change:** 0B<sup>(0.00%)</sup> - **Total Gzip Change:** 0B<sup>(0.00%)</sup>
411-
Files: 2 total (0 added, 0 removed, 0 changed)
412-
413-
**@mui/material/Button/index.js**&emsp;**parsed:** 0B<sup>(0.00%)</sup> **gzip:** 0B<sup>(0.00%)</sup>
392+
"**@mui/material/Button/index.js**&emsp;**parsed:** 0B<sup>(0.00%)</sup> **gzip:** 0B<sup>(0.00%)</sup>
414393
**@mui/material/TextField/index.js**&emsp;**parsed:** 0B<sup>(0.00%)</sup> **gzip:** 0B<sup>(0.00%)</sup>
415-
<details>
416-
<summary>Show 1 other bundle changes</summary>
417-
418-
**@mui/material/Icon/index.js**&emsp;**parsed:** 🔺+100B<sup>(+1.25%)</sup> **gzip:** 🔺+50B<sup>(+2.00%)</sup>
419-
420-
</details>
421394
422395
[Details of bundle changes](https://frontend-public.mui.com/size-comparison/mui/material-ui/diff?prNumber=42&baseRef=master&baseCommit=abc123&headCommit=def456)"
423396
`);
@@ -441,14 +414,10 @@ describe('renderMarkdownReport', () => {
441414
});
442415

443416
expect(result).toMatchInlineSnapshot(`
444-
"**Total Size Change:** 🔺+400B<sup>(+2.67%)</sup> - **Total Gzip Change:** 🔺+100B<sup>(+2.22%)</sup>
445-
Files: 1 total (0 added, 0 removed, 1 changed)
417+
"**@mui/material/Button/index.js**&emsp;**parsed:** 🔺+400B<sup>(+2.67%)</sup> **gzip:** 🔺+100B<sup>(+2.22%)</sup><details>
418+
<summary>Show 1 bundle changes</summary>
446419
447420
**@mui/material/Button/index.js**&emsp;**parsed:** 🔺+400B<sup>(+2.67%)</sup> **gzip:** 🔺+100B<sup>(+2.22%)</sup>
448-
<details>
449-
<summary>No other bundles with changes</summary>
450-
451-
No untracked bundles have size changes.
452421
453422
</details>
454423

0 commit comments

Comments
 (0)