Socket
Socket
Sign inDemoInstall

msw

Package Overview
Dependencies
Maintainers
1
Versions
261
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

msw - npm Package Compare versions

Comparing version 2.2.5 to 2.2.6

7

lib/core/bypass.js

@@ -26,3 +26,8 @@ "use strict";

function bypass(input, init) {
const request = input instanceof Request ? input : new Request(input, init);
const request = new Request(
// If given a Request instance, clone it not to exhaust
// the original request's body.
input instanceof Request ? input.clone() : input,
init
);
(0, import_outvariant.invariant)(

@@ -29,0 +34,0 @@ !request.bodyUsed,

13

lib/mockServiceWorker.js

@@ -11,4 +11,4 @@ /* eslint-disable */

const PACKAGE_VERSION = '2.2.5'
const INTEGRITY_CHECKSUM = '5db7e6e8385dc04e017ac4823e0e9b29'
const PACKAGE_VERSION = '2.2.6'
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')

@@ -210,9 +210,2 @@ const activeClientIds = new Set()

// Bypass requests with the explicit bypass header.
// Such requests can be issued by "ctx.fetch()".
const mswIntention = request.headers.get('x-msw-intention')
if (['bypass', 'passthrough'].includes(mswIntention)) {
return passthrough()
}
// Notify the client that a request has been intercepted.

@@ -249,3 +242,3 @@ const requestBuffer = await request.arrayBuffer()

case 'MOCK_NOT_FOUND': {
case 'PASSTHROUGH': {
return passthrough()

@@ -252,0 +245,0 @@ }

{
"name": "msw",
"version": "2.2.5",
"version": "2.2.6",
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",

@@ -5,0 +5,0 @@ "main": "./lib/core/index.js",

@@ -51,3 +51,3 @@ import {

onPassthroughResponse() {
messageChannel.postMessage('NOT_FOUND')
messageChannel.postMessage('PASSTHROUGH')
},

@@ -54,0 +54,0 @@ async onMockedResponse(response, { handler, parsedResult }) {

@@ -24,2 +24,4 @@ import type {

console.log('RESPONSE LISTENER', responseJson, context.requests)
/**

@@ -26,0 +28,0 @@ * CORS requests with `mode: "no-cors"` result in "opaque" responses.

@@ -19,3 +19,3 @@ import {

]
NOT_FOUND: []
PASSTHROUGH: []
}

@@ -22,0 +22,0 @@

@@ -48,1 +48,23 @@ /**

})
it('allows modifying the bypassed request instance', async () => {
const original = new Request('http://localhost/resource', {
method: 'POST',
body: 'hello world',
})
const request = bypass(original, {
method: 'PUT',
headers: { 'x-modified-header': 'yes' },
})
expect(request.method).toBe('PUT')
expect(Object.fromEntries(request.headers.entries())).toEqual({
'x-msw-intention': 'bypass',
'x-modified-header': 'yes',
})
expect(original.bodyUsed).toBe(false)
expect(request.bodyUsed).toBe(false)
expect(await request.text()).toBe('hello world')
expect(original.bodyUsed).toBe(false)
})

@@ -18,3 +18,11 @@ import { invariant } from 'outvariant'

export function bypass(input: BypassRequestInput, init?: RequestInit): Request {
const request = input instanceof Request ? input : new Request(input, init)
// Always create a new Request instance.
// This way, the "init" modifications will propagate
// to the bypass request instance automatically.
const request = new Request(
// If given a Request instance, clone it not to exhaust
// the original request's body.
input instanceof Request ? input.clone() : input,
init,
)

@@ -21,0 +29,0 @@ invariant(

@@ -55,3 +55,3 @@ import { until } from '@open-draft/until'

// Perform bypassed requests (i.e. issued via "ctx.fetch") as-is.
// Perform bypassed requests (i.e. wrapped in "bypass()") as-is.
if (request.headers.get('x-msw-intention') === 'bypass') {

@@ -58,0 +58,0 @@ emitter.emit('request:end', { request, requestId })

@@ -209,9 +209,2 @@ /* eslint-disable */

// Bypass requests with the explicit bypass header.
// Such requests can be issued by "ctx.fetch()".
const mswIntention = request.headers.get('x-msw-intention')
if (['bypass', 'passthrough'].includes(mswIntention)) {
return passthrough()
}
// Notify the client that a request has been intercepted.

@@ -248,3 +241,3 @@ const requestBuffer = await request.arrayBuffer()

case 'MOCK_NOT_FOUND': {
case 'PASSTHROUGH': {
return passthrough()

@@ -251,0 +244,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc