Unverified Commit 2e488403 authored by Kevin Mårtensson's avatar Kevin Mårtensson Committed by GitHub

chore: bump supported `msw` version to `v2.3.0` (#66351)

### What?

This bumps the supported `msw` version when using the `playwright` test
mode. There's no need for mocking requests and responses anymore since
[they adopted](https://github.com/mswjs/msw/pull/1436) the global fetch
API in `msw`.

### Why?

Users can extend `test` from `playwright` manually and create the `msw`
fixtures, but it's better if it works out of the box with newer versions
of `msw`.

Fixes #63338.
Co-authored-by: 's avatarSam Ko <sam@vercel.com>
parent 9622d89e
...@@ -263,7 +263,7 @@ ...@@ -263,7 +263,7 @@
"lodash.curry": "4.1.1", "lodash.curry": "4.1.1",
"lru-cache": "5.1.1", "lru-cache": "5.1.1",
"mini-css-extract-plugin": "2.4.4", "mini-css-extract-plugin": "2.4.4",
"msw": "1.3.0", "msw": "2.3.0",
"nanoid": "3.1.32", "nanoid": "3.1.32",
"native-url": "0.3.4", "native-url": "0.3.4",
"neo-async": "2.6.1", "neo-async": "2.6.1",
......
import { test as base, defineConfig } from './index' import { test as base, defineConfig } from './index'
import type { NextFixture } from './next-fixture' import type { NextFixture } from './next-fixture'
// eslint-disable-next-line import/no-extraneous-dependencies // eslint-disable-next-line import/no-extraneous-dependencies
import { import { type RequestHandler, handleRequest } from 'msw'
type RequestHandler,
type MockedResponse,
MockedRequest,
handleRequest,
} from 'msw'
// eslint-disable-next-line import/no-extraneous-dependencies // eslint-disable-next-line import/no-extraneous-dependencies
import { Emitter } from 'strict-event-emitter' import { Emitter } from 'strict-event-emitter'
...@@ -33,39 +28,13 @@ export const test = base.extend<{ ...@@ -33,39 +28,13 @@ export const test = base.extend<{
const emitter = new Emitter() const emitter = new Emitter()
next.onFetch(async (request) => { next.onFetch(async (request) => {
const { const requestId = Math.random().toString(16).slice(2)
body,
method,
headers,
credentials,
cache,
redirect,
integrity,
keepalive,
mode,
destination,
referrer,
referrerPolicy,
} = request
const mockedRequest = new MockedRequest(new URL(request.url), {
body: body ? await request.arrayBuffer() : undefined,
method,
headers: Object.fromEntries(headers),
credentials,
cache,
redirect,
integrity,
keepalive,
mode,
destination,
referrer,
referrerPolicy,
})
let isUnhandled = false let isUnhandled = false
let isPassthrough = false let isPassthrough = false
let mockedResponse: MockedResponse | undefined let mockedResponse
await handleRequest( await handleRequest(
mockedRequest, request.clone(),
requestId,
handlers.slice(0), handlers.slice(0),
{ {
onUnhandledRequest: () => { onUnhandledRequest: () => {
...@@ -91,19 +60,7 @@ export const test = base.extend<{ ...@@ -91,19 +60,7 @@ export const test = base.extend<{
} }
if (mockedResponse) { if (mockedResponse) {
const { return mockedResponse
status,
headers: responseHeaders,
body: responseBody,
delay,
} = mockedResponse
if (delay) {
await new Promise((resolve) => setTimeout(resolve, delay))
}
return new Response(responseBody, {
status,
headers: new Headers(responseHeaders),
})
} }
return 'abort' return 'abort'
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment