mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
test: add minimal pages fixture (#30457)
This commit is contained in:
parent
7f49b6d573
commit
660f172030
@ -1112,6 +1112,12 @@ importers:
|
|||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../../packages/nuxt
|
version: link:../../../packages/nuxt
|
||||||
|
|
||||||
|
test/fixtures/minimal-pages:
|
||||||
|
dependencies:
|
||||||
|
nuxt:
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../../packages/nuxt
|
||||||
|
|
||||||
test/fixtures/minimal-types:
|
test/fixtures/minimal-types:
|
||||||
dependencies:
|
dependencies:
|
||||||
nuxt:
|
nuxt:
|
||||||
|
@ -7,11 +7,13 @@ import { join } from 'pathe'
|
|||||||
|
|
||||||
describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM_CI)('minimal nuxt application', () => {
|
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 rootDir = fileURLToPath(new URL('./fixtures/minimal', import.meta.url))
|
||||||
|
const pagesRootDir = fileURLToPath(new URL('./fixtures/minimal-pages', import.meta.url))
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
exec('pnpm', ['nuxi', 'build', rootDir], { nodeOptions: { env: { EXTERNAL_VUE: 'false' } } }),
|
exec('pnpm', ['nuxi', 'build', rootDir], { nodeOptions: { env: { EXTERNAL_VUE: 'false' } } }),
|
||||||
exec('pnpm', ['nuxi', 'build', rootDir], { nodeOptions: { env: { EXTERNAL_VUE: 'true' } } }),
|
exec('pnpm', ['nuxi', 'build', rootDir], { nodeOptions: { env: { EXTERNAL_VUE: 'true' } } }),
|
||||||
|
exec('pnpm', ['nuxi', 'build', pagesRootDir]),
|
||||||
])
|
])
|
||||||
}, 120 * 1000)
|
}, 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 () => {
|
it('default server bundle size', async () => {
|
||||||
const serverDir = join(rootDir, '.output/server')
|
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) {
|
async function analyzeSizes (pattern: string[], rootDir: string) {
|
||||||
|
3
test/fixtures/minimal-pages/app.vue
vendored
Normal file
3
test/fixtures/minimal-pages/app.vue
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<NuxtLayout><NuxtPage /></NuxtLayout>
|
||||||
|
</template>
|
3
test/fixtures/minimal-pages/error.vue
vendored
Normal file
3
test/fixtures/minimal-pages/error.vue
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<div>Error page</div>
|
||||||
|
</template>
|
3
test/fixtures/minimal-pages/layouts/default.vue
vendored
Normal file
3
test/fixtures/minimal-pages/layouts/default.vue
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<slot />
|
||||||
|
</template>
|
1
test/fixtures/minimal-pages/middleware/test.global.ts
vendored
Normal file
1
test/fixtures/minimal-pages/middleware/test.global.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export default defineNuxtRouteMiddleware(() => {})
|
27
test/fixtures/minimal-pages/nuxt.config.ts
vendored
Normal file
27
test/fixtures/minimal-pages/nuxt.config.ts
vendored
Normal 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',
|
||||||
|
},
|
||||||
|
})
|
13
test/fixtures/minimal-pages/package.json
vendored
Normal file
13
test/fixtures/minimal-pages/package.json
vendored
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
3
test/fixtures/minimal-pages/pages/a.client.vue
vendored
Normal file
3
test/fixtures/minimal-pages/pages/a.client.vue
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<div>Client-only page</div>
|
||||||
|
</template>
|
3
test/fixtures/minimal-pages/pages/b.server.vue
vendored
Normal file
3
test/fixtures/minimal-pages/pages/b.server.vue
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<div>Server-only page</div>
|
||||||
|
</template>
|
3
test/fixtures/minimal-pages/pages/index.vue
vendored
Normal file
3
test/fixtures/minimal-pages/pages/index.vue
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<div>Hello World!</div>
|
||||||
|
</template>
|
1
test/fixtures/minimal-pages/plugins/test.ts
vendored
Normal file
1
test/fixtures/minimal-pages/plugins/test.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export default defineNuxtPlugin(() => {})
|
3
test/fixtures/minimal-pages/tsconfig.json
vendored
Normal file
3
test/fixtures/minimal-pages/tsconfig.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "./.nuxt/tsconfig.json"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user