Skip to content

Commit

Permalink
test: mask zlib size
Browse files Browse the repository at this point in the history
  • Loading branch information
ambar committed Feb 8, 2024
1 parent 86fc1d6 commit 1538759
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 22 deletions.
40 changes: 20 additions & 20 deletions measure-bundle-size/test/__snapshots__/measure.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports[`measure "
"result": {
"human": {
"size": "22B",
"zippedSize": "42B",
"zippedSize": "4*B",
},
"modulePkg": undefined,
"modulePkgFile": undefined,
Expand All @@ -55,7 +55,7 @@ exports[`measure "
"pkgFile": "node_modules/react-inline-center/package.json",
"size": 22,
"stats": undefined,
"zippedSize": 42,
"zippedSize": "4*",
},
},
]
Expand All @@ -76,7 +76,7 @@ exports[`measure "
"result": {
"human": {
"size": "2.13KB",
"zippedSize": "930B",
"zippedSize": "9**B",
},
"modulePkg": undefined,
"modulePkgFile": undefined,
Expand All @@ -91,7 +91,7 @@ exports[`measure "
"pkgFile": "node_modules/sanitize.css/package.json",
"size": 2185,
"stats": undefined,
"zippedSize": 930,
"zippedSize": "9**",
},
},
{
Expand All @@ -104,7 +104,7 @@ exports[`measure "
"result": {
"human": {
"size": "525B",
"zippedSize": "353B",
"zippedSize": "3**B",
},
"modulePkg": undefined,
"modulePkgFile": undefined,
Expand All @@ -119,7 +119,7 @@ exports[`measure "
"pkgFile": "node_modules/sanitize.css/package.json",
"size": 525,
"stats": undefined,
"zippedSize": 353,
"zippedSize": "3**",
},
},
]
Expand Down Expand Up @@ -158,7 +158,7 @@ exports[`measure "
"pkgFile": "node_modules/date-fns/package.json",
"size": 0,
"stats": undefined,
"zippedSize": 0,
"zippedSize": "0",
},
},
]
Expand Down Expand Up @@ -206,7 +206,7 @@ exports[`measure "
"pkgFile": "node_modules/date-fns/package.json",
"size": 0,
"stats": undefined,
"zippedSize": 0,
"zippedSize": "0",
},
},
]
Expand Down Expand Up @@ -237,7 +237,7 @@ exports[`measure "
"result": {
"human": {
"size": "869B",
"zippedSize": "506B",
"zippedSize": "5**B",
},
"modulePkg": undefined,
"modulePkgFile": undefined,
Expand All @@ -252,7 +252,7 @@ exports[`measure "
"pkgFile": "node_modules/date-fns/package.json",
"size": 869,
"stats": undefined,
"zippedSize": 506,
"zippedSize": "5**",
},
},
]
Expand Down Expand Up @@ -295,7 +295,7 @@ exports[`measure "
"result": {
"human": {
"size": "2.43KB",
"zippedSize": "1.13KB",
"zippedSize": "1**KB",
},
"modulePkg": undefined,
"modulePkgFile": undefined,
Expand All @@ -310,7 +310,7 @@ exports[`measure "
"pkgFile": "node_modules/date-fns/package.json",
"size": 2489,
"stats": undefined,
"zippedSize": 1162,
"zippedSize": "1***",
},
},
]
Expand All @@ -333,7 +333,7 @@ exports[`measure "
"result": {
"human": {
"size": "71.78KB",
"zippedSize": "26.02KB",
"zippedSize": "2***KB",
},
"modulePkg": undefined,
"modulePkgFile": undefined,
Expand All @@ -348,7 +348,7 @@ exports[`measure "
"pkgFile": "node_modules/lodash/package.json",
"size": 73500,
"stats": undefined,
"zippedSize": 26641,
"zippedSize": "2****",
},
},
]
Expand All @@ -371,7 +371,7 @@ exports[`measure "
"result": {
"human": {
"size": "7.79KB",
"zippedSize": "3.26KB",
"zippedSize": "3**KB",
},
"modulePkg": undefined,
"modulePkgFile": undefined,
Expand All @@ -389,7 +389,7 @@ exports[`measure "
"pkgFile": "node_modules/react/package.json",
"size": 7974,
"stats": undefined,
"zippedSize": 3335,
"zippedSize": "3***",
},
},
]
Expand All @@ -412,7 +412,7 @@ exports[`measure "
"result": {
"human": {
"size": "637B",
"zippedSize": "372B",
"zippedSize": "3**B",
},
"modulePkg": undefined,
"modulePkgFile": undefined,
Expand All @@ -427,7 +427,7 @@ exports[`measure "
"pkgFile": "node_modules/@ambarli/alias/package.json",
"size": 637,
"stats": undefined,
"zippedSize": 372,
"zippedSize": "3**",
},
},
]
Expand All @@ -450,7 +450,7 @@ exports[`measure "
"result": {
"human": {
"size": "21.1KB",
"zippedSize": "8.29KB",
"zippedSize": "8**KB",
},
"modulePkg": undefined,
"modulePkgFile": undefined,
Expand All @@ -465,7 +465,7 @@ exports[`measure "
"pkgFile": "node_modules/lodash/package.json",
"size": 21611,
"stats": undefined,
"zippedSize": 8489,
"zippedSize": "8***",
},
},
]
Expand Down
35 changes: 33 additions & 2 deletions measure-bundle-size/test/measure.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import path from 'path'
import dedent from 'dedent'
import {measure} from '../src/measure'
import {measure, MeasureResult} from '../src/measure'

// zlib different on mac/linux: https://github.com/nodejs/node/issues/12244
const snapshot = (values: MeasureResult[]) => {
const maskSize = (value: number | string) => {
if (typeof value === 'number') {
return `${String(value)[0]}`.padEnd(String(value).length, '*')
}
const [size, unit] = value.split(/(B|KB|MB)/g)
return size[0].padEnd(size.length - unit.length + 1, '*') + unit
}

expect(
values.map((r) => {
const result = r?.result
if (result) {
return {
...r,
result: {
...result,
zippedSize: maskSize(result.zippedSize),
human: {
...result.human,
zippedSize: maskSize(result.human.zippedSize),
},
},
}
}
return r
})
).toMatchSnapshot()
}

const inputs = [
// skip node core
Expand Down Expand Up @@ -69,7 +100,7 @@ const inputs = [
]

test.each(inputs)('measure %p', async (input) => {
expect(await measure(dedent(input), __filename)).toMatchSnapshot()
snapshot(await measure(dedent(input), __filename))
})

test('throw', async () => {
Expand Down

0 comments on commit 1538759

Please sign in to comment.