Skip to content

Commit b761041

Browse files
authored
Merge pull request #301 from github/top-100-changeset
Limit changeset to first 100 rows
2 parents 4f9c4d1 + 209158d commit b761041

File tree

7 files changed

+128
-128
lines changed

7 files changed

+128
-128
lines changed

__tests__/__snapshots__/main.test.ts.snap

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@
33
exports[`Shows stats when files are added 1`] = `
44
"**Total**
55
6-
Files count | Type | Total bundle size | % Changed
7-
----------- | ---- | ----------------- | ---------
8-
2 -> 7 | bundled<br />gzip | 1.29 MB -> 1.34 MB (+53.65 KB)<br />N/A -> 386.44 KB | +4.07%"
6+
Files count | Total bundle size | % Changed
7+
----------- | ----------------- | ---------
8+
2 -> 7 | 1.29 MB -> 1.34 MB (+53.65 KB)<br />N/A -> 386.44 KB (gzip) | +4.07%"
99
`;
1010

1111
exports[`Shows stats when files are added 2`] = `
1212
"**Added**
1313
14-
Asset | Type | File Size | % Changed
15-
----- | ---- | --------- | ---------
16-
296.chunk.js | bundled<br />gzip | 0 B -> 124.57 KB (+124.57 KB)<br />0 B -> 35.05 KB | -
17-
288.chunk.js | bundled<br />gzip | 0 B -> 57.24 KB (+57.24 KB)<br />0 B -> 16.33 KB | -
18-
920.chunk.js | bundled<br />gzip | 0 B -> 54.98 KB (+54.98 KB)<br />0 B -> 17.08 KB | -
19-
912.chunk.js | bundled<br />gzip | 0 B -> 44.37 KB (+44.37 KB)<br />0 B -> 14.31 KB | -
20-
699.chunk.js | bundled<br />gzip | 0 B -> 26.39 KB (+26.39 KB)<br />0 B -> 6.14 KB | -
14+
Asset | File Size | % Changed
15+
----- | --------- | ---------
16+
296.chunk.js | 0 B -> 124.57 KB (+124.57 KB)<br />0 B -> 35.05 KB (gzip) | -
17+
288.chunk.js | 0 B -> 57.24 KB (+57.24 KB)<br />0 B -> 16.33 KB (gzip) | -
18+
920.chunk.js | 0 B -> 54.98 KB (+54.98 KB)<br />0 B -> 17.08 KB (gzip) | -
19+
912.chunk.js | 0 B -> 44.37 KB (+44.37 KB)<br />0 B -> 14.31 KB (gzip) | -
20+
699.chunk.js | 0 B -> 26.39 KB (+26.39 KB)<br />0 B -> 6.14 KB (gzip) | -
2121
2222
**Removed**
2323
2424
No assets were removed
2525
2626
**Bigger**
2727
28-
Asset | Type | File Size | % Changed
29-
----- | ---- | --------- | ---------
30-
manifest.json | bundled<br />gzip | 91 B -> 551 B (+460 B)<br />N/A -> 151 B | +505.49%
28+
Asset | File Size | % Changed
29+
----- | --------- | ---------
30+
manifest.json | 91 B -> 551 B (+460 B)<br />N/A -> 151 B (gzip) | +505.49%
3131
3232
**Smaller**
3333
34-
Asset | Type | File Size | % Changed
35-
----- | ---- | --------- | ---------
36-
app.bundle.js | bundled<br />gzip | 1.29 MB -> 1.04 MB (-254.35 KB)<br />N/A -> 297.38 KB | -19.29%
34+
Asset | File Size | % Changed
35+
----- | --------- | ---------
36+
app.bundle.js | 1.29 MB -> 1.04 MB (-254.35 KB)<br />N/A -> 297.38 KB (gzip) | -19.29%
3737
3838
**Unchanged**
3939
@@ -43,9 +43,9 @@ No assets were unchanged"
4343
exports[`Shows stats when files are removed 1`] = `
4444
"**Total**
4545
46-
Files count | Type | Total bundle size | % Changed
47-
----------- | ---- | ----------------- | ---------
48-
7 -> 2 | bundled<br />gzip | 1.34 MB -> 1.29 MB (-53.65 KB)<br />386.44 KB -> N/A | -3.91%"
46+
Files count | Total bundle size | % Changed
47+
----------- | ----------------- | ---------
48+
7 -> 2 | 1.34 MB -> 1.29 MB (-53.65 KB)<br />386.44 KB -> N/A (gzip) | -3.91%"
4949
`;
5050

5151
exports[`Shows stats when files are removed 2`] = `
@@ -55,25 +55,25 @@ No assets were added
5555
5656
**Removed**
5757
58-
Asset | Type | File Size | % Changed
59-
----- | ---- | --------- | ---------
60-
296.chunk.js | bundled<br />gzip | 124.57 KB -> 0 B (-124.57 KB)<br />35.05 KB -> 0 B | -100%
61-
288.chunk.js | bundled<br />gzip | 57.24 KB -> 0 B (-57.24 KB)<br />16.33 KB -> 0 B | -100%
62-
920.chunk.js | bundled<br />gzip | 54.98 KB -> 0 B (-54.98 KB)<br />17.08 KB -> 0 B | -100%
63-
912.chunk.js | bundled<br />gzip | 44.37 KB -> 0 B (-44.37 KB)<br />14.31 KB -> 0 B | -100%
64-
699.chunk.js | bundled<br />gzip | 26.39 KB -> 0 B (-26.39 KB)<br />6.14 KB -> 0 B | -100%
58+
Asset | File Size | % Changed
59+
----- | --------- | ---------
60+
296.chunk.js | 124.57 KB -> 0 B (-124.57 KB)<br />35.05 KB -> 0 B (gzip) | -100%
61+
288.chunk.js | 57.24 KB -> 0 B (-57.24 KB)<br />16.33 KB -> 0 B (gzip) | -100%
62+
920.chunk.js | 54.98 KB -> 0 B (-54.98 KB)<br />17.08 KB -> 0 B (gzip) | -100%
63+
912.chunk.js | 44.37 KB -> 0 B (-44.37 KB)<br />14.31 KB -> 0 B (gzip) | -100%
64+
699.chunk.js | 26.39 KB -> 0 B (-26.39 KB)<br />6.14 KB -> 0 B (gzip) | -100%
6565
6666
**Bigger**
6767
68-
Asset | Type | File Size | % Changed
69-
----- | ---- | --------- | ---------
70-
app.bundle.js | bundled<br />gzip | 1.04 MB -> 1.29 MB (+254.35 KB)<br />297.38 KB -> N/A | +23.91%
68+
Asset | File Size | % Changed
69+
----- | --------- | ---------
70+
app.bundle.js | 1.04 MB -> 1.29 MB (+254.35 KB)<br />297.38 KB -> N/A (gzip) | +23.91%
7171
7272
**Smaller**
7373
74-
Asset | Type | File Size | % Changed
75-
----- | ---- | --------- | ---------
76-
manifest.json | bundled<br />gzip | 551 B -> 91 B (-460 B)<br />151 B -> N/A | -83.48%
74+
Asset | File Size | % Changed
75+
----- | --------- | ---------
76+
manifest.json | 551 B -> 91 B (-460 B)<br />151 B -> N/A (gzip) | -83.48%
7777
7878
**Unchanged**
7979
@@ -83,9 +83,9 @@ No assets were unchanged"
8383
exports[`Shows stats when files are unchanged 1`] = `
8484
"**Total**
8585
86-
Files count | Type | Total bundle size | % Changed
87-
----------- | ---- | ----------------- | ---------
88-
7 | bundled<br />gzip | 1.34 MB<br />386.44 KB | 0%"
86+
Files count | Total bundle size | % Changed
87+
----------- | ----------------- | ---------
88+
7 | 1.34 MB<br />386.44 KB | 0%"
8989
`;
9090

9191
exports[`Shows stats when files are unchanged 2`] = `
@@ -107,25 +107,25 @@ No assets were smaller
107107
108108
**Unchanged**
109109
110-
Asset | Type | File Size | % Changed
111-
----- | ---- | --------- | ---------
112-
app.bundle.js | bundled<br />gzip | 1.04 MB<br />297.38 KB | 0%
113-
296.chunk.js | bundled<br />gzip | 124.57 KB<br />35.05 KB | 0%
114-
288.chunk.js | bundled<br />gzip | 57.24 KB<br />16.33 KB | 0%
115-
920.chunk.js | bundled<br />gzip | 54.98 KB<br />17.08 KB | 0%
116-
912.chunk.js | bundled<br />gzip | 44.37 KB<br />14.31 KB | 0%
117-
699.chunk.js | bundled<br />gzip | 26.39 KB<br />6.14 KB | 0%
118-
manifest.json | bundled<br />gzip | 551 B<br />151 B | 0%"
110+
Asset | File Size | % Changed
111+
----- | --------- | ---------
112+
app.bundle.js | 1.04 MB<br />297.38 KB | 0%
113+
296.chunk.js | 124.57 KB<br />35.05 KB | 0%
114+
288.chunk.js | 57.24 KB<br />16.33 KB | 0%
115+
920.chunk.js | 54.98 KB<br />17.08 KB | 0%
116+
912.chunk.js | 44.37 KB<br />14.31 KB | 0%
117+
699.chunk.js | 26.39 KB<br />6.14 KB | 0%
118+
manifest.json | 551 B<br />151 B | 0%"
119119
`;
120120

