Unverified Commit b046a059 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Disable build-output size specific tests (#26769)

* Disable build-output size specific tests

* remove size-limit test

* lint-fix
parent ddc0e793
......@@ -115,44 +115,44 @@ describe('Build Output', () => {
expect(parseFloat(size)).toBeGreaterThan(0)
}
const gz = gzipSize !== false
// const gz = gzipSize !== false
expect(parseFloat(indexSize) / 1000).toBeCloseTo(
gz ? 0.251 : 0.394,
2
)
// expect(parseFloat(indexSize) / 1000).toBeCloseTo(
// gz ? 0.251 : 0.394,
// 2
// )
expect(indexSize.endsWith('B')).toBe(true)
expect(parseFloat(indexFirstLoad)).toBeCloseTo(gz ? 64 : 196, 1)
// expect(parseFloat(indexFirstLoad)).toBeCloseTo(gz ? 64 : 196, 1)
expect(indexFirstLoad.endsWith('kB')).toBe(true)
expect(parseFloat(err404Size)).toBeCloseTo(gz ? 3.17 : 8.51, 1)
// expect(parseFloat(err404Size)).toBeCloseTo(gz ? 3.17 : 8.51, 1)
expect(err404Size.endsWith('kB')).toBe(true)
expect(parseFloat(err404FirstLoad)).toBeCloseTo(gz ? 66.9 : 204, 1)
// expect(parseFloat(err404FirstLoad)).toBeCloseTo(gz ? 66.9 : 204, 1)
expect(err404FirstLoad.endsWith('kB')).toBe(true)
expect(parseFloat(sharedByAll)).toBeCloseTo(gz ? 63.7 : 196, 1)
// expect(parseFloat(sharedByAll)).toBeCloseTo(gz ? 63.7 : 196, 1)
expect(sharedByAll.endsWith('kB')).toBe(true)
const appSizeValue = _appSize.endsWith('kB')
? parseFloat(_appSize)
: parseFloat(_appSize) / 1000
expect(appSizeValue).toBeCloseTo(gz ? 0.799 : 1.63, 1)
// const appSizeValue = _appSize.endsWith('kB')
// ? parseFloat(_appSize)
// : parseFloat(_appSize) / 1000
// expect(appSizeValue).toBeCloseTo(gz ? 0.799 : 1.63, 1)
expect(_appSize.endsWith('kB') || _appSize.endsWith(' B')).toBe(true)
const webpackSizeValue = webpackSize.endsWith('kB')
? parseFloat(webpackSize)
: parseFloat(webpackSize) / 1000
expect(webpackSizeValue).toBeCloseTo(gz ? 0.766 : 1.46, 2)
// const webpackSizeValue = webpackSize.endsWith('kB')
// ? parseFloat(webpackSize)
// : parseFloat(webpackSize) / 1000
// expect(webpackSizeValue).toBeCloseTo(gz ? 0.766 : 1.46, 2)
expect(webpackSize.endsWith('kB') || webpackSize.endsWith(' B')).toBe(
true
)
expect(parseFloat(mainSize)).toBeCloseTo(gz ? 20.1 : 62.7, 1)
// expect(parseFloat(mainSize)).toBeCloseTo(gz ? 20.1 : 62.7, 1)
expect(mainSize.endsWith('kB')).toBe(true)
expect(parseFloat(frameworkSize)).toBeCloseTo(gz ? 42.0 : 130, 1)
// expect(parseFloat(frameworkSize)).toBeCloseTo(gz ? 42.0 : 130, 1)
expect(frameworkSize.endsWith('kB')).toBe(true)
})
......
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
module.exports = {
webpack(config, { isServer }) {
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: `dist/${isServer ? 'server' : 'client'}.html`,
openAnalyzer: false,
})
)
return config
},
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
}
export default () => <div>About</div>
import Link from 'next/link'
export default () => (
<div>
Size-Limit Page
<br />
<Link href="/about">
<a>about</a>
</Link>
</div>
)
/* eslint-env jest */
import { nextBuild, nextServer, startApp, stopApp } from 'next-test-utils'
import { join } from 'path'
import cheerio from 'cheerio'
import fetch from 'node-fetch'
jest.setTimeout(1000 * 60 * 2)
let server
let scriptsUrls
let baseResponseSize
function getResponseSizes(resourceUrls) {
return Promise.all(
resourceUrls.map(async (url) => {
const context = await fetch(url).then((res) => res.text())
return {
url,
bytes: context.length,
}
})
)
}
function getResponseSizesBytes(responseSizes) {
return responseSizes.reduce(
(accumulator, responseSizeObj) => accumulator + responseSizeObj.bytes,
0
)
}
describe('Production response size', () => {
beforeAll(async () => {
const dir = join(__dirname, '../')
// Build next app
await nextBuild(dir)
// Start next app
server = await startApp(
nextServer({
dir,
dev: false,
quiet: true,
})
)
// Get the html document
let baseUrl = `http://localhost:${server.address().port}`
const htmlResponse = await fetch(baseUrl)
// Find all script urls
const html = await htmlResponse.text()
baseResponseSize = { url: baseUrl, bytes: html.length }
const $ = cheerio.load(html)
scriptsUrls = $('script[src]')
.map((i, el) => $(el).attr('src'))
.get()
.map((path) => `${baseUrl}${path}`)
})
afterAll(async () => {
// Clean up
await stopApp(server)
})
it('should not increase the overall response size of default build', async () => {
if (process.env.NEXT_PRIVATE_SKIP_SIZE_TESTS) {
return
}
const responseSizes = [
baseResponseSize,
...(await getResponseSizes(scriptsUrls)),
]
const responseSizesBytes = getResponseSizesBytes(responseSizes)
console.log(
`Response Sizes for default:\n${responseSizes
.map((obj) => ` ${obj.url}: ${obj.bytes} (bytes)`)
.join('\n')} \nOverall: ${responseSizesBytes} KB`
)
// These numbers are without gzip compression!
const delta = responseSizesBytes / 1024
// Expected difference: < 0.5
expect(delta).toBeCloseTo(286.8, 0)
})
})
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