mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-11 03:08:16 +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 { fileURLToPath } from 'node:url'
|
||||||
import { afterAll, bench, describe } from 'vitest'
|
import { rm } from 'node:fs/promises'
|
||||||
import { join, normalize } from 'pathe'
|
import { afterAll, beforeAll, bench, describe } from 'vitest'
|
||||||
|
import { join, normalize, resolve } from 'pathe'
|
||||||
import { withoutTrailingSlash } from 'ufo'
|
import { withoutTrailingSlash } from 'ufo'
|
||||||
import { loadNuxt, writeTypes } from '@nuxt/kit'
|
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 relativeDir = join('../../..', 'test/fixtures/basic-types')
|
||||||
const path = withoutTrailingSlash(normalize(fileURLToPath(new URL(relativeDir, import.meta.url))))
|
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 () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
}, 20_000)
|
||||||
|
|
||||||
bench('writeTypes in the basic-types fixture', async () => {
|
bench('writeTypes in the basic-types fixture', async () => {
|
||||||
await writeTypes(nuxt)
|
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 { fileURLToPath } from 'node:url'
|
||||||
import { bench, describe } from 'vitest'
|
import { rm } from 'node:fs/promises'
|
||||||
import { normalize } from 'pathe'
|
import { beforeAll, bench, describe } from 'vitest'
|
||||||
|
import { join, normalize } from 'pathe'
|
||||||
import { withoutTrailingSlash } from 'ufo'
|
import { withoutTrailingSlash } from 'ufo'
|
||||||
import { loadNuxt } from 'nuxt'
|
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))))
|
const basicTestFixtureDir = withoutTrailingSlash(normalize(fileURLToPath(new URL('../../../test/fixtures/basic', import.meta.url))))
|
||||||
|
|
||||||
describe('loadNuxt', () => {
|
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 () => {
|
bench('loadNuxt in an empty directory', async () => {
|
||||||
const nuxt = await loadNuxt({
|
const nuxt = await loadNuxt({
|
||||||
cwd: emptyDir,
|
cwd: emptyDir,
|
||||||
|
Loading…
Reference in New Issue
Block a user