Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test:types": "tsc --noEmit",
"test:knip": "knip",
"test:dist": "pnpm -r test:dist",
"test:unit": "vitest --coverage"
"test:unit": "vitest --coverage --run && pnpm --filter nuxt-cli-playground test --run"
},
"devDependencies": {
"@antfu/eslint-config": "^4.16.2",
Expand Down
8 changes: 6 additions & 2 deletions packages/nuxi/src/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class IPC {

const ipc = new IPC()

export async function initialize(devContext: NuxtDevContext, ctx: InitializeOptions = {}, listenOptions?: true | Partial<ListenOptions>) {
export async function initialize(devContext: NuxtDevContext, ctx: InitializeOptions = {}, _listenOptions?: true | Partial<ListenOptions>) {
const devServerOverrides = resolveDevServerOverrides({
public: devContext.public,
})
Expand All @@ -52,6 +52,11 @@ export async function initialize(devContext: NuxtDevContext, ctx: InitializeOpti
https: devContext.proxy?.https,
}, devContext.publicURLs)

// _PORT is used by `@nuxt/test-utils` to launch the dev server on a specific port
const listenOptions = _listenOptions === true || process.env._PORT
? { port: process.env._PORT ?? 0, hostname: '127.0.0.1', showURL: false }
: _listenOptions

// Init Nuxt dev
const devServer = await createNuxtDevServer({
cwd: devContext.cwd,
Expand All @@ -61,7 +66,6 @@ export async function initialize(devContext: NuxtDevContext, ctx: InitializeOpti
clear: !!devContext.args.clear,
dotenv: { cwd: devContext.cwd, fileName: devContext.args.dotenv },
envName: devContext.args.envName,
port: process.env._PORT ?? undefined,
devContext,
}, listenOptions)

Expand Down
15 changes: 15 additions & 0 deletions playground/test/e2e/build.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fileURLToPath } from 'node:url'
import { $fetch, setup } from '@nuxt/test-utils'
import { describe, expect, it } from 'vitest'

await setup({
rootDir: fileURLToPath(new URL('../..', import.meta.url)),
})

describe('built server', () => {
it('should start and return HTML', async () => {
const html = await $fetch('/')

expect(html).toContain('Welcome to the Nuxt CLI playground')
})
})
14 changes: 7 additions & 7 deletions playground/test/e2e/dev.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// import { fileURLToPath } from 'node:url'
// import { $fetch, setup } from '@nuxt/test-utils'
import { fileURLToPath } from 'node:url'
import { $fetch, setup } from '@nuxt/test-utils'
import { describe, expect, it } from 'vitest'

// await setup({
// rootDir: fileURLToPath(new URL('../..', import.meta.url)),
// dev: true,
// })
await setup({
rootDir: fileURLToPath(new URL('../..', import.meta.url)),
dev: true,
})

describe('dev server', () => {
it.skip('should start and return HTML', async () => {
it('should start and return HTML', async () => {
const html = await $fetch('/')

expect(html).toContain('Welcome to the Nuxt CLI playground')
Expand Down
6 changes: 5 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import codspeed from '@codspeed/vitest-plugin'
import { defineConfig } from 'vitest/config'
import { defaultExclude, defineConfig } from 'vitest/config'

export default defineConfig({
plugins: [codspeed()],
test: {
coverage: {},
exclude: [
...defaultExclude,
'playground/**',
],
},
})