121121
exports[`displays module information when files are added/removed/changed 1`] = `
122122
"
123123
<details>
124-
<summary>**Changeset**</summary>
124+
<summary>Changeset</summary>
125125
126126
File | Δ | Size
127127
---- | - | ----
128-
\`src/client/this/file/has/a/long/name/so-that-it-will-hopefully-wrap.tsx\` | 🆕 +2.72 KB | 0 B -> 2.72 KB
128+
\`src/client/this/file/has/a/long/name/so-that-it-will-hopefully-wrap.tsx\` | 🆕 +2.72 KB | 0 B -> 2.72 KB
129129
\`src/client/this-file-was-added.ts\` | 🆕 +1.46 KB | 0 B -> 1.46 KB
130130
\`src/client/this-is-another-file-with-a-long-name-to-test-the-table-sizing.tsx\` | 🆕 +1.04 KB | 0 B -> 1.04 KB
131131
\`src/client/helpers/this-file-is-much-larger.ts\` | 📈 +11.66 KB (+865.77%) | 1.35 KB -> 13.01 KB
@@ -142,7 +142,7 @@ File | Δ | Size
142142

143143
exports[`displays no module information when unchanged 1`] = `
144144
"
145-
**Changeset**
145+
Changeset
146146
147147
No files were changed"
148148
`;

__tests__/main.test.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
11
import {expect, test} from '@jest/globals'
22
import {getStatsDiff} from '../src/get-stats-diff'
33
import {getChunkModuleDiff} from '../src/get-chunk-module-diff'
4-
import {getCommentBody} from '../src/to-comment-body'
54
import {
65
printAssetTablesByGroup,
76
printChunkModulesTable,
87
printTotalAssetTable
98
} from '../src/print-markdown'
109
import {AssetDiff} from '../src/types'
10+
import {readFile} from 'node:fs/promises'
11+
import {resolve} from 'node:path'
12+
import {StatsCompilation} from 'webpack'
1113

12-
test('Shows stats when files are removed', () => {
14+
async function readJsonFile(path: string): Promise<StatsCompilation> {
15+
const data = await readFile(resolve(__dirname, path), 'utf8')
16+
return JSON.parse(data)
17+
}
18+
19+
test('Shows stats when files are removed', async () => {
1320
const statsDiff = getStatsDiff(
14-
require('./__mocks__/old-stats-assets.json'),
15-
require('./__mocks__/new-stats-assets.json')
21+
await readJsonFile('./__mocks__/old-stats-assets.json'),
22+
await readJsonFile('./__mocks__/new-stats-assets.json')
1623
)
1724

1825
expect(printTotalAssetTable(statsDiff)).toMatchSnapshot()
1926
expect(printAssetTablesByGroup(statsDiff)).toMatchSnapshot()
2027
})
2128

22-
test('Shows stats when files are added', () => {
29+
test('Shows stats when files are added', async () => {
2330
const statsDiff = getStatsDiff(
24-
require('./__mocks__/new-stats-assets.json'),
25-
require('./__mocks__/old-stats-assets.json')
31+
await readJsonFile('./__mocks__/new-stats-assets.json'),
32+
await readJsonFile('./__mocks__/old-stats-assets.json')
2633
)
2734

2835
expect(printTotalAssetTable(statsDiff)).toMatchSnapshot()
2936
expect(printAssetTablesByGroup(statsDiff)).toMatchSnapshot()
3037
})
3138

32-
test('Shows stats when files are unchanged', () => {
39+
test('Shows stats when files are unchanged', async () => {
3340
const statsDiff = getStatsDiff(
34-
require('./__mocks__/old-stats-assets.json'),
35-
require('./__mocks__/old-stats-assets.json')
41+
await readJsonFile('./__mocks__/old-stats-assets.json'),
42+
await readJsonFile('./__mocks__/old-stats-assets.json')
3643
)
3744

3845
expect(printTotalAssetTable(statsDiff)).toMatchSnapshot()
3946
expect(printAssetTablesByGroup(statsDiff)).toMatchSnapshot()
4047
})
4148

42-
test('computes the correct module diff information', () => {
49+
test('computes the correct module diff information', async () => {
4350
const statsDiff = getChunkModuleDiff(
44-
require('./__mocks__/old-stats-with-chunks.json'),
45-
require('./__mocks__/new-stats-with-chunks.json')
51+
await readJsonFile('./__mocks__/old-stats-with-chunks.json'),
52+
await readJsonFile('./__mocks__/new-stats-with-chunks.json')
4653
)
4754

4855
expect(statsDiff?.added).toContainEqual({
@@ -78,28 +85,28 @@ test('computes the correct module diff information', () => {
7885
expect(statsDiff?.total.diffPercentage).toEqual(0)
7986
})
8087

81-
test('displays module information when files are added/removed/changed', () => {
88+
test('displays module information when files are added/removed/changed', async () => {
8289
const statsDiff = getChunkModuleDiff(
83-
require('./__mocks__/old-stats-with-chunks.json'),
84-
require('./__mocks__/new-stats-with-chunks.json')
90+
await readJsonFile('./__mocks__/old-stats-with-chunks.json'),
91+
await readJsonFile('./__mocks__/new-stats-with-chunks.json')
8592
)
8693

8794
expect(printChunkModulesTable(statsDiff)).toMatchSnapshot()
8895
})
8996

90-
test('displays no module information when unchanged', () => {
97+
test('displays no module information when unchanged', async () => {
9198
const statsDiff = getChunkModuleDiff(
92-
require('./__mocks__/old-stats-with-chunks.json'),
93-
require('./__mocks__/old-stats-with-chunks.json')
99+
await readJsonFile('./__mocks__/old-stats-with-chunks.json'),
100+
await readJsonFile('./__mocks__/old-stats-with-chunks.json')
94101
)
95102

96103
expect(printChunkModulesTable(statsDiff)).toMatchSnapshot()
97104
})
98105

99-
test('does not display module information when it does not exist', () => {
106+
test('does not display module information when it does not exist', async () => {
100107
const statsDiff = getChunkModuleDiff(
101-
require('./__mocks__/old-stats-assets.json'),
102-
require('./__mocks__/old-stats-assets.json')
108+
await readJsonFile('./__mocks__/old-stats-assets.json'),
109+
await readJsonFile('./__mocks__/old-stats-assets.json')
103110
)
104111

105112
expect(printChunkModulesTable(statsDiff)).toMatchSnapshot()

0 commit comments

Comments
 (0)