Unverified Commit 5dfc20dc authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update size-limit test to be more fine grained (#10434)

* Update size-limit test to be more fine grained

* Decrease default build expected size

* Update failing diff amount to be 1kb
parent 238202ec
...@@ -5,7 +5,7 @@ import { join } from 'path' ...@@ -5,7 +5,7 @@ import { join } from 'path'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import fetch from 'node-fetch' import fetch from 'node-fetch'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
let server let server
let scriptsUrls let scriptsUrls
...@@ -23,12 +23,11 @@ function getResponseSizes(resourceUrls) { ...@@ -23,12 +23,11 @@ function getResponseSizes(resourceUrls) {
) )
} }
function getResponseSizesKB(responseSizes) { function getResponseSizesBytes(responseSizes) {
const responseSizeBytes = responseSizes.reduce( return responseSizes.reduce(
(accumulator, responseSizeObj) => accumulator + responseSizeObj.bytes, (accumulator, responseSizeObj) => accumulator + responseSizeObj.bytes,
0 0
) )
return Math.ceil(responseSizeBytes / 1024)
} }
describe('Production response size', () => { describe('Production response size', () => {
...@@ -73,17 +72,17 @@ describe('Production response size', () => { ...@@ -73,17 +72,17 @@ describe('Production response size', () => {
scriptsUrls.filter(path => !path.endsWith('.module.js')) scriptsUrls.filter(path => !path.endsWith('.module.js'))
)), )),
] ]
const responseSizeKilobytes = getResponseSizesKB(responseSizes) const responseSizesBytes = getResponseSizesBytes(responseSizes)
console.log( console.log(
`Response Sizes for default:\n${responseSizes `Response Sizes for default:\n${responseSizes
.map(obj => ` ${obj.url}: ${obj.bytes} (bytes)`) .map(obj => ` ${obj.url}: ${obj.bytes} (bytes)`)
.join('\n')} \nOverall: ${responseSizeKilobytes} KB` .join('\n')} \nOverall: ${responseSizesBytes} KB`
) )
// These numbers are without gzip compression! // These numbers are without gzip compression!
const delta = responseSizeKilobytes - 227 const delta = responseSizesBytes - 226 * 1024
expect(delta).toBeLessThanOrEqual(0) // don't increase size expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
expect(delta).toBeGreaterThanOrEqual(-1) // don't decrease size without updating target expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target
}) })
it('should not increase the overall response size of modern build', async () => { it('should not increase the overall response size of modern build', async () => {
...@@ -93,16 +92,16 @@ describe('Production response size', () => { ...@@ -93,16 +92,16 @@ describe('Production response size', () => {
scriptsUrls.filter(path => path.endsWith('.module.js')) scriptsUrls.filter(path => path.endsWith('.module.js'))
)), )),
] ]
const responseSizeKilobytes = getResponseSizesKB(responseSizes) const responseSizesBytes = getResponseSizesBytes(responseSizes)
console.log( console.log(
`Response Sizes for modern:\n${responseSizes `Response Sizes for modern:\n${responseSizes
.map(obj => ` ${obj.url}: ${obj.bytes} (bytes)`) .map(obj => ` ${obj.url}: ${obj.bytes} (bytes)`)
.join('\n')} \nOverall: ${responseSizeKilobytes} KB` .join('\n')} \nOverall: ${responseSizesBytes} bytes`
) )
// These numbers are without gzip compression! // These numbers are without gzip compression!
const delta = responseSizeKilobytes - 195 const delta = responseSizesBytes - 195 * 1024
expect(delta).toBeLessThanOrEqual(0) // don't increase size expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
expect(delta).toBeGreaterThanOrEqual(-1) // don't decrease size without updating target expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target
}) })
}) })
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