Skip to content

Commit

Permalink
chore: bump supported msw version to v2.3.0
Browse files Browse the repository at this point in the history
Fixes #63338.
  • Loading branch information
kevva committed May 30, 2024
1 parent 50ca7f8 commit fa9aa51
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 188 deletions.
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
"lodash.curry": "4.1.1",
"lru-cache": "5.1.1",
"mini-css-extract-plugin": "2.4.4",
"msw": "1.3.0",
"msw": "2.3.0",
"nanoid": "3.1.32",
"native-url": "0.3.4",
"neo-async": "2.6.1",
Expand Down
55 changes: 6 additions & 49 deletions packages/next/src/experimental/testmode/playwright/msw.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { test as base, defineConfig } from './index'
import type { NextFixture } from './next-fixture'
// eslint-disable-next-line import/no-extraneous-dependencies
import {
type RequestHandler,
type MockedResponse,
MockedRequest,
handleRequest,
} from 'msw'
import { type RequestHandler, handleRequest } from 'msw'
// eslint-disable-next-line import/no-extraneous-dependencies
import { Emitter } from 'strict-event-emitter'

Expand All @@ -33,39 +28,13 @@ export const test = base.extend<{
const emitter = new Emitter()

next.onFetch(async (request) => {
const {
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,
})
const requestId = Math.random().toString(16).slice(2)
let isUnhandled = false
let isPassthrough = false
let mockedResponse: MockedResponse | undefined
let mockedResponse
await handleRequest(
mockedRequest,
request.clone(),
requestId,
handlers.slice(0),
{
onUnhandledRequest: () => {
Expand All @@ -91,19 +60,7 @@ export const test = base.extend<{
}

if (mockedResponse) {
const {
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 mockedResponse
}

return 'abort'
Expand Down
Loading

0 comments on commit fa9aa51

Please sign in to comment.