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
26 changes: 26 additions & 0 deletions examples/module/test/dot-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { $fetch, setup, startServer } from '@nuxt/test-utils/e2e'

describe('ssr', async () => {
await setup({
rootDir: fileURLToPath(new URL('./fixtures/dot-config', import.meta.url)),
})

it('renders the index page', async () => {
// Get response to a server-rendered page with `$fetch`.
const html = await $fetch('/')
expect(html).toContain('<div>dot-config <span>original value</span></div>')
})

it('changes runtime config and restarts', { timeout: 120000 }, async () => {
await startServer({ env: { NUXT_PUBLIC_MY_VALUE: 'overwritten by test!' } })

const html = await $fetch('/')
expect(html).toContain('<div>dot-config <span>overwritten by test!</span></div>')

await startServer()
const htmlRestored = await $fetch('/')
expect(htmlRestored).toContain('<div>dot-config <span>original value</span></div>')
})
})
13 changes: 13 additions & 0 deletions examples/module/test/fixtures/dot-config/.config/nuxt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import MyModule from '../../../../src/module'

export default defineNuxtConfig({
modules: [
MyModule,
],
runtimeConfig: {
public: {
myValue: 'original value',
},
},
compatibilityDate: '2024-04-03',
})
7 changes: 7 additions & 0 deletions examples/module/test/fixtures/dot-config/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div>dot-config <span>{{ config.public.myValue }}</span></div>
</template>

<script setup>
const config = useRuntimeConfig()
</script>
5 changes: 5 additions & 0 deletions examples/module/test/fixtures/dot-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"private": true,
"name": "example-module-dot-config-fixture",
"type": "module"
}
4 changes: 4 additions & 0 deletions src/e2e/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const isNuxtApp = (dir: string) => {
|| existsSync(resolve(dir, 'nuxt.config.mjs'))
|| existsSync(resolve(dir, 'nuxt.config.cjs'))
|| existsSync(resolve(dir, 'nuxt.config.ts'))
|| existsSync(resolve(dir, '.config', 'nuxt.js'))
|| existsSync(resolve(dir, '.config', 'nuxt.mjs'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

maybe ultimately we might try to get a resolveConfigPath into c12 so we have one location for configuration resolution (cc: @pi0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Feel free to open an issue so we don't forget!

|| existsSync(resolve(dir, '.config', 'nuxt.cjs'))
|| existsSync(resolve(dir, '.config', 'nuxt.ts'))
)
}

Expand Down
Loading