test: add minimal pages fixture (#30457)

This commit is contained in:
Daniel Roe 2025-01-05 00:34:55 +00:00 committed by GitHub
parent 7f49b6d573
commit 660f172030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 131 additions and 0 deletions

View File

@ -1112,6 +1112,12 @@ importers:
specifier: workspace:*
version: link:../../../packages/nuxt
test/fixtures/minimal-pages:
dependencies:
nuxt:
specifier: workspace:*
version: link:../../../packages/nuxt
test/fixtures/minimal-types:
dependencies:
nuxt:

View File

@ -7,11 +7,13 @@ import { join } from 'pathe'
describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM_CI)('minimal nuxt application', () => {
const rootDir = fileURLToPath(new URL('./fixtures/minimal', import.meta.url))
const pagesRootDir = fileURLToPath(new URL('./fixtures/minimal-pages', import.meta.url))
beforeAll(async () => {
await Promise.all([
exec('pnpm', ['nuxi', 'build', rootDir], { nodeOptions: { env: { EXTERNAL_VUE: 'false' } } }),
exec('pnpm', ['nuxi', 'build', rootDir], { nodeOptions: { env: { EXTERNAL_VUE: 'true' } } }),
exec('pnpm', ['nuxi', 'build', pagesRootDir]),
])
}, 120 * 1000)
@ -33,6 +35,25 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
`)
})
it('default client bundle size (pages)', async () => {
const clientStats = await analyzeSizes(['**/*.js'], join(pagesRootDir, '.output/public'))
expect.soft(roundToKilobytes(clientStats!.totalBytes)).toMatchInlineSnapshot(`"175k"`)
const files = clientStats!.files.map(f => f.replace(/\..*\.js/, '.js'))
expect([...files]).toMatchInlineSnapshot(`
[
"_nuxt/a.js",
"_nuxt/client-component.js",
"_nuxt/default.js",
"_nuxt/entry.js",
"_nuxt/index.js",
"_nuxt/server-component.js",
]
`)
})
it('default server bundle size', async () => {
const serverDir = join(rootDir, '.output/server')
@ -99,6 +120,47 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
]
`)
})
it('default server bundle size (pages)', async () => {
const serverDir = join(pagesRootDir, '.output/server')
const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"303k"`)
const modules = await analyzeSizes(['node_modules/**/*'], serverDir)
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"1396k"`)
const packages = modules.files
.filter(m => m.endsWith('package.json'))
.map(m => m.replace('/package.json', '').replace('node_modules/', ''))
.sort()
expect(packages).toMatchInlineSnapshot(`
[
"@babel/parser",
"@unhead/dom",
"@unhead/shared",
"@unhead/ssr",
"@vue/compiler-core",
"@vue/compiler-dom",
"@vue/compiler-ssr",
"@vue/reactivity",
"@vue/runtime-core",
"@vue/runtime-dom",
"@vue/server-renderer",
"@vue/shared",
"db0",
"devalue",
"entities",
"estree-walker",
"hookable",
"source-map-js",
"ufo",
"unhead",
"vue",
"vue-bundle-renderer",
]
`)
})
})
async function analyzeSizes (pattern: string[], rootDir: string) {

3
test/fixtures/minimal-pages/app.vue vendored Normal file
View File

@ -0,0 +1,3 @@
<template>
<NuxtLayout><NuxtPage /></NuxtLayout>
</template>

3
test/fixtures/minimal-pages/error.vue vendored Normal file
View File

@ -0,0 +1,3 @@
<template>
<div>Error page</div>
</template>

View File

@ -0,0 +1,3 @@
<template>
<slot />
</template>

View File

@ -0,0 +1 @@
export default defineNuxtRouteMiddleware(() => {})

View File

@ -0,0 +1,27 @@
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
const nuxtEntry = fileURLToPath(new URL('../../../packages/nuxt/dist/index.mjs', import.meta.url))
const isStubbed = readFileSync(nuxtEntry, 'utf-8').includes('const _module = await jiti')
export default defineNuxtConfig({
$production: {
vite: {
$client: {
build: {
rollupOptions: {
output: {
chunkFileNames: '_nuxt/[name].js',
entryFileNames: '_nuxt/[name].js',
},
},
},
},
},
},
sourcemap: false,
compatibilityDate: '2024-06-28',
typescript: {
typeCheck: isStubbed ? false : 'build',
},
})

View File

@ -0,0 +1,13 @@
{
"private": true,
"name": "fixture-minimal-pages",
"scripts": {
"build": "nuxi build"
},
"dependencies": {
"nuxt": "workspace:*"
},
"engines": {
"node": "^18.20.5 || ^20.9.0 || >=22.0.0"
}
}

View File

@ -0,0 +1,3 @@
<template>
<div>Client-only page</div>
</template>

View File

@ -0,0 +1,3 @@
<template>
<div>Server-only page</div>
</template>

View File

@ -0,0 +1,3 @@
<template>
<div>Hello World!</div>
</template>

View File

@ -0,0 +1 @@
export default defineNuxtPlugin(() => {})

View File

@ -0,0 +1,3 @@
{
"extends": "./.nuxt/tsconfig.json"
}