mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-10 10:48:10 +00:00
test: add benchmarks for dev server initial build (#30742)
This commit is contained in:
parent
82c2e86d38
commit
4e0ef29d1c
@ -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)
|
||||
|
33
packages/nuxt/test/build.bench.ts
Normal file
33
packages/nuxt/test/build.bench.ts
Normal 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()
|
||||
})
|
||||
})
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user