test: add benchmarks for dev server initial build (#30742)

This commit is contained in:
Daniel Roe 2025-02-04 16:03:27 +00:00 committed by GitHub
parent 82c2e86d38
commit 4e0ef29d1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 56 additions and 7 deletions

View File

@ -1,17 +1,25 @@
import { fileURLToPath } from 'node:url'
import { afterAll, bench, describe } from 'vitest'
import { join, normalize } from 'pathe'
import { rm } from 'node:fs/promises'
import { afterAll, beforeAll, bench, describe } from 'vitest'
import { join, normalize, resolve } from 'pathe'
import { withoutTrailingSlash } from 'ufo'
import { loadNuxt, writeTypes } from '@nuxt/kit'
import type { Nuxt } from 'nuxt/schema'
describe('writeTypes', async () => {
describe('writeTypes', () => {
const relativeDir = join('../../..', 'test/fixtures/basic-types')
const path = withoutTrailingSlash(normalize(fileURLToPath(new URL(relativeDir, import.meta.url))))
const nuxt = await loadNuxt({ cwd: path })
let nuxt: Nuxt
beforeAll(async () => {
nuxt = await loadNuxt({ cwd: path })
await rm(resolve(path, '.nuxt'), { recursive: true, force: true })
}, 20_000)
afterAll(async () => {
await nuxt.close()
})
}, 20_000)
bench('writeTypes in the basic-types fixture', async () => {
await writeTypes(nuxt)

View File

@ -0,0 +1,33 @@
import { fileURLToPath } from 'node:url'
import { rm } from 'node:fs/promises'
import { beforeAll, bench, describe } from 'vitest'
import { join, normalize } from 'pathe'
import { withoutTrailingSlash } from 'ufo'
import { build, loadNuxt } from 'nuxt'
const basicTestFixtureDir = withoutTrailingSlash(normalize(fileURLToPath(new URL('../../../test/fixtures/basic', import.meta.url))))
describe('build', () => {
beforeAll(async () => {
await rm(join(basicTestFixtureDir, '.nuxt'), { recursive: true, force: true })
})
bench('initial dev server build in the basic test fixture', async () => {
const nuxt = await loadNuxt({
cwd: basicTestFixtureDir,
ready: true,
overrides: {
dev: true,
sourcemap: false,
builder: {
bundle: () => Promise.resolve(),
},
},
})
await new Promise<void>((resolve) => {
nuxt.hook('build:done', () => resolve())
build(nuxt)
})
await nuxt.close()
})
})

View File

@ -1,6 +1,7 @@
import { fileURLToPath } from 'node:url'
import { bench, describe } from 'vitest'
import { normalize } from 'pathe'
import { rm } from 'node:fs/promises'
import { beforeAll, bench, describe } from 'vitest'
import { join, normalize } from 'pathe'
import { withoutTrailingSlash } from 'ufo'
import { loadNuxt } from 'nuxt'
@ -8,6 +9,13 @@ const emptyDir = withoutTrailingSlash(normalize(fileURLToPath(new URL('../../../
const basicTestFixtureDir = withoutTrailingSlash(normalize(fileURLToPath(new URL('../../../test/fixtures/basic', import.meta.url))))
describe('loadNuxt', () => {
beforeAll(async () => {
await Promise.all([
rm(join(emptyDir, '.nuxt'), { recursive: true, force: true }),
rm(join(basicTestFixtureDir, '.nuxt'), { recursive: true, force: true }),
])
})
bench('loadNuxt in an empty directory', async () => {
const nuxt = await loadNuxt({
cwd: emptyDir,