Skip to content

Commit

Permalink
Merge pull request #24 from github/handle-gzip-display
Browse files Browse the repository at this point in the history
handle gzipped displaying
  • Loading branch information
mattcosta7 authored Jan 22, 2022
2 parents c6574c2 + 467ab16 commit 044adc9
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 309 deletions.
284 changes: 44 additions & 240 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,103 +11,37 @@ test('Shows stats when files are removed', () => {
require('./__mocks__/old-stats-assets.json'),
require('./__mocks__/new-stats-assets.json')
)
expect(statsDiff).toEqual({
added: [],
bigger: [
{
diff: 260452,
diffPercentage: 23.90567,
name: 'app.bundle.js',
newSize: 1349951,
oldSize: 1089499
}
],
removed: [
{
diff: -127558,
diffPercentage: -100,
name: '296.chunk.js',
newSize: 0,
oldSize: 127558
},
{
diff: -58610,
diffPercentage: -100,
name: '288.chunk.js',
newSize: 0,
oldSize: 58610
},
{
diff: -56302,
diffPercentage: -100,
name: '920.chunk.js',
newSize: 0,
oldSize: 56302
},
{
diff: -45438,
diffPercentage: -100,
name: '912.chunk.js',
newSize: 0,
oldSize: 45438
},
{
diff: -27026,
diffPercentage: -100,
name: '699.chunk.js',
newSize: 0,
oldSize: 27026
}
],
smaller: [
{
diff: -460,
diffPercentage: -83.48457,
name: 'manifest.json',
newSize: 91,
oldSize: 551
}
],
total: {
diff: -54942,
diffPercentage: -3.91051,
name: '7 -> 2',
newSize: 1350042,
oldSize: 1404984
},
unchanged: []
})

expect(printTotalAssetTable(statsDiff)).toEqual(`**Total**
Files count | Total bundle size | % Changed
----------- | ----------------- | ---------
7 -> 2 | 1.34 MB -> 1.29 MB (-53.65 KB) | -3.91%`)
Files count | Type | Total bundle size | % Changed
----------- | ---- | ----------------- | ---------
7 -> 2 | bundled<br />gzip | 1.34 MB -> 1.29 MB (-53.65 KB)<br />386.44 KB -> N/A | -3.91%`)
expect(printAssetTablesByGroup(statsDiff)).toEqual(`**Added**
No assets were added
**Removed**
Asset | File Size | % Changed
----- | --------- | ---------
296.chunk.js | 124.57 KB -> 0 Bytes (-124.57 KB) | -100%
288.chunk.js | 57.24 KB -> 0 Bytes (-57.24 KB) | -100%
920.chunk.js | 54.98 KB -> 0 Bytes (-54.98 KB) | -100%
912.chunk.js | 44.37 KB -> 0 Bytes (-44.37 KB) | -100%
699.chunk.js | 26.39 KB -> 0 Bytes (-26.39 KB) | -100%
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
296.chunk.js | bundled<br />gzip | 124.57 KB -> 0 Bytes (-124.57 KB)<br />35.05 KB -> 0 Bytes | -100%
288.chunk.js | bundled<br />gzip | 57.24 KB -> 0 Bytes (-57.24 KB)<br />16.33 KB -> 0 Bytes | -100%
920.chunk.js | bundled<br />gzip | 54.98 KB -> 0 Bytes (-54.98 KB)<br />17.08 KB -> 0 Bytes | -100%
912.chunk.js | bundled<br />gzip | 44.37 KB -> 0 Bytes (-44.37 KB)<br />14.31 KB -> 0 Bytes | -100%
699.chunk.js | bundled<br />gzip | 26.39 KB -> 0 Bytes (-26.39 KB)<br />6.14 KB -> 0 Bytes | -100%
**Bigger**
Asset | File Size | % Changed
----- | --------- | ---------
app.bundle.js | 1.04 MB -> 1.29 MB (+254.35 KB) | +23.91%
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
app.bundle.js | bundled<br />gzip | 1.04 MB -> 1.29 MB (+254.35 KB)<br />297.38 KB -> N/A | +23.91%
**Smaller**
Asset | File Size | % Changed
----- | --------- | ---------
manifest.json | 551 Bytes -> 91 Bytes (-460 Bytes) | -83.48%
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
manifest.json | bundled<br />gzip | 551 Bytes -> 91 Bytes (-460 Bytes)<br />151 Bytes -> N/A | -83.48%
**Unchanged**
Expand All @@ -119,103 +53,37 @@ test('Shows stats when files are added', () => {
require('./__mocks__/new-stats-assets.json'),
require('./__mocks__/old-stats-assets.json')
)
expect(statsDiff).toEqual({
added: [
{
diff: 127558,
diffPercentage: Infinity,
name: '296.chunk.js',
newSize: 127558,
oldSize: 0
},
{
diff: 58610,
diffPercentage: Infinity,
name: '288.chunk.js',
newSize: 58610,
oldSize: 0
},
{
diff: 56302,
diffPercentage: Infinity,
name: '920.chunk.js',
newSize: 56302,
oldSize: 0
},
{
diff: 45438,
diffPercentage: Infinity,
name: '912.chunk.js',
newSize: 45438,
oldSize: 0
},
{
diff: 27026,
diffPercentage: Infinity,
name: '699.chunk.js',
newSize: 27026,
oldSize: 0
}
],
bigger: [
{
diff: 460,
diffPercentage: 505.49451,
name: 'manifest.json',
newSize: 551,
oldSize: 91
}
],
removed: [],
smaller: [
{
diff: -260452,
diffPercentage: -19.29344,
name: 'app.bundle.js',
newSize: 1089499,
oldSize: 1349951
}
],
total: {
diff: 54942,
diffPercentage: 4.06965,
name: '2 -> 7',
newSize: 1404984,
oldSize: 1350042
},
unchanged: []
})

expect(printTotalAssetTable(statsDiff)).toEqual(`**Total**
Files count | Total bundle size | % Changed
----------- | ----------------- | ---------
2 -> 7 | 1.29 MB -> 1.34 MB (+53.65 KB) | +4.07%`)
Files count | Type | Total bundle size | % Changed
----------- | ---- | ----------------- | ---------
2 -> 7 | bundled<br />gzip | 1.29 MB -> 1.34 MB (+53.65 KB)<br />N/A -> 386.44 KB | +4.07%`)
expect(printAssetTablesByGroup(statsDiff)).toEqual(`**Added**
Asset | File Size | % Changed
----- | --------- | ---------
296.chunk.js | 0 Bytes -> 124.57 KB (+124.57 KB) | -
288.chunk.js | 0 Bytes -> 57.24 KB (+57.24 KB) | -
920.chunk.js | 0 Bytes -> 54.98 KB (+54.98 KB) | -
912.chunk.js | 0 Bytes -> 44.37 KB (+44.37 KB) | -
699.chunk.js | 0 Bytes -> 26.39 KB (+26.39 KB) | -
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
296.chunk.js | bundled<br />gzip | 0 Bytes -> 124.57 KB (+124.57 KB)<br />0 Bytes -> 35.05 KB | -
288.chunk.js | bundled<br />gzip | 0 Bytes -> 57.24 KB (+57.24 KB)<br />0 Bytes -> 16.33 KB | -
920.chunk.js | bundled<br />gzip | 0 Bytes -> 54.98 KB (+54.98 KB)<br />0 Bytes -> 17.08 KB | -
912.chunk.js | bundled<br />gzip | 0 Bytes -> 44.37 KB (+44.37 KB)<br />0 Bytes -> 14.31 KB | -
699.chunk.js | bundled<br />gzip | 0 Bytes -> 26.39 KB (+26.39 KB)<br />0 Bytes -> 6.14 KB | -
**Removed**
No assets were removed
**Bigger**
Asset | File Size | % Changed
----- | --------- | ---------
manifest.json | 91 Bytes -> 551 Bytes (+460 Bytes) | +505.49%
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
manifest.json | bundled<br />gzip | 91 Bytes -> 551 Bytes (+460 Bytes)<br />N/A -> 151 Bytes | +505.49%
**Smaller**
Asset | File Size | % Changed
----- | --------- | ---------
app.bundle.js | 1.29 MB -> 1.04 MB (-254.35 KB) | -19.29%
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
app.bundle.js | bundled<br />gzip | 1.29 MB -> 1.04 MB (-254.35 KB)<br />N/A -> 297.38 KB | -19.29%
**Unchanged**
Expand All @@ -227,76 +95,12 @@ test('Shows stats when files are unchanged', () => {
require('./__mocks__/old-stats-assets.json'),
require('./__mocks__/old-stats-assets.json')
)
expect(statsDiff).toEqual({
added: [],
bigger: [],
removed: [],
smaller: [],
total: {
diff: 0,
diffPercentage: 0,
name: '7',
newSize: 1404984,
oldSize: 1404984
},
unchanged: [
{
diff: 0,
diffPercentage: 0,
name: 'app.bundle.js',
newSize: 1089499,
oldSize: 1089499
},
{
diff: 0,
diffPercentage: 0,
name: '296.chunk.js',
newSize: 127558,
oldSize: 127558
},
{
diff: 0,
diffPercentage: 0,
name: '288.chunk.js',
newSize: 58610,
oldSize: 58610
},
{
diff: 0,
diffPercentage: 0,
name: '920.chunk.js',
newSize: 56302,
oldSize: 56302
},
{
diff: 0,
diffPercentage: 0,
name: '912.chunk.js',
newSize: 45438,
oldSize: 45438
},
{
diff: 0,
diffPercentage: 0,
name: '699.chunk.js',
newSize: 27026,
oldSize: 27026
},
{
diff: 0,
diffPercentage: 0,
name: 'manifest.json',
newSize: 551,
oldSize: 551
}
]
})

expect(printTotalAssetTable(statsDiff)).toEqual(`**Total**
Files count | Total bundle size | % Changed
----------- | ----------------- | ---------
7 | 1.34 MB | 0%`)
Files count | Type | Total bundle size | % Changed
----------- | ---- | ----------------- | ---------
7 | bundled<br />gzip | 1.34 MB<br />386.44 KB | 0%`)
expect(printAssetTablesByGroup(statsDiff)).toEqual(`**Added**
No assets were added
Expand All @@ -315,13 +119,13 @@ No assets were smaller
**Unchanged**
Asset | File Size | % Changed
----- | --------- | ---------
app.bundle.js | 1.04 MB | 0%
296.chunk.js | 124.57 KB | 0%
288.chunk.js | 57.24 KB | 0%
920.chunk.js | 54.98 KB | 0%
912.chunk.js | 44.37 KB | 0%
699.chunk.js | 26.39 KB | 0%
manifest.json | 551 Bytes | 0%`)
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
app.bundle.js | bundled<br />gzip | 1.04 MB<br />297.38 KB | 0%
296.chunk.js | bundled<br />gzip | 124.57 KB<br />35.05 KB | 0%
288.chunk.js | bundled<br />gzip | 57.24 KB<br />16.33 KB | 0%
920.chunk.js | bundled<br />gzip | 54.98 KB<br />17.08 KB | 0%
912.chunk.js | bundled<br />gzip | 44.37 KB<br />14.31 KB | 0%
699.chunk.js | bundled<br />gzip | 26.39 KB<br />6.14 KB | 0%
manifest.json | bundled<br />gzip | 551 Bytes<br />151 Bytes | 0%`)
})
Loading

0 comments on commit 044adc9

Please sign in to comment.