mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-19 16:01:24 +00:00
test: add benchmark for vite client build (#31118)
This commit is contained in:
parent
25cd5bfff2
commit
bbae4d74a4
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -235,6 +235,9 @@ jobs:
|
||||
name: dist
|
||||
path: packages
|
||||
|
||||
- name: Prepare test fixtures
|
||||
run: pnpm test:prepare
|
||||
|
||||
- name: Run benchmarks
|
||||
uses: CodSpeedHQ/action@63ae6025a0ffee97d7736a37c9192dbd6ed4e75f # v3.4.0
|
||||
with:
|
||||
|
40
packages/nuxt/test/build-plugins.bench.ts
Normal file
40
packages/nuxt/test/build-plugins.bench.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { rm } from 'node:fs/promises'
|
||||
import { afterAll, beforeAll, bench, describe } from 'vitest'
|
||||
import { join, normalize } from 'pathe'
|
||||
import { withoutTrailingSlash } from 'ufo'
|
||||
import { build, loadNuxt } from 'nuxt'
|
||||
import type { Nuxt } from '@nuxt/schema'
|
||||
|
||||
const basicTestFixtureDir = withoutTrailingSlash(normalize(fileURLToPath(new URL('../../../test/fixtures/basic', import.meta.url))))
|
||||
|
||||
describe('build', () => {
|
||||
let nuxt: Nuxt
|
||||
beforeAll(async () => {
|
||||
await rm(join(basicTestFixtureDir, 'node_modules/build-plugins/.nuxt'), { recursive: true, force: true })
|
||||
nuxt = await loadNuxt({
|
||||
cwd: basicTestFixtureDir,
|
||||
ready: true,
|
||||
overrides: {
|
||||
buildDir: join(basicTestFixtureDir, 'node_modules/build-plugins/.nuxt'),
|
||||
ssr: false,
|
||||
sourcemap: false,
|
||||
hooks: {
|
||||
'build:done': () => {
|
||||
throw new Error('bypass nitro build')
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(() => nuxt?.close())
|
||||
|
||||
bench('initial production build in the basic test fixture', async () => {
|
||||
await build(nuxt).catch((e) => {
|
||||
if (!e?.toString().includes('bypass nitro build')) {
|
||||
throw e
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
@ -9,7 +9,7 @@ const basicTestFixtureDir = withoutTrailingSlash(normalize(fileURLToPath(new URL
|
||||
|
||||
describe('build', () => {
|
||||
beforeAll(async () => {
|
||||
await rm(join(basicTestFixtureDir, '.nuxt'), { recursive: true, force: true })
|
||||
await rm(join(basicTestFixtureDir, 'node_modules/build/.nuxt'), { recursive: true, force: true })
|
||||
})
|
||||
|
||||
bench('initial dev server build in the basic test fixture', async () => {
|
||||
@ -18,6 +18,7 @@ describe('build', () => {
|
||||
ready: true,
|
||||
overrides: {
|
||||
dev: true,
|
||||
buildDir: join(basicTestFixtureDir, 'node_modules/build/.nuxt'),
|
||||
sourcemap: false,
|
||||
builder: {
|
||||
bundle: () => Promise.resolve(),
|
||||
|
@ -11,8 +11,8 @@ const basicTestFixtureDir = withoutTrailingSlash(normalize(fileURLToPath(new URL
|
||||
describe('loadNuxt', () => {
|
||||
beforeAll(async () => {
|
||||
await Promise.all([
|
||||
rm(join(emptyDir, '.nuxt'), { recursive: true, force: true }),
|
||||
rm(join(basicTestFixtureDir, '.nuxt'), { recursive: true, force: true }),
|
||||
rm(join(emptyDir, 'node_modules/load-nuxt/.nuxt'), { recursive: true, force: true }),
|
||||
rm(join(basicTestFixtureDir, 'node_modules/load-nuxt/.nuxt'), { recursive: true, force: true }),
|
||||
])
|
||||
})
|
||||
|
||||
@ -20,6 +20,9 @@ describe('loadNuxt', () => {
|
||||
const nuxt = await loadNuxt({
|
||||
cwd: emptyDir,
|
||||
ready: true,
|
||||
overrides: {
|
||||
buildDir: join(emptyDir, 'node_modules/load-nuxt/.nuxt'),
|
||||
},
|
||||
})
|
||||
await nuxt.close()
|
||||
})
|
||||
@ -28,6 +31,9 @@ describe('loadNuxt', () => {
|
||||
const nuxt = await loadNuxt({
|
||||
cwd: basicTestFixtureDir,
|
||||
ready: true,
|
||||
overrides: {
|
||||
buildDir: join(basicTestFixtureDir, 'node_modules/load-nuxt/.nuxt'),
|
||||
},
|
||||
})
|
||||
await nuxt.close()
|
||||
})
|
||||
|
15
packages/nuxt/test/nitro/render-index.ts
Normal file
15
packages/nuxt/test/nitro/render-index.ts
Normal file
@ -0,0 +1,15 @@
|
||||
// @ts-expect-error untyped
|
||||
import '#nitro-internal-pollyfills'
|
||||
import type { NitroApp } from 'nitro/types'
|
||||
// @ts-expect-error untyped
|
||||
import { useNitroApp } from 'nitropack/runtime'
|
||||
|
||||
const nitroApp = useNitroApp()
|
||||
|
||||
async function renderIndex () {
|
||||
const text = await (nitroApp as NitroApp).localFetch('/', {}).then(r => r.text())
|
||||
// eslint-disable-next-line
|
||||
console.log(text)
|
||||
}
|
||||
|
||||
renderIndex()
|
41
packages/nuxt/test/render.bench.ts
Normal file
41
packages/nuxt/test/render.bench.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { rm } from 'node:fs/promises'
|
||||
import { beforeAll, bench, describe, expect } from 'vitest'
|
||||
import { join, normalize } from 'pathe'
|
||||
import { withoutTrailingSlash } from 'ufo'
|
||||
import { build, loadNuxt } from 'nuxt'
|
||||
import { x } from 'tinyexec'
|
||||
|
||||
const basicTestFixtureDir = withoutTrailingSlash(normalize(fileURLToPath(new URL('../../../test/fixtures/basic', import.meta.url))))
|
||||
const outputDir = fileURLToPath(new URL('../../../node_modules/.test/render', import.meta.url))
|
||||
|
||||
describe.todo('render', () => {
|
||||
beforeAll(async () => {
|
||||
await rm(join(basicTestFixtureDir, 'node_modules/render/.nuxt'), { recursive: true, force: true })
|
||||
const nuxt = await loadNuxt({
|
||||
cwd: basicTestFixtureDir,
|
||||
ready: true,
|
||||
overrides: {
|
||||
buildDir: join(basicTestFixtureDir, 'node_modules/render/.nuxt'),
|
||||
nitro: {
|
||||
output: {
|
||||
dir: outputDir,
|
||||
},
|
||||
},
|
||||
sourcemap: false,
|
||||
},
|
||||
})
|
||||
nuxt.hook('nitro:build:before', (nitro) => {
|
||||
nitro.options.entry = fileURLToPath(new URL('./nitro/render-index', import.meta.url))
|
||||
})
|
||||
await build(nuxt)
|
||||
await nuxt.close()
|
||||
}, 200_000)
|
||||
|
||||
bench('index route in the basic test fixture', async () => {
|
||||
const res = await x('node', [join(outputDir, 'server/index.mjs')], {
|
||||
nodeOptions: { stdio: 'pipe' },
|
||||
})
|
||||
expect(res.stdout).toContain('Hello Nuxt 3!')
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user