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
|
|
|
|
2020-12-09 23:19:31 +00:00
|
|
|
const LEGACY_JS_RESOURCES_KB_SIZE = 217
|
2019-08-26 23:05:29 +00:00
|
|
|
expect(legacyResourcesSize.uncompressed).toBeWithinSize(LEGACY_JS_RESOURCES_KB_SIZE)
|
|
|
|
|
2020-05-27 21:27:20 +00:00
|
|
|
const LEGACY_JS_RESOURCES_GZIP_KB_SIZE = 70
|
2019-08-26 23:05:29 +00:00
|
|
|
expect(legacyResourcesSize.gzip).toBeWithinSize(LEGACY_JS_RESOURCES_GZIP_KB_SIZE)
|
|
|
|
|
2020-12-09 23:19:31 +00:00
|
|
|
const LEGACY_JS_RESOURCES_BROTLI_KB_SIZE = 64
|
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
|
|
|
|
2020-12-09 23:19:31 +00:00
|
|
|
const MODERN_JS_RESOURCES_KB_SIZE = 180
|
2019-08-26 23:05:29 +00:00
|
|
|
expect(modernResourcesSize.uncompressed).toBeWithinSize(MODERN_JS_RESOURCES_KB_SIZE)
|
|
|
|
|
2020-05-27 21:27:20 +00:00
|
|
|
const MODERN_JS_RESOURCES_GZIP_KB_SIZE = 60
|
2019-08-26 23:05:29 +00:00
|
|
|
expect(modernResourcesSize.gzip).toBeWithinSize(MODERN_JS_RESOURCES_GZIP_KB_SIZE)
|
|
|
|
|
2020-05-27 21:27:20 +00:00
|
|
|
const MODERN_JS_RESOURCES_BROTLI_KB_SIZE = 55
|
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
|
|
|
})
|
|
|
|
})
|