Skip to content

Commit

Permalink
Update size-limit test to be more fine grained (#10434)
Browse files Browse the repository at this point in the history
* Update size-limit test to be more fine grained

* Decrease default build expected size

* Update failing diff amount to be 1kb
  • Loading branch information
ijjk committed Feb 5, 2020
1 parent 238202e commit 5dfc20d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions test/integration/size-limit/test/index.test.js
Expand Up @@ -5,7 +5,7 @@ import { join } from 'path'
import cheerio from 'cheerio'
import fetch from 'node-fetch'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2

let server
let scriptsUrls
Expand All @@ -23,12 +23,11 @@ function getResponseSizes(resourceUrls) {
)
}

function getResponseSizesKB(responseSizes) {
const responseSizeBytes = responseSizes.reduce(
function getResponseSizesBytes(responseSizes) {
return responseSizes.reduce(
(accumulator, responseSizeObj) => accumulator + responseSizeObj.bytes,
0
)
return Math.ceil(responseSizeBytes / 1024)
}

describe('Production response size', () => {
Expand Down Expand Up @@ -73,17 +72,17 @@ describe('Production response size', () => {
scriptsUrls.filter(path => !path.endsWith('.module.js'))
)),
]
const responseSizeKilobytes = getResponseSizesKB(responseSizes)
const responseSizesBytes = getResponseSizesBytes(responseSizes)
console.log(
`Response Sizes for default:\n${responseSizes
.map(obj => ` ${obj.url}: ${obj.bytes} (bytes)`)
.join('\n')} \nOverall: ${responseSizeKilobytes} KB`
.join('\n')} \nOverall: ${responseSizesBytes} KB`
)

// These numbers are without gzip compression!
const delta = responseSizeKilobytes - 227
expect(delta).toBeLessThanOrEqual(0) // don't increase size
expect(delta).toBeGreaterThanOrEqual(-1) // don't decrease size without updating target
const delta = responseSizesBytes - 226 * 1024
expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
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 () => {
Expand All @@ -93,16 +92,16 @@ describe('Production response size', () => {
scriptsUrls.filter(path => path.endsWith('.module.js'))
)),
]
const responseSizeKilobytes = getResponseSizesKB(responseSizes)
const responseSizesBytes = getResponseSizesBytes(responseSizes)
console.log(
`Response Sizes for modern:\n${responseSizes
.map(obj => ` ${obj.url}: ${obj.bytes} (bytes)`)
.join('\n')} \nOverall: ${responseSizeKilobytes} KB`
.join('\n')} \nOverall: ${responseSizesBytes} bytes`
)

// These numbers are without gzip compression!
const delta = responseSizeKilobytes - 195
expect(delta).toBeLessThanOrEqual(0) // don't increase size
expect(delta).toBeGreaterThanOrEqual(-1) // don't decrease size without updating target
const delta = responseSizesBytes - 195 * 1024
expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target
})
})

0 comments on commit 5dfc20d

Please sign in to comment.