Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading