mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-15 02:14:44 +00:00
f319033928
* feat(nuxt-link): Improve <n-link> and add automatic prefetch * Update packages/vue-app/template/components/nuxt-link.js Co-Authored-By: Atinux <seb@orion.sh> * add missing space * feat(nuxt-link): Split in two components for smaller bundle * fix(vue-app): Use requestIdleCallback * chore(vue-app): Improve nuxt prefetch strategy for nuxt links * chore(vue-app): Add .isOnline and handle it for prefetch * chore(vue-app): Add .isOffline and use it * chore(vue-app): Add .isOffline * chore(server): Check is options.modern is given in dev mode * chore(vue-app): Add intersection-observer polyfill if router.prefetchLinks is 'polyfill' * chore(vue-app): Remove polyfill * chore(vue-app): Use only process.client * chore(vue-app): Add TS typings for .isOnline and isOffline * chore(vue-app): Update typings by @kevinmarrec * chore(vue-app): Reorder names * examples(nuxt-prefetch): Add Nuxt prefetching example * chore(vue-app): Add router.linkPrefetchedClass * lint(vue-app): Fix lint * chore(vue-app): Use intersectionRatio, recommend by @maoberlehner * fix(lint): Fix linting issues * lint(vue-app): Fix again (lol) * types(vue-app): Update TS typings * chore(vue-app): Update Vetur tags description * fix(vue-app): Use prefetchClass * chore(vue-app): Disable linkPrefetchedClass by default
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import cheerio from 'cheerio'
|
|
import fetch from 'node-fetch'
|
|
import { getPort, loadFixture, Nuxt } from '../utils'
|
|
|
|
let port
|
|
let nuxt = null
|
|
const url = route => 'http://localhost:' + port + route
|
|
let responseSizes
|
|
|
|
describe('size-limit test', () => {
|
|
beforeAll(async () => {
|
|
const options = await loadFixture('async-config')
|
|
nuxt = new Nuxt(options)
|
|
port = await getPort()
|
|
await nuxt.server.listen(port, '0.0.0.0')
|
|
|
|
const { html } = await nuxt.server.renderRoute('/')
|
|
// Get all script URLs from the HTML
|
|
const $ = cheerio.load(html)
|
|
const scriptsUrls = $('script[src]')
|
|
.map((_, el) => $(el).attr('src'))
|
|
.get()
|
|
.map(url)
|
|
const resourceUrls = [url('/'), ...scriptsUrls]
|
|
|
|
// Fetch all resources and get their size (bytes)
|
|
responseSizes = await Promise.all(resourceUrls.map(async (url) => {
|
|
const response = await fetch(url).then(res => res.text())
|
|
return response.length
|
|
}))
|
|
})
|
|
|
|
it('should stay within the size boundaries', () => {
|
|
const responseSizeBytes = responseSizes.reduce((bytes, responseLength) => bytes + responseLength, 0)
|
|
const responseSizeKilobytes = Math.ceil(responseSizeBytes / 1024)
|
|
// Without gzip!
|
|
expect(responseSizeKilobytes).toBeLessThanOrEqual(180)
|
|
})
|
|
})
|