@mswjs/interceptors
Advanced tools
Comparing version 0.37.0 to 0.37.1
@@ -590,19 +590,35 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
queueMicrotask(() => { | ||
this.socket.dispatchEvent( | ||
bindEvent( | ||
/** | ||
* @note Setting this event's "target" to the | ||
* WebSocket override instance is important. | ||
* This way it can tell apart original incoming events | ||
* (must be forwarded to the transport) from the | ||
* mocked message events like the one below | ||
* (must be dispatched on the client instance). | ||
*/ | ||
this.socket, | ||
new MessageEvent("message", { | ||
data, | ||
origin: this.socket.url | ||
}) | ||
) | ||
); | ||
if (this.socket.readyState === this.socket.CLOSING || this.socket.readyState === this.socket.CLOSED) { | ||
return; | ||
} | ||
const dispatchEvent = () => { | ||
this.socket.dispatchEvent( | ||
bindEvent( | ||
/** | ||
* @note Setting this event's "target" to the | ||
* WebSocket override instance is important. | ||
* This way it can tell apart original incoming events | ||
* (must be forwarded to the transport) from the | ||
* mocked message events like the one below | ||
* (must be dispatched on the client instance). | ||
*/ | ||
this.socket, | ||
new MessageEvent("message", { | ||
data, | ||
origin: this.socket.url | ||
}) | ||
) | ||
); | ||
}; | ||
if (this.socket.readyState === this.socket.CONNECTING) { | ||
this.socket.addEventListener( | ||
"open", | ||
() => { | ||
dispatchEvent(); | ||
}, | ||
{ once: true } | ||
); | ||
} else { | ||
dispatchEvent(); | ||
} | ||
}); | ||
@@ -609,0 +625,0 @@ } |
{ | ||
"name": "@mswjs/interceptors", | ||
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.", | ||
"version": "0.37.0", | ||
"version": "0.37.1", | ||
"main": "./lib/node/index.js", | ||
@@ -6,0 +6,0 @@ "module": "./lib/node/index.mjs", |
@@ -67,19 +67,40 @@ import { bindEvent } from './utils/bindEvent' | ||
queueMicrotask(() => { | ||
this.socket.dispatchEvent( | ||
bindEvent( | ||
/** | ||
* @note Setting this event's "target" to the | ||
* WebSocket override instance is important. | ||
* This way it can tell apart original incoming events | ||
* (must be forwarded to the transport) from the | ||
* mocked message events like the one below | ||
* (must be dispatched on the client instance). | ||
*/ | ||
this.socket, | ||
new MessageEvent('message', { | ||
data, | ||
origin: this.socket.url, | ||
}) | ||
if ( | ||
this.socket.readyState === this.socket.CLOSING || | ||
this.socket.readyState === this.socket.CLOSED | ||
) { | ||
return | ||
} | ||
const dispatchEvent = () => { | ||
this.socket.dispatchEvent( | ||
bindEvent( | ||
/** | ||
* @note Setting this event's "target" to the | ||
* WebSocket override instance is important. | ||
* This way it can tell apart original incoming events | ||
* (must be forwarded to the transport) from the | ||
* mocked message events like the one below | ||
* (must be dispatched on the client instance). | ||
*/ | ||
this.socket, | ||
new MessageEvent('message', { | ||
data, | ||
origin: this.socket.url, | ||
}) | ||
) | ||
) | ||
) | ||
} | ||
if (this.socket.readyState === this.socket.CONNECTING) { | ||
this.socket.addEventListener( | ||
'open', | ||
() => { | ||
dispatchEvent() | ||
}, | ||
{ once: true } | ||
) | ||
} else { | ||
dispatchEvent() | ||
} | ||
}) | ||
@@ -86,0 +107,0 @@ } |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1398378
18604