diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-12-11 17:52:38 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-12-11 17:52:38 +0100 |
| commit | 93db24b7f7650abac1bb7095026e3a1f367b0c0a (patch) | |
| tree | c6efd8669d333941494e573d2468a4fb6603b134 /tests/cypress/support/msw.ts | |
| parent | cd2cb5748be9e9c479d9802dd3897de1cd1cbd9f (diff) | |
refactor(pages): refine Contact page
* remove next/router dependency
* remove pageTitle since it is defined in MDX
* reduce statements by grouping messages
* mock response with MSW and add test for sendEmail
Diffstat (limited to 'tests/cypress/support/msw.ts')
| -rw-r--r-- | tests/cypress/support/msw.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/cypress/support/msw.ts b/tests/cypress/support/msw.ts new file mode 100644 index 0000000..829b147 --- /dev/null +++ b/tests/cypress/support/msw.ts @@ -0,0 +1,44 @@ +import type { SetupWorker } from 'msw/lib/browser'; + +export type CustomWindow = { + msw?: { + worker: SetupWorker; + }; +} & Window; + +Cypress.on('test:before:run:async', async () => { + window.process = { + // @ts-expect-error -- window.process type is not NodeJS process type + env: { + NEXT_PUBLIC_STAGING_GRAPHQL_API: Cypress.env( + 'NEXT_PUBLIC_STAGING_GRAPHQL_API' + ), + }, + }; + + if (!('msw' in window) || !window.msw) { + const { worker } = await import('../../msw/browser'); + await worker + .start({ + onUnhandledRequest(request) { + if ( + request.url.includes('/_next/') || + request.url.includes('/__next') + ) { + return; + } + + console.warn( + '[MSW] Warning: intercepted a request without a matching request handler: %s %s', + request.method, + request.url + ); + }, + }) + .then(() => { + (window as CustomWindow).msw = { + worker, + }; + }); + } +}); |
