mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 09:55:53 +00:00
45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
import { fileURLToPath } from 'node:url'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { normalize } from 'pathe'
|
|
import { withoutTrailingSlash } from 'ufo'
|
|
import { loadNuxt } from '../src'
|
|
|
|
const repoRoot = withoutTrailingSlash(normalize(fileURLToPath(new URL('../../../', import.meta.url))))
|
|
|
|
vi.stubGlobal('console', {
|
|
...console,
|
|
error: vi.fn(console.error),
|
|
warn: vi.fn(console.warn),
|
|
})
|
|
|
|
vi.mock('pkg-types', async (og) => {
|
|
const originalPkgTypes = (await og<typeof import('pkg-types')>())
|
|
return {
|
|
...originalPkgTypes,
|
|
readPackageJSON: vi.fn(originalPkgTypes.readPackageJSON),
|
|
}
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
describe('loadNuxt', () => {
|
|
it('respects hook overrides', async () => {
|
|
let hookRan = false
|
|
const nuxt = await loadNuxt({
|
|
cwd: repoRoot,
|
|
ready: true,
|
|
overrides: {
|
|
hooks: {
|
|
ready () {
|
|
hookRan = true
|
|
},
|
|
},
|
|
},
|
|
})
|
|
await nuxt.close()
|
|
expect(hookRan).toBe(true)
|
|
})
|
|
})
|