|
1 | 1 | import { fileURLToPath } from 'node:url'
|
2 | 2 | import { describe, expect, it } from 'vitest'
|
3 |
| -import { $fetch, setRuntimeConfig, setup } from '@nuxt/test-utils/e2e' |
| 3 | +import { $fetch, getBrowser, setRuntimeConfig, setup, url } from '@nuxt/test-utils/e2e' |
4 | 4 |
|
5 | 5 | describe('ssr', async () => {
|
6 | 6 | await setup({
|
7 | 7 | rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)),
|
| 8 | + browser: true, |
8 | 9 | })
|
9 | 10 |
|
10 | 11 | it('renders the index page', async () => {
|
11 | 12 | // Get response to a server-rendered page with `$fetch`.
|
12 | 13 | const html = await $fetch('/')
|
13 |
| - expect(html).toContain('<div>basic <span>original value</span></div>') |
| 14 | + expect(html).toContain('<span id="runtime">original value</span></div>') |
14 | 15 | })
|
15 | 16 |
|
16 |
| - it('changes runtime config and restarts', async () => { |
17 |
| - const restoreConfig = await setRuntimeConfig({ public: { myValue: 'overwritten by test!' } }) |
| 17 | + it('changes runtime config client-side', async () => { |
| 18 | + const browser = await getBrowser() |
| 19 | + const page = await browser.newPage() |
| 20 | + await page.goto(url('/')) |
18 | 21 |
|
19 |
| - const html = await $fetch('/') |
20 |
| - expect(html).toContain('<div>basic <span>overwritten by test!</span></div>') |
| 22 | + const el = page.locator('#runtime') |
| 23 | + expect(await el.innerText()).to.equal('original value') |
| 24 | + |
| 25 | + await page.evaluate(() => { |
| 26 | + window.__NUXT_TEST_RUNTIME_CONFIG_SETTER__({ public: { myValue: 'overwritten by test!' } }) |
| 27 | + }) |
| 28 | + |
| 29 | + expect(await el.innerText()).to.equal('overwritten by test!') |
| 30 | + }) |
| 31 | + |
| 32 | + it('changes runtime config in server route', async () => { |
| 33 | + const originalConfig = await $fetch('/api/config') |
| 34 | + expect(originalConfig.public.myValue).to.equal('original value') |
21 | 35 |
|
22 |
| - await restoreConfig() |
23 |
| - const htmlRestored = await $fetch('/') |
24 |
| - expect(htmlRestored).toContain('<div>basic <span>original value</span></div>') |
| 36 | + await setRuntimeConfig({ public: { myValue: 'overwritten by test!' } }) |
| 37 | + |
| 38 | + const newConfig = await $fetch('/api/config') |
| 39 | + expect(newConfig.public.myValue).to.equal('overwritten by test!') |
| 40 | + }) |
| 41 | + |
| 42 | + it('changes runtime config', async () => { |
| 43 | + await setRuntimeConfig({ public: { myValue: 'overwritten by test!' } }) |
| 44 | + |
| 45 | + const html = await $fetch('/') |
| 46 | + expect(html).toContain('<span id="runtime">overwritten by test!</span></div>') |
25 | 47 | })
|
26 | 48 | })
|
0 commit comments