Skip to content

Commit 0fe0e6b

Browse files
authored
feat(e2e): allow updating env in context before setup runs (#812)
1 parent c4df41d commit 0fe0e6b

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

examples/app-playwright/app.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<template>
22
<h1>
3-
Welcome to Playwright!
3+
{{ config.public.myValue }}
44
</h1>
55
</template>
6+
7+
<script setup>
8+
const config = useRuntimeConfig()
9+
</script>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
// https://nuxt.com/docs/api/configuration/nuxt-config
22
export default defineNuxtConfig({
33
devtools: { enabled: true },
4+
runtimeConfig: {
5+
public: {
6+
myValue: 'Welcome to Playwright!',
7+
},
8+
},
49
})

examples/app-playwright/tests/basic.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,17 @@ test('test', async ({ page, goto }) => {
44
await goto('/', { waitUntil: 'hydration' })
55
await expect(page.getByRole('heading')).toHaveText('Welcome to Playwright!')
66
})
7+
8+
const testHello = test.extend({
9+
nuxt: async ({ nuxt }, use) => {
10+
nuxt!.env = {
11+
NUXT_PUBLIC_MY_VALUE: 'Hello World!',
12+
}
13+
await use(nuxt)
14+
},
15+
})
16+
17+
testHello('testing', async ({ page, goto }) => {
18+
await goto('/', { waitUntil: 'hydration' })
19+
await expect(page.getByRole('heading')).toHaveText('Hello World!')
20+
})

src/core/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export async function startServer(options: StartServerOptions = {}) {
3232
HOST: host,
3333
NODE_ENV: 'development',
3434
...options.env,
35+
...ctx.options.env,
3536
},
3637
})
3738
await waitForPort(port, { retries: 32, host }).catch(() => {})
@@ -62,6 +63,7 @@ export async function startServer(options: StartServerOptions = {}) {
6263
HOST: host,
6364
NODE_ENV: 'test',
6465
...options.env,
66+
...ctx.options.env,
6567
},
6668
})
6769
await waitForPort(port, { retries: 20, host })

0 commit comments

Comments
 (0)