Skip to content

Commit

Permalink
Merge pull request #301 from github/top-100-changeset
Browse files Browse the repository at this point in the history
Limit changeset to first 100 rows
  • Loading branch information
mattcosta7 authored Jan 25, 2023
2 parents 4f9c4d1 + 209158d commit b761041
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 128 deletions.
94 changes: 47 additions & 47 deletions __tests__/__snapshots__/main.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
exports[`Shows stats when files are added 1`] = `
"**Total**
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%"
Files count | Total bundle size | % Changed
----------- | ----------------- | ---------
2 -> 7 | 1.29 MB -> 1.34 MB (+53.65 KB)<br />N/A -> 386.44 KB (gzip) | +4.07%"
`;

exports[`Shows stats when files are added 2`] = `
"**Added**
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
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 | -
Asset | File Size | % Changed
----- | --------- | ---------
296.chunk.js | 0 B -> 124.57 KB (+124.57 KB)<br />0 B -> 35.05 KB (gzip) | -
288.chunk.js | 0 B -> 57.24 KB (+57.24 KB)<br />0 B -> 16.33 KB (gzip) | -
920.chunk.js | 0 B -> 54.98 KB (+54.98 KB)<br />0 B -> 17.08 KB (gzip) | -
912.chunk.js | 0 B -> 44.37 KB (+44.37 KB)<br />0 B -> 14.31 KB (gzip) | -
699.chunk.js | 0 B -> 26.39 KB (+26.39 KB)<br />0 B -> 6.14 KB (gzip) | -
**Removed**
No assets were removed
**Bigger**
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
manifest.json | bundled<br />gzip | 91 B -> 551 B (+460 B)<br />N/A -> 151 B | +505.49%
Asset | File Size | % Changed
----- | --------- | ---------
manifest.json | 91 B -> 551 B (+460 B)<br />N/A -> 151 B (gzip) | +505.49%
**Smaller**
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%
Asset | File Size | % Changed
----- | --------- | ---------
app.bundle.js | 1.29 MB -> 1.04 MB (-254.35 KB)<br />N/A -> 297.38 KB (gzip) | -19.29%
**Unchanged**
Expand All @@ -43,9 +43,9 @@ No assets were unchanged"
exports[`Shows stats when files are removed 1`] = `
"**Total**
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%"
Files count | Total bundle size | % Changed
----------- | ----------------- | ---------
7 -> 2 | 1.34 MB -> 1.29 MB (-53.65 KB)<br />386.44 KB -> N/A (gzip) | -3.91%"
`;

exports[`Shows stats when files are removed 2`] = `
Expand All @@ -55,25 +55,25 @@ No assets were added
**Removed**
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
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%
Asset | File Size | % Changed
----- | --------- | ---------
296.chunk.js | 124.57 KB -> 0 B (-124.57 KB)<br />35.05 KB -> 0 B (gzip) | -100%
288.chunk.js | 57.24 KB -> 0 B (-57.24 KB)<br />16.33 KB -> 0 B (gzip) | -100%
920.chunk.js | 54.98 KB -> 0 B (-54.98 KB)<br />17.08 KB -> 0 B (gzip) | -100%
912.chunk.js | 44.37 KB -> 0 B (-44.37 KB)<br />14.31 KB -> 0 B (gzip) | -100%
699.chunk.js | 26.39 KB -> 0 B (-26.39 KB)<br />6.14 KB -> 0 B (gzip) | -100%
**Bigger**
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%
Asset | File Size | % Changed
----- | --------- | ---------
app.bundle.js | 1.04 MB -> 1.29 MB (+254.35 KB)<br />297.38 KB -> N/A (gzip) | +23.91%
**Smaller**
Asset | Type | File Size | % Changed
----- | ---- | --------- | ---------
manifest.json | bundled<br />gzip | 551 B -> 91 B (-460 B)<br />151 B -> N/A | -83.48%
Asset | File Size | % Changed
----- | --------- | ---------
manifest.json | 551 B -> 91 B (-460 B)<br />151 B -> N/A (gzip) | -83.48%
**Unchanged**
Expand All @@ -83,9 +83,9 @@ No assets were unchanged"
exports[`Shows stats when files are unchanged 1`] = `
"**Total**
Files count | Type | Total bundle size | % Changed
----------- | ---- | ----------------- | ---------
7 | bundled<br />gzip | 1.34 MB<br />386.44 KB | 0%"
Files count | Total bundle size | % Changed
----------- | ----------------- | ---------
7 | 1.34 MB<br />386.44 KB | 0%"
`;

exports[`Shows stats when files are unchanged 2`] = `
Expand All @@ -107,25 +107,25 @@ No assets were smaller
**Unchanged**
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 B<br />151 B | 0%"
Asset | File Size | % Changed
----- | --------- | ---------
app.bundle.js | 1.04 MB<br />297.38 KB | 0%
296.chunk.js | 124.57 KB<br />35.05 KB | 0%
288.chunk.js | 57.24 KB<br />16.33 KB | 0%
920.chunk.js | 54.98 KB<br />17.08 KB | 0%
912.chunk.js | 44.37 KB<br />14.31 KB | 0%
699.chunk.js | 26.39 KB<br />6.14 KB | 0%
manifest.json | 551 B<br />151 B | 0%"
`;

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

exports[`displays no module information when unchanged 1`] = `
"
**Changeset**
Changeset
No files were changed"
`;
Expand Down
51 changes: 29 additions & 22 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,55 @@
import {expect, test} from '@jest/globals'
import {getStatsDiff} from '../src/get-stats-diff'
import {getChunkModuleDiff} from '../src/get-chunk-module-diff'
import {getCommentBody} from '../src/to-comment-body'
import {
printAssetTablesByGroup,
printChunkModulesTable,
printTotalAssetTable
} from '../src/print-markdown'
import {AssetDiff} from '../src/types'
import {readFile} from 'node:fs/promises'
import {resolve} from 'node:path'
import {StatsCompilation} from 'webpack'

test('Shows stats when files are removed', () => {
async function readJsonFile(path: string): Promise<StatsCompilation> {
const data = await readFile(resolve(__dirname, path), 'utf8')
return JSON.parse(data)
}

test('Shows stats when files are removed', async () => {
const statsDiff = getStatsDiff(
require('./__mocks__/old-stats-assets.json'),
require('./__mocks__/new-stats-assets.json')
await readJsonFile('./__mocks__/old-stats-assets.json'),
await readJsonFile('./__mocks__/new-stats-assets.json')
)

expect(printTotalAssetTable(statsDiff)).toMatchSnapshot()
expect(printAssetTablesByGroup(statsDiff)).toMatchSnapshot()
})

test('Shows stats when files are added', () => {
test('Shows stats when files are added', async () => {
const statsDiff = getStatsDiff(
require('./__mocks__/new-stats-assets.json'),
require('./__mocks__/old-stats-assets.json')
await readJsonFile('./__mocks__/new-stats-assets.json'),
await readJsonFile('./__mocks__/old-stats-assets.json')
)

expect(printTotalAssetTable(statsDiff)).toMatchSnapshot()
expect(printAssetTablesByGroup(statsDiff)).toMatchSnapshot()
})

test('Shows stats when files are unchanged', () => {
test('Shows stats when files are unchanged', async () => {
const statsDiff = getStatsDiff(
require('./__mocks__/old-stats-assets.json'),
require('./__mocks__/old-stats-assets.json')
await readJsonFile('./__mocks__/old-stats-assets.json'),
await readJsonFile('./__mocks__/old-stats-assets.json')
)

expect(printTotalAssetTable(statsDiff)).toMatchSnapshot()
expect(printAssetTablesByGroup(statsDiff)).toMatchSnapshot()
})

test('computes the correct module diff information', () => {
test('computes the correct module diff information', async () => {
const statsDiff = getChunkModuleDiff(
require('./__mocks__/old-stats-with-chunks.json'),
require('./__mocks__/new-stats-with-chunks.json')
await readJsonFile('./__mocks__/old-stats-with-chunks.json'),
await readJsonFile('./__mocks__/new-stats-with-chunks.json')
)

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

test('displays module information when files are added/removed/changed', () => {
test('displays module information when files are added/removed/changed', async () => {
const statsDiff = getChunkModuleDiff(
require('./__mocks__/old-stats-with-chunks.json'),
require('./__mocks__/new-stats-with-chunks.json')
await readJsonFile('./__mocks__/old-stats-with-chunks.json'),
await readJsonFile('./__mocks__/new-stats-with-chunks.json')
)

expect(printChunkModulesTable(statsDiff)).toMatchSnapshot()
})

test('displays no module information when unchanged', () => {
test('displays no module information when unchanged', async () => {
const statsDiff = getChunkModuleDiff(
require('./__mocks__/old-stats-with-chunks.json'),
require('./__mocks__/old-stats-with-chunks.json')
await readJsonFile('./__mocks__/old-stats-with-chunks.json'),
await readJsonFile('./__mocks__/old-stats-with-chunks.json')
)

expect(printChunkModulesTable(statsDiff)).toMatchSnapshot()
})

test('does not display module information when it does not exist', () => {
test('does not display module information when it does not exist', async () => {
const statsDiff = getChunkModuleDiff(
require('./__mocks__/old-stats-assets.json'),
require('./__mocks__/old-stats-assets.json')
await readJsonFile('./__mocks__/old-stats-assets.json'),
await readJsonFile('./__mocks__/old-stats-assets.json')
)

expect(printChunkModulesTable(statsDiff)).toMatchSnapshot()
Expand Down
Loading

0 comments on commit b761041

Please sign in to comment.