mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 06:35:10 +00:00
chore: progress
This commit is contained in:
parent
84030919a5
commit
dd366aa494
@ -46,14 +46,14 @@ export default defineNuxtCommand({
|
|||||||
|
|
||||||
const { loadNuxt, loadNuxtConfig, buildNuxt } = await loadKit(rootDir)
|
const { loadNuxt, loadNuxtConfig, buildNuxt } = await loadKit(rootDir)
|
||||||
|
|
||||||
console.log('overrides', ...(process.env.NUXT_CONFIG_OVERRIDES ? JSON.parse(process.env.NUXT_CONFIG_OVERRIDES) : {}))
|
const overrides = {
|
||||||
const config = await loadNuxtConfig({
|
|
||||||
cwd: rootDir,
|
|
||||||
overrides: {
|
|
||||||
dev: true,
|
dev: true,
|
||||||
// used for testing
|
// used for testing
|
||||||
...(process.env.NUXT_CONFIG_OVERRIDES ? JSON.parse(process.env.NUXT_CONFIG_OVERRIDES) : {})
|
...(process.env.NUXT_CONFIG_OVERRIDES ? JSON.parse(process.env.NUXT_CONFIG_OVERRIDES) : {})
|
||||||
}
|
}
|
||||||
|
const config = await loadNuxtConfig({
|
||||||
|
cwd: rootDir,
|
||||||
|
overrides
|
||||||
})
|
})
|
||||||
|
|
||||||
const listener = await listen(serverHandler, {
|
const listener = await listen(serverHandler, {
|
||||||
@ -93,7 +93,7 @@ export default defineNuxtCommand({
|
|||||||
await distWatcher.close()
|
await distWatcher.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
currentNuxt = await loadNuxt({ rootDir, dev: true, ready: false })
|
currentNuxt = await loadNuxt({ rootDir, overrides, dev: true, ready: false })
|
||||||
|
|
||||||
currentNuxt.hooks.hookOnce('restart', async (options) => {
|
currentNuxt.hooks.hookOnce('restart', async (options) => {
|
||||||
if (options?.hard && process.send) {
|
if (options?.hard && process.send) {
|
||||||
|
@ -16,7 +16,7 @@ const isNuxtApp = (dir: string) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolveRootDir = () => {
|
export const resolveRootDir = () => {
|
||||||
const { options } = useTestContext()
|
const { options } = useTestContext()
|
||||||
|
|
||||||
const dirs = [
|
const dirs = [
|
||||||
@ -37,9 +37,6 @@ const resolveRootDir = () => {
|
|||||||
export async function loadFixture () {
|
export async function loadFixture () {
|
||||||
const ctx = useTestContext()
|
const ctx = useTestContext()
|
||||||
|
|
||||||
ctx.options.rootDir = resolveRootDir()
|
|
||||||
|
|
||||||
if (!ctx.options.dev) {
|
|
||||||
const randomId = Math.random().toString(36).slice(2, 8)
|
const randomId = Math.random().toString(36).slice(2, 8)
|
||||||
const buildDir = resolve(ctx.options.rootDir, '.nuxt', randomId)
|
const buildDir = resolve(ctx.options.rootDir, '.nuxt', randomId)
|
||||||
Object.assign(ctx.options.nuxtConfig, {
|
Object.assign(ctx.options.nuxtConfig, {
|
||||||
@ -50,7 +47,6 @@ export async function loadFixture () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
ctx.nuxt = await kit.loadNuxt({
|
ctx.nuxt = await kit.loadNuxt({
|
||||||
cwd: ctx.options.rootDir,
|
cwd: ctx.options.rootDir,
|
||||||
|
@ -15,7 +15,7 @@ export async function startDevServer () {
|
|||||||
const port = await getRandomPort()
|
const port = await getRandomPort()
|
||||||
const nuxiCLI = await kit.resolvePath('nuxi/cli')
|
const nuxiCLI = await kit.resolvePath('nuxi/cli')
|
||||||
ctx.serverProcess = execa(nuxiCLI, ['dev'], {
|
ctx.serverProcess = execa(nuxiCLI, ['dev'], {
|
||||||
cwd: ctx.nuxt!.options.rootDir,
|
cwd: ctx.options.rootDir,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
PORT: String(port),
|
PORT: String(port),
|
||||||
@ -24,6 +24,7 @@ export async function startDevServer () {
|
|||||||
NUXT_CONFIG_OVERRIDES: JSON.stringify(ctx.options.nuxtConfig)
|
NUXT_CONFIG_OVERRIDES: JSON.stringify(ctx.options.nuxtConfig)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
console.log('boot dev server', ctx.options.rootDir, JSON.stringify(ctx.options.nuxtConfig))
|
||||||
// wait until the server process displays the listening path
|
// wait until the server process displays the listening path
|
||||||
ctx.url = await new Promise<string>(resolve => {
|
ctx.url = await new Promise<string>(resolve => {
|
||||||
// @ts-expect-error untyoed
|
// @ts-expect-error untyoed
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createTestContext, setTestContext } from '../context'
|
import {createTestContext, setTestContext, useTestContext} from '../context'
|
||||||
import { loadFixture, buildFixture } from '../nuxt'
|
import {loadFixture, buildFixture, resolveRootDir} from '../nuxt'
|
||||||
import {startDevServer, startServer, stopServer} from '../server'
|
import {startDevServer, startServer, stopServer} from '../server'
|
||||||
import { createBrowser } from '../browser'
|
import { createBrowser } from '../browser'
|
||||||
import type { TestHooks, TestOptions } from '../types'
|
import type { TestHooks, TestOptions } from '../types'
|
||||||
@ -37,13 +37,16 @@ export function createTest (options: Partial<TestOptions>): TestHooks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
if (ctx.options.fixture) {
|
const ctx = useTestContext()
|
||||||
await loadFixture()
|
ctx.options.rootDir = resolveRootDir()
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx.options.dev) {
|
if (ctx.options.dev) {
|
||||||
await startDevServer()
|
await startDevServer()
|
||||||
} else {
|
} else {
|
||||||
|
if (ctx.options.fixture) {
|
||||||
|
await loadFixture()
|
||||||
|
}
|
||||||
|
|
||||||
if (ctx.options.build) {
|
if (ctx.options.build) {
|
||||||
await buildFixture()
|
await buildFixture()
|
||||||
}
|
}
|
||||||
|
@ -4,25 +4,29 @@ import { setup, $fetch } from '@nuxt/test-utils'
|
|||||||
import { describe, it, expect } from 'vitest'
|
import { describe, it, expect } from 'vitest'
|
||||||
|
|
||||||
await setup({
|
await setup({
|
||||||
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)),
|
rootDir: fileURLToPath(new URL('./fixtures/minimal', import.meta.url)),
|
||||||
dev: true,
|
dev: true,
|
||||||
nuxtConfig: {
|
nuxtConfig: {
|
||||||
app: {
|
app: {
|
||||||
baseURL: '/test'
|
baseURL: '/test'
|
||||||
|
},
|
||||||
|
runtimeConfig: {
|
||||||
|
public: {
|
||||||
|
foo: 'bar',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
describe('dev tests', () => {
|
describe('dev tests', () => {
|
||||||
it('should just work', async () => {
|
it('config is overriden', async () => {
|
||||||
expect(await $fetch('/')).toMatchInlineSnapshot(`
|
const html = await $fetch('/')
|
||||||
"<!DOCTYPE html>
|
const expr = /window.__NUXT__=({.*})<\/script>/.exec(html)![1]
|
||||||
<html >
|
expect(expr).toMatchInlineSnapshot('"{data:{},state:{},_errors:{},serverRendered:true,config:{public:{foo:\\"bar\\"},app:{baseURL:\\"\\\\u002Ftest\\",buildAssetsDir:\\"\\\\u002F_nuxt\\\\u002F\\",cdnURL:\\"\\"}}}"')
|
||||||
<head><meta charset=\\"utf-8\\">
|
|
||||||
<meta name=\\"viewport\\" content=\\"width=1024, initial-scale=1\\">
|
// expr is a javascript object string, but not valid JSON, we need to turn it a real object
|
||||||
<title>- Fixture</title><link rel=\\"preload\\" as=\\"style\\" href=\\"/_nuxt/assets/global.css\\"><link rel=\\"preload\\" as=\\"style\\" href=\\"/_nuxt/virtual.css\\"><link rel=\\"preload\\" as=\\"style\\" href=\\"/_nuxt/assets/plugin.css\\"><link rel=\\"modulepreload\\" as=\\"script\\" crossorigin href=\\"/_nuxt/home/harlan/forks/nuxt3/packages/nuxt/src/app/entry.ts\\"><link rel=\\"stylesheet\\" href=\\"/_nuxt/assets/global.css\\"><link rel=\\"stylesheet\\" href=\\"/_nuxt/virtual.css\\"><link rel=\\"stylesheet\\" href=\\"/_nuxt/assets/plugin.css\\"></head>
|
const obj = JSON.parse(expr.replace(/(\w+):/g, '"$1":'))
|
||||||
<body ><div id=\\"__nuxt\\"><div><div>Extended layout from foo</div><div><h1>[...slug].vue</h1><div>catchall at > Network: http:</div><div>Middleware ran: true</div></div></div></div><script>window.__NUXT__=(function(a){return {data:{hey:{foo:\\"bar\\",baz:\\"qux\\"}},state:{},_errors:{},serverRendered:true,config:{public:{ids:[1,2,3],needsFallback:a,testConfig:123},app:{baseURL:\\"\\\\u002F\\",buildAssetsDir:\\"\\\\u002F_nuxt\\\\u002F\\",cdnURL:a}},prerenderedAt:1678028804677}}(\\"\\"))</script><script type=\\"module\\" src=\\"/_nuxt/@vite/client\\" crossorigin></script><script type=\\"module\\" src=\\"/_nuxt/home/harlan/forks/nuxt3/packages/nuxt/src/app/entry.ts\\" crossorigin></script></body>
|
expect(obj.config.public.foo).toBe('bar')
|
||||||
</html>"
|
expect(obj.config.app.baseURL).toBe('/test')
|
||||||
`)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user