diff --git a/examples/module/test/dot-config.test.ts b/examples/module/test/dot-config.test.ts new file mode 100644 index 000000000..e4889ef48 --- /dev/null +++ b/examples/module/test/dot-config.test.ts @@ -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('
dot-config original value
') + }) + + 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('
dot-config overwritten by test!
') + + await startServer() + const htmlRestored = await $fetch('/') + expect(htmlRestored).toContain('
dot-config original value
') + }) +}) diff --git a/examples/module/test/fixtures/dot-config/.config/nuxt.ts b/examples/module/test/fixtures/dot-config/.config/nuxt.ts new file mode 100644 index 000000000..37dfc832c --- /dev/null +++ b/examples/module/test/fixtures/dot-config/.config/nuxt.ts @@ -0,0 +1,13 @@ +import MyModule from '../../../../src/module' + +export default defineNuxtConfig({ + modules: [ + MyModule, + ], + runtimeConfig: { + public: { + myValue: 'original value', + }, + }, + compatibilityDate: '2024-04-03', +}) diff --git a/examples/module/test/fixtures/dot-config/app.vue b/examples/module/test/fixtures/dot-config/app.vue new file mode 100644 index 000000000..6b47d7a7d --- /dev/null +++ b/examples/module/test/fixtures/dot-config/app.vue @@ -0,0 +1,7 @@ + + + diff --git a/examples/module/test/fixtures/dot-config/package.json b/examples/module/test/fixtures/dot-config/package.json new file mode 100644 index 000000000..3503431ee --- /dev/null +++ b/examples/module/test/fixtures/dot-config/package.json @@ -0,0 +1,5 @@ +{ + "private": true, + "name": "example-module-dot-config-fixture", + "type": "module" +} diff --git a/src/e2e/nuxt.ts b/src/e2e/nuxt.ts index 7f8988687..b6fa72d07 100644 --- a/src/e2e/nuxt.ts +++ b/src/e2e/nuxt.ts @@ -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')) + || existsSync(resolve(dir, '.config', 'nuxt.cjs')) + || existsSync(resolve(dir, '.config', 'nuxt.ts')) ) }