Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Markdown comment #160

Merged
merged 16 commits into from
Aug 4, 2022
Merged
12 changes: 6 additions & 6 deletions __tests__/__mocks__/new-stats-with-chunks.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@
},
{
"size": 2790,
"name": "./src/client/routes.tsx"
"name": "./src/client/this/file/has/a/long/name/so-that-it-will-hopefully-wrap.tsx"
},
{
"size": 1067,
"name": "./src/client/render-memex.tsx"
"name": "./src/client/this-is-another-file-with-a-long-name-to-test-the-table-sizing.tsx"
},
{
"size": 878,
Expand Down Expand Up @@ -330,12 +330,12 @@
"name": "./src/client/services/github-enabled-features-service.ts"
},
{
"size": 11949,
"name": "./src/client/app.tsx"
"size": 10,
"name": "./src/client/this-file-is-much-smaller.tsx"
},
{
"size": 1379,
"name": "./src/client/helpers/initial-state.ts"
"size": 13318,
"name": "./src/client/helpers/this-file-is-much-larger.ts"
},
{
"size": 103,
Expand Down
4 changes: 2 additions & 2 deletions __tests__/__mocks__/old-stats-with-chunks.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,11 @@
},
{
"size": 11949,
"name": "./src/client/app.tsx"
"name": "./src/client/this-file-is-much-smaller.tsx"
},
{
"size": 1379,
"name": "./src/client/helpers/initial-state.ts"
"name": "./src/client/helpers/this-file-is-much-larger.ts"
},
{
"size": 103,
Expand Down
129 changes: 74 additions & 55 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ No assets were added

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%
296.chunk.js | bundled<br />gzip | 124.57 KB -> 0 B (-124.57 KB)<br />35.05 KB -> 0 B | -100%
288.chunk.js | bundled<br />gzip | 57.24 KB -> 0 B (-57.24 KB)<br />16.33 KB -> 0 B | -100%
920.chunk.js | bundled<br />gzip | 54.98 KB -> 0 B (-54.98 KB)<br />17.08 KB -> 0 B | -100%
912.chunk.js | bundled<br />gzip | 44.37 KB -> 0 B (-44.37 KB)<br />14.31 KB -> 0 B | -100%
699.chunk.js | bundled<br />gzip | 26.39 KB -> 0 B (-26.39 KB)<br />6.14 KB -> 0 B | -100%

**Bigger**

Expand All @@ -44,7 +44,7 @@ app.bundle.js | bundled<br />gzip | 1.04 MB -> 1.29 MB (+254.35 KB)<br />297.38

Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
manifest.json | bundled<br />gzip | 551 Bytes -> 91 Bytes (-460 Bytes)<br />151 Bytes -> N/A | -83.48%
manifest.json | bundled<br />gzip | 551 B -> 91 B (-460 B)<br />151 B -> N/A | -83.48%

**Unchanged**

Expand All @@ -66,11 +66,11 @@ Files count | Type | Total bundle size | % Changed

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 | -
296.chunk.js | bundled<br />gzip | 0 B -> 124.57 KB (+124.57 KB)<br />0 B -> 35.05 KB | -
288.chunk.js | bundled<br />gzip | 0 B -> 57.24 KB (+57.24 KB)<br />0 B -> 16.33 KB | -
920.chunk.js | bundled<br />gzip | 0 B -> 54.98 KB (+54.98 KB)<br />0 B -> 17.08 KB | -
912.chunk.js | bundled<br />gzip | 0 B -> 44.37 KB (+44.37 KB)<br />0 B -> 14.31 KB | -
699.chunk.js | bundled<br />gzip | 0 B -> 26.39 KB (+26.39 KB)<br />0 B -> 6.14 KB | -

**Removed**

Expand All @@ -80,7 +80,7 @@ No assets were removed

Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
manifest.json | bundled<br />gzip | 91 Bytes -> 551 Bytes (+460 Bytes)<br />N/A -> 151 Bytes | +505.49%
manifest.json | bundled<br />gzip | 91 B -> 551 B (+460 B)<br />N/A -> 151 B | +505.49%

**Smaller**

Expand Down Expand Up @@ -130,7 +130,7 @@ app.bundle.js | bundled<br />gzip | 1.04 MB<br />297.38 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%`)
manifest.json | bundled<br />gzip | 551 B<br />151 B | 0%`)
})

test('computes the correct module diff information', () => {
Expand All @@ -139,42 +139,34 @@ test('computes the correct module diff information', () => {
require('./__mocks__/new-stats-with-chunks.json')
)

expect(statsDiff?.added).toEqual([
{
name: './src/client/this-file-was-added.ts',
diff: 1496,
diffPercentage: Infinity,
new: {size: 1496, gzipSize: NaN},
old: {size: 0, gzipSize: 0}
}
] as AssetDiff[])
expect(statsDiff?.bigger).toEqual([
{
name: './src/client/this-file-grew-larger.tsx',
diff: 200,
diffPercentage: 35.58719,
new: {size: 762, gzipSize: NaN},
old: {size: 562, gzipSize: NaN}
}
] as AssetDiff[])
expect(statsDiff?.smaller).toEqual([
{
name: './src/client/helpers/this-file-grew-smaller.ts',
diff: -200,
diffPercentage: -7.94281,
new: {size: 2318, gzipSize: NaN},
old: {size: 2518, gzipSize: NaN}
}
] as AssetDiff[])
expect(statsDiff?.removed).toEqual([
{
name: './src/client/this-file-will-be-deleted.ts',
diff: -1496,
diffPercentage: -100,
new: {size: 0, gzipSize: 0},
old: {size: 1496, gzipSize: NaN}
}
] as AssetDiff[])
expect(statsDiff?.added).toContainEqual({
name: './src/client/this-file-was-added.ts',
diff: 1496,
diffPercentage: Infinity,
new: {size: 1496, gzipSize: NaN},
old: {size: 0, gzipSize: 0}
} as AssetDiff)
expect(statsDiff?.bigger).toContainEqual({
name: './src/client/this-file-grew-larger.tsx',
diff: 200,
diffPercentage: 35.58719,
new: {size: 762, gzipSize: NaN},
old: {size: 562, gzipSize: NaN}
} as AssetDiff)
expect(statsDiff?.smaller).toContainEqual({
name: './src/client/helpers/this-file-grew-smaller.ts',
diff: -200,
diffPercentage: -7.94281,
new: {size: 2318, gzipSize: NaN},
old: {size: 2518, gzipSize: NaN}
} as AssetDiff)
expect(statsDiff?.removed).toContainEqual({
name: './src/client/this-file-will-be-deleted.ts',
diff: -1496,
diffPercentage: -100,
new: {size: 0, gzipSize: 0},
old: {size: 1496, gzipSize: NaN}
} as AssetDiff)
expect(statsDiff?.total.new).toEqual(statsDiff?.total.old)
expect(statsDiff?.total.diff).toEqual(0)
expect(statsDiff?.total.diffPercentage).toEqual(0)
Expand All @@ -186,15 +178,42 @@ test('displays module information when files are added/removed/changed', () => {
require('./__mocks__/new-stats-with-chunks.json')
)

console.log(printChunkModulesTable(statsDiff))

expect(printChunkModulesTable(statsDiff)).toEqual(`
**Changeset**

File | Size | % Changed
---- | ---- | ---------
./src/client/this-file-was-added.ts | 0 Bytes -> 1.46 KB (+1.46 KB) | -
./src/client/this-file-grew-larger.tsx | 562 Bytes -> 762 Bytes (+200 Bytes) | +35.59%
./src/client/helpers/this-file-grew-smaller.ts | 2.46 KB -> 2.26 KB (-200 Bytes) | -7.94%
./src/client/this-file-will-be-deleted.ts | 1.46 KB -> 0 Bytes (-1.46 KB) | -100%`)
File | Δ
---- | -
\`src/client/this/file/has/a/long/name/so-that-it-will-hopefully-wrap.tsx\` | 🆕 +2.72 KB
\`src/client/this-file-was-added.ts\` | 🆕 +1.46 KB
\`src/client/this-is-another-file-with-a-long-name-to-test-the-table-sizing.tsx\` | 🆕 +1.04 KB
\`src/client/helpers/this-file-is-much-larger.ts\` | 📈 +11.66 KB (+865.77%)
\`src/client/this-file-grew-larger.tsx\` | 📈 +200 B (+35.59%)
\`src/client/helpers/this-file-grew-smaller.ts\` | 📉 -200 B (-7.94%)
\`src/client/this-file-is-much-smaller.tsx\` | 📉 -11.66 KB (-99.92%)
\`src/client/routes.tsx\` | 🔥 -2.72 KB (-100%)
\`src/client/this-file-will-be-deleted.ts\` | 🔥 -1.46 KB (-100%)
\`src/client/render-memex.tsx\` | 🔥 -1.04 KB (-100%)

<details>
<summary>View detailed changes</summary>

File | Old | New | Δ
---- | --- | --- | -
\`src/client/this/file/has/a/long/name/so-that-it-will-hopefully-wrap.tsx\` | 0 B | 2.72 KB | 🆕 +2.72 KB
\`src/client/this-file-was-added.ts\` | 0 B | 1.46 KB | 🆕 +1.46 KB
\`src/client/this-is-another-file-with-a-long-name-to-test-the-table-sizing.tsx\` | 0 B | 1.04 KB | 🆕 +1.04 KB
\`src/client/helpers/this-file-is-much-larger.ts\` | 1.35 KB | 13.01 KB | 📈 +11.66 KB (+865.77%)
\`src/client/this-file-grew-larger.tsx\` | 562 B | 762 B | 📈 +200 B (+35.59%)
\`src/client/helpers/this-file-grew-smaller.ts\` | 2.46 KB | 2.26 KB | 📉 -200 B (-7.94%)
\`src/client/this-file-is-much-smaller.tsx\` | 11.67 KB | 10 B | 📉 -11.66 KB (-99.92%)
\`src/client/routes.tsx\` | 2.72 KB | 0 B | 🔥 -2.72 KB (-100%)
\`src/client/this-file-will-be-deleted.ts\` | 1.46 KB | 0 B | 🔥 -1.46 KB (-100%)
\`src/client/render-memex.tsx\` | 1.04 KB | 0 B | 🔥 -1.04 KB (-100%)

</details>
`)
})

test('displays no module information when unchanged', () => {
Expand Down
66 changes: 57 additions & 9 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/file-sizes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const BYTES_PER_KILOBYTE = 1024
const denominations = [
'Bytes', // 1 Byte
'B', // 1 Byte
'KB', // 1 Kilobyte
'MB', // 1 Megabyte
'GB', // 1 Gigabyte
Expand Down
Loading