Skip to content

Commit

Permalink
fix(e2e): use nuxtConfig.nitro.output.dir with build: false (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Rozhkov authored Dec 5, 2024
1 parent 56122b7 commit bddac9e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
43 changes: 43 additions & 0 deletions examples/app-vitest/test/build-false.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { fileURLToPath } from 'node:url'
import { resolve } from 'node:path'
import { $fetch, setup } from '@nuxt/test-utils/e2e'
import { describe, expect, it } from 'vitest'
import { loadNuxt, buildNuxt } from '@nuxt/kit'

const rootDir = fileURLToPath(new URL('../', import.meta.url))
const randomId = Math.random().toString(36).slice(2, 8)
const buildDir = resolve(rootDir, '.nuxt', 'test', randomId)
const buildOutput = resolve(buildDir, 'output')
const nuxt = await loadNuxt({
cwd: rootDir,
overrides: {
buildDir,
nitro: {
output: {
dir: buildOutput,
},
},
},
})
await buildNuxt(nuxt)
await setup({
rootDir,
buildDir,
nuxtConfig: {
nitro: {
output: {
dir: buildOutput,
},
},
},
build: false,
})

describe('build: false', () => {
it('runs a test', async () => {
const html = await $fetch('/')
expect(html.slice(0, 15)).toMatchInlineSnapshot(`
"<!DOCTYPE html>"
`)
})
})
3 changes: 2 additions & 1 deletion src/core/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ export async function startServer(options: StartServerOptions = {}) {
throw lastError || new Error('Timeout waiting for dev server!')
}
else {
const outputDir = ctx.nuxt ? ctx.nuxt.options.nitro.output!.dir! : ctx.options.nuxtConfig.nitro!.output!.dir!
ctx.serverProcess = exec(
'node',
[resolve(ctx.nuxt!.options.nitro.output!.dir!, 'server/index.mjs')],
[resolve(outputDir, 'server/index.mjs')],
{
nodeOptions: {
stdio: 'inherit',
Expand Down

0 comments on commit bddac9e

Please sign in to comment.