Repository navigation
fix(e2e): apply nuxtConfig overrides to dev server
#1851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { fileURLToPath } from 'node:url' | ||
| import { createTest, setTestContext } from '@nuxt/test-utils/e2e' | ||
| import { afterAll, beforeAll, describe, expect, it } from 'vitest' | ||
|
|
||
| const rootDir = fileURLToPath(new URL('../../', import.meta.url)) | ||
| const servers = [createTest({ rootDir, dev: true }), createTest({ rootDir, dev: true })] | ||
|
|
||
| for (const server of servers) { | ||
| beforeAll(async () => { | ||
| setTestContext(server.ctx) | ||
| await server.beforeAll() | ||
| }, server.ctx.options.setupTimeout) | ||
| afterAll(server.afterAll, server.ctx.options.teardownTimeout) | ||
| } | ||
|
|
||
| describe('concurrent dev servers', () => { | ||
| it('runs two dev servers for the same fixture', async () => { | ||
| const [first, second] = servers.map(server => server.ctx) | ||
| expect(first!.nuxt!.options.buildDir).not.toBe(second!.nuxt!.options.buildDir) | ||
| for (const ctx of [first!, second!]) { | ||
| const html = await fetch(ctx.url!).then(res => res.text()) | ||
| expect(html).toContain('My title') | ||
| } | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { fileURLToPath } from 'node:url' | ||
| import { $fetch, setup } from '@nuxt/test-utils/e2e' | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| await setup({ | ||
| rootDir: fileURLToPath(new URL('../../', import.meta.url)), | ||
| dev: true, | ||
| nuxtConfig: { | ||
| ssr: false, | ||
| app: { head: { title: 'Overridden in dev' } }, | ||
| }, | ||
| }) | ||
|
|
||
| describe('server (dev) with nuxtConfig overrides', () => { | ||
| it('applies the overrides to the dev server', async () => { | ||
| const html = await $fetch<string>('/') | ||
| expect(html).toContain('<title>Overridden in dev</title>') | ||
| expect(html).not.toContain('My title') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import process from 'node:process' | ||
| import { pathToFileURL } from 'node:url' | ||
|
|
||
| interface NuxtCli { | ||
| runCommand: (name: string, argv?: string[], data?: { overrides?: Record<string, unknown> }) => Promise<unknown> | ||
| } | ||
|
|
||
| const overrides = JSON.parse(process.env.__NUXT_TEST_DEV_OVERRIDES__ || '{}') | ||
| delete process.env.__NUXT_TEST_DEV_OVERRIDES__ | ||
|
|
||
| process.on('unhandledRejection', err => console.error('[unhandledRejection]', err)) | ||
| process.on('uncaughtException', err => console.error('[uncaughtException]', err)) | ||
|
|
||
| const { runCommand }: NuxtCli = await import(pathToFileURL(process.argv[2]!).href) | ||
| await runCommand('_dev', [], { overrides }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { toSerializable } from '../../src/utils.ts' | ||
|
|
||
| describe('toSerializable', () => { | ||
| it('should keep plain values and report the paths of values that cannot be serialized', () => { | ||
| const source: Record<string, unknown> = { | ||
| ssr: false, | ||
| app: { head: { title: 'title' } }, | ||
| hooks: { ready: () => {} }, | ||
| modules: ['a', () => {}, undefined, 'b'], | ||
| build: { transpile: [/foo/] }, | ||
| } | ||
| source.self = source | ||
|
|
||
| expect(toSerializable(source)).toEqual({ | ||
| value: { | ||
| ssr: false, | ||
| app: { head: { title: 'title' } }, | ||
| hooks: {}, | ||
| modules: ['a', 'b'], | ||
| build: { transpile: [] }, | ||
| }, | ||
| omitted: ['hooks.ready', 'modules[1]', 'build.transpile[0]', 'self'], | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Copy only own properties into a null-prototype object.
If
nuxtConfighas an own__proto__key, assignment to{}changes the copy’s prototype instead of retaining that key for JSON serialization. IfObject.prototypehas an enumerable property,for...inalso adds that inherited property to the dev-server overrides. UseObject.create(null)forcopyand iterate withObject.entries(input). Based on learnings, canonical copies should preserve__proto__as an own key and exclude inherited properties.🤖 Prompt for AI Agents
Source: Learnings