Commit a90318cb authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: update test-size (#6118)

* fix: update test-size

* fix: update main size
parent 93cf4b35
...@@ -16,10 +16,10 @@ try { ...@@ -16,10 +16,10 @@ try {
} }
// The last recorded size for these assets, as reported by `yarn build`. // The last recorded size for these assets, as reported by `yarn build`.
const MAX_SIZE_MAIN_KB = 361.36 const LAST_SIZE_MAIN_KB = 374
// This is the async-loaded js, called <number>.<hash>.js, with a matching css file. // This is the async-loaded js, called <number>.<hash>.js, with a matching css file.
const MAX_SIZE_ENTRY_MB = 1.38 const LAST_SIZE_ENTRY_KB = 1417
const SIZE_TOLERANCE_KB = 5 const SIZE_TOLERANCE_KB = 5
...@@ -30,20 +30,22 @@ let fail = false ...@@ -30,20 +30,22 @@ let fail = false
console.log('File sizes after gzip:\n') console.log('File sizes after gzip:\n')
jsEntrypoints.forEach((entrypoint) => { jsEntrypoints.forEach((entrypoint) => {
const name = entrypoint.match(/\/([\w\d-]*)\./)[1] const name = entrypoint.match(/\/([\w\d-]*)\./)[1]
const size = gzipSize(fs.readFileSync(path.join(buildDir, entrypoint))) const size = gzipSize(fs.readFileSync(path.join(buildDir, entrypoint))) / 1024
let maxSize = MAX_SIZE_ENTRY_MB * 1024 * 1024 let maxSize = LAST_SIZE_ENTRY_KB + SIZE_TOLERANCE_KB
if (name === 'runtime-main') { if (name === 'runtime-main') {
return return
} else if (name === 'main') { } else if (name === 'main') {
maxSize = MAX_SIZE_MAIN_KB * 1024 maxSize = LAST_SIZE_MAIN_KB + SIZE_TOLERANCE_KB
} }
maxSize += SIZE_TOLERANCE_KB * 1024
const report = `\t${size.toFixed(2).padEnd(8)}kB\t${chalk.dim(
`max: ${maxSize.toFixed().padEnd(4)} kB`
)}\t${entrypoint}`
if (maxSize > size) { if (maxSize > size) {
console.log(chalk.green(`\t${toKb(maxSize)}\t${entrypoint}`)) console.log(chalk.green(report))
} else { } else {
console.log(chalk.red(`\t${toKb(maxSize)}\t${entrypoint}`), '\tdid you import an unnecessary dependency?') console.log(chalk.red(report), '\tdid you import an unnecessary dependency?')
fail = true fail = true
} }
}) })
...@@ -52,7 +54,3 @@ if (fail) { ...@@ -52,7 +54,3 @@ if (fail) {
console.log(chalk.yellow('Reduce the file size or update the size limit (in scripts/test-size.js)')) console.log(chalk.yellow('Reduce the file size or update the size limit (in scripts/test-size.js)'))
process.exit(1) process.exit(1)
} }
function toKb(bytes) {
return ((bytes / 1024).toFixed(2) + ' kB').padEnd(8)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment