2019-08-26 23:05:29 +00:00
|
|
|
import { resolve } from 'path'
|
2019-09-05 15:15:27 +00:00
|
|
|
import { getResourcesSize } from '../utils'
|
2019-08-26 23:05:29 +00:00
|
|
|
|
|
|
|
const distDir = resolve(__dirname, '../fixtures/async-config/.nuxt/dist')
|
|
|
|
|
|
|
|
describe('nuxt basic resources size limit', () => {
|
|
|
|
expect.extend({
|
|
|
|
toBeWithinSize (received, size) {
|
|
|
|
const maxSize = size * 1.05
|
|
|
|
const minSize = size * 0.95
|
|
|
|
const pass = received >= minSize && received <= maxSize
|
|
|
|
return {
|
|
|
|
pass,
|
|
|
|
message: () =>
|
|
|
|
`expected ${received} to be within range ${minSize} - ${maxSize}`
|
|
|
|
}
|
|
|
|
}
|
2018-11-07 22:34:14 +00:00
|
|
|
})
|
|
|
|
|
2019-08-26 23:05:29 +00:00
|
|
|
it('should stay within the size limit range in legacy mode', async () => {
|
2019-09-05 15:15:27 +00:00
|
|
|
const legacyResourcesSize = await getResourcesSize(distDir, 'client', { gzip: true, brotli: true })
|
2019-08-26 23:05:29 +00:00
|
|
|
|
2022-07-01 10:42:24 +00:00
|
|
|
const LEGACY_JS_RESOURCES_KB_SIZE = 253
|
2019-08-26 23:05:29 +00:00
|
|
|
expect(legacyResourcesSize.uncompressed).toBeWithinSize(LEGACY_JS_RESOURCES_KB_SIZE)
|
|
|
|
|
2022-09-03 13:17:44 +00:00
|
|
|
const LEGACY_JS_RESOURCES_GZIP_KB_SIZE = 88
|
2019-08-26 23:05:29 +00:00
|
|
|
expect(legacyResourcesSize.gzip).toBeWithinSize(LEGACY_JS_RESOURCES_GZIP_KB_SIZE)
|
|
|
|
|
2024-06-14 12:08:41 +00:00
|
|
|
const LEGACY_JS_RESOURCES_BROTLI_KB_SIZE = 76
|
2019-08-26 23:05:29 +00:00
|
|
|
expect(legacyResourcesSize.brotli).toBeWithinSize(LEGACY_JS_RESOURCES_BROTLI_KB_SIZE)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should stay within the size limit range in modern mode', async () => {
|
2019-09-05 15:15:27 +00:00
|
|
|
const modernResourcesSize = await getResourcesSize(distDir, 'modern', { gzip: true, brotli: true })
|
2019-08-26 23:05:29 +00:00
|
|
|
|
2024-06-14 12:08:41 +00:00
|
|
|
const MODERN_JS_RESOURCES_KB_SIZE = 225
|
2019-08-26 23:05:29 +00:00
|
|
|
expect(modernResourcesSize.uncompressed).toBeWithinSize(MODERN_JS_RESOURCES_KB_SIZE)
|
|
|
|
|
2022-09-03 13:17:44 +00:00
|
|
|
const MODERN_JS_RESOURCES_GZIP_KB_SIZE = 77
|
2019-08-26 23:05:29 +00:00
|
|
|
expect(modernResourcesSize.gzip).toBeWithinSize(MODERN_JS_RESOURCES_GZIP_KB_SIZE)
|
|
|
|
|
2022-09-03 13:17:44 +00:00
|
|
|
const MODERN_JS_RESOURCES_BROTLI_KB_SIZE = 68
|
2019-08-26 23:05:29 +00:00
|
|
|
expect(modernResourcesSize.brotli).toBeWithinSize(MODERN_JS_RESOURCES_BROTLI_KB_SIZE)
|
2018-11-07 22:34:14 +00:00
|
|
|
})
|
|
|
|
})
|