Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Feb 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
})
})