Skip to content

Commit b7355dc

Browse files
committed
test: confirm setRuntimeConfig works
1 parent ae80876 commit b7355dc

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

examples/module/test/basic.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { fileURLToPath } from 'node:url'
22
import { describe, expect, it } from 'vitest'
33
import { $fetch, setup } from '@nuxt/test-utils/e2e'
4+
import { setRuntimeConfig } from '@nuxt/test-utils/module-utils'
45

56
describe('ssr', async () => {
67
await setup({
@@ -10,6 +11,18 @@ describe('ssr', async () => {
1011
it('renders the index page', async () => {
1112
// Get response to a server-rendered page with `$fetch`.
1213
const html = await $fetch('/')
13-
expect(html).toContain('<div>basic</div>')
14+
expect(html).toContain('<div>basic <span>original value</span></div>')
15+
})
16+
17+
18+
it('changes runtime config and restarts', async () => {
19+
const restoreConfig = await setRuntimeConfig({ public: { myValue: 'overwritten by test!' } })
20+
21+
const html = await $fetch('/')
22+
expect(html).toContain('<div>basic <span>overwritten by test!</span></div>')
23+
24+
await restoreConfig()
25+
const htmlRestored = await $fetch('/')
26+
expect(htmlRestored).toContain('<div>basic <span>original value</span></div>')
1427
})
1528
})
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
2-
<div>basic</div>
2+
<div>basic <span>{{ config.public.myValue }}</span></div>
33
</template>
44

55
<script setup>
6+
const config = useRuntimeConfig();
67
</script>

examples/module/test/fixtures/basic/nuxt.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import MyModule from '../../../src/module'
22

33
export default defineNuxtConfig({
4+
runtimeConfig: {
5+
public: {
6+
myValue: 'original value',
7+
},
8+
},
49
modules: [
510
MyModule
611
]

0 commit comments

Comments
 (0)