chore: messing around

This commit is contained in:
Harlan Wilton 2023-03-06 23:58:02 +11:00
parent 723a55b500
commit 4bae4df057
3 changed files with 30 additions and 22 deletions

View File

@ -37,17 +37,6 @@ export const resolveRootDir = () => {
export async function loadFixture () { export async function loadFixture () {
const ctx = useTestContext() const ctx = useTestContext()
const randomId = Math.random().toString(36).slice(2, 8)
const buildDir = resolve(ctx.options.rootDir, '.nuxt', randomId)
Object.assign(ctx.options.nuxtConfig, {
buildDir,
nitro: {
output: {
dir: resolve(buildDir, 'output')
}
}
})
ctx.nuxt = await kit.loadNuxt({ ctx.nuxt = await kit.loadNuxt({
cwd: ctx.options.rootDir, cwd: ctx.options.rootDir,
dev: ctx.options.dev, dev: ctx.options.dev,

View File

@ -5,6 +5,8 @@ import { createBrowser } from '../browser'
import type { TestHooks, TestOptions } from '../types' import type { TestHooks, TestOptions } from '../types'
import setupJest from './jest' import setupJest from './jest'
import setupVitest from './vitest' import setupVitest from './vitest'
import {resolve} from "node:path";
import {promises as fsp} from "node:fs";
export const setupMaps = { export const setupMaps = {
jest: setupJest, jest: setupJest,
@ -40,9 +42,22 @@ export function createTest (options: Partial<TestOptions>): TestHooks {
const ctx = useTestContext() const ctx = useTestContext()
ctx.options.rootDir = resolveRootDir() ctx.options.rootDir = resolveRootDir()
if (ctx.options.dev) { // always output to a random build dir
const randomId = Math.random().toString(36).slice(2, 8)
const buildDir = resolve(ctx.options.rootDir, '.nuxt', randomId)
Object.assign(ctx.options.nuxtConfig, {
buildDir,
nitro: {
output: {
dir: resolve(buildDir, 'output')
}
}
})
await fsp.mkdir(buildDir, { recursive: true })
if (ctx.options.devServer) {
await startDevServer() await startDevServer()
} else { }
if (ctx.options.fixture) { if (ctx.options.fixture) {
await loadFixture() await loadFixture()
} }
@ -54,7 +69,6 @@ export function createTest (options: Partial<TestOptions>): TestHooks {
if (ctx.options.server) { if (ctx.options.server) {
await startServer() await startServer()
} }
}
if (ctx.options.waitFor) { if (ctx.options.waitFor) {
await (new Promise(resolve => setTimeout(resolve, ctx.options.waitFor))) await (new Promise(resolve => setTimeout(resolve, ctx.options.waitFor)))

View File

@ -12,7 +12,12 @@ export interface TestOptions {
buildDir: string buildDir: string
nuxtConfig: NuxtConfig nuxtConfig: NuxtConfig
build: boolean build: boolean
/**
* @deprecated use `devServer`
*/
dev: boolean dev: boolean
devServer: boolean
setupTimeout: number setupTimeout: number
waitFor: number waitFor: number
browser: boolean browser: boolean