Skip to content

Commit

Permalink
feat(e2e): allow updating env in context before setup runs (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
linspw authored Jul 26, 2024
1 parent c4df41d commit 0fe0e6b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion examples/app-playwright/app.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<h1>
Welcome to Playwright!
{{ config.public.myValue }}
</h1>
</template>

<script setup>
const config = useRuntimeConfig()
</script>
5 changes: 5 additions & 0 deletions examples/app-playwright/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
runtimeConfig: {
public: {
myValue: 'Welcome to Playwright!',
},
},
})
14 changes: 14 additions & 0 deletions examples/app-playwright/tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@ test('test', async ({ page, goto }) => {
await goto('/', { waitUntil: 'hydration' })
await expect(page.getByRole('heading')).toHaveText('Welcome to Playwright!')
})

const testHello = test.extend({
nuxt: async ({ nuxt }, use) => {
nuxt!.env = {
NUXT_PUBLIC_MY_VALUE: 'Hello World!',
}
await use(nuxt)
},
})

testHello('testing', async ({ page, goto }) => {
await goto('/', { waitUntil: 'hydration' })
await expect(page.getByRole('heading')).toHaveText('Hello World!')
})
2 changes: 2 additions & 0 deletions src/core/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export async function startServer(options: StartServerOptions = {}) {
HOST: host,
NODE_ENV: 'development',
...options.env,
...ctx.options.env,
},
})
await waitForPort(port, { retries: 32, host }).catch(() => {})
Expand Down Expand Up @@ -62,6 +63,7 @@ export async function startServer(options: StartServerOptions = {}) {
HOST: host,
NODE_ENV: 'test',
...options.env,
...ctx.options.env,
},
})
await waitForPort(port, { retries: 20, host })
Expand Down

0 comments on commit 0fe0e6b

Please sign in to comment.