Add Playwright E2E tests with MSW API mocking
- Playwright + @msw/playwright + @msw/source for OpenAPI-driven mocks - Chromium-only configuration with Vite dev server integration - Smoke tests: home page, CTA, navigation - US-1 tests: validation, event creation flow, localStorage, error handling - Suppress Node 25 --localstorage-file warning from MSW cookieStore
This commit is contained in:
30
frontend/e2e/msw-setup.ts
Normal file
30
frontend/e2e/msw-setup.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { test as base, expect } from '@playwright/test'
|
||||
import { defineNetworkFixture, type NetworkFixture } from '@msw/playwright'
|
||||
import { fromOpenApi } from '@msw/source/open-api'
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
||||
const specPath = resolve(__dirname, '../../backend/src/main/resources/openapi/api.yaml')
|
||||
const spec = readFileSync(specPath, 'utf-8')
|
||||
|
||||
const handlers = await fromOpenApi(spec)
|
||||
|
||||
interface Fixtures {
|
||||
network: NetworkFixture
|
||||
}
|
||||
|
||||
export const test = base.extend<Fixtures>({
|
||||
network: [
|
||||
async ({ context }, use) => {
|
||||
const network = defineNetworkFixture({ context, handlers })
|
||||
await network.enable()
|
||||
await use(network)
|
||||
await network.disable()
|
||||
},
|
||||
{ auto: true },
|
||||
],
|
||||
})
|
||||
|
||||
export { expect }
|
||||
Reference in New Issue
Block a user