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
Display request log once the response is signaled by the worker #1343
Comments
Released: v0.47.1 🎉This has been released in v0.47.1! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
I’ve noticed an increase in the amount of logged “[MSW]” messages due to this change (implemented in #1392). Entries like “[MSW] 12:23:53 GET http://localhost:8000/path (200 OK)” now appear multiple times despite the related request only being made once. I also started getting the following warning (see also #785):
Is this supposed to work this way? |
@kleinfreund, thanks for reporting this! No, that sounds like an issue. I think I've noticed this happening yesterday as well. Please, do you have a repo example to reproduce this?
This happens in Node, right? The introduced change didn't affect Node. |
@kettanaito Hey.
I don’t have a minimal reproduction, but a branch that I’m working on where this occurs. Though just now I’m having trouble reproducing this again. On https://github.com/kleinfreund/kuma-gui/tree/feat/rework-dataplanes-view, I have currently pinned msw to 1.47.0. Yesterday, unpinning the version and updating to 1.47.2 and starting the application (yarn install, yarn run dev) made the issue visible, but that doesn't occur anymore. I have no idea why.
Yes, I think? I’m working on a Vue app using Vite as the general tooling wrapper. To use Vite, I did make sure that my application code never imports a file that imports msw/node. The mock server is set-up using Let me keep msw 1.47.2 installed and continue development and see if it re-appears with further use. Previous content, unrelated to this issue: I’m running into an unrelated issue with the headers-polyfill. Error
Fixed in: mswjs/interceptors#286 |
@kettanaito Regarding the headers-polyfill error, I think that project’s package.json file is missing the module specifier definitions when using package.json diff{
"name": "headers-polyfill",
"version": "3.1.0",
"description": "A native \"Headers\" class polyfill.",
"main": "./lib/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"require": "./lib/index.js",
"default": "./lib/esm/index.js"
},
+ "./lib": {
+ "types": "./lib/index.d.ts",
+ "require": "./lib/index.js",
+ "default": "./lib/esm/index.js"
+ }
},
"repository": "https://github.com/mswjs/headers-polyfill",
"author": "Artem Zakharchenko",
"license": "MIT",
"scripts": {
"start": "tsup --watch",
"clean": "rimraf lib",
"build": "yarn clean && tsup",
"test": "jest",
"release": "release publish",
"prepublishOnly": "yarn test && yarn build"
},
"files": [
"lib",
"README.md"
],
"devDependencies": {
"@ossjs/release": "^0.3.0",
"@types/jest": "^28.1.4",
"jest": "^28.1.2",
"jest-environment-jsdom": "^28.1.2",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.5",
"tsup": "^6.2.3",
"typescript": "4.3.2"
}
} |
@kleinfreund, you're right! But I'd fix it the other way around: we should use direct imports now instead of |
@kettanaito Yep, expanding the exports like I did was just a means of verifying what’s actually missing. Using the bare headers-polyfill module specifier seems better because adding /lib would just be redundant now. |
I’ve managed to reproduce the issue again (I did update msw to the latest version and manually patched one msw instance of importing headers-polyfill/lib to get the latest dependencies to work) so here is a more complete trace:
I think it took a bit of navigating around in the app to start seeing the increase in MSW output and eventually the warning. I feel like more listeners of something are registered than are being cleaned up. |
@kleinfreund I've fixed this in |
I can confim @kleinfreund ! I still get "MaxListenersExceededWarning" ( Some side Note: I switched from 0.43.0 to 0.47.3 and now new additional strange behavior appeared. The logs in the devTools are displayed (logged) multiple/many/>=10x times in the browser. In 0.43.0 everything works fine. DevTools Log
|
@SerkanSipahi I'm pretty sure that both symptoms are caused by the same issue. @kettanaito Do you want a new issue being reported for this? I'm happy to do so. |
I see, you are right!
|
@kleinfreund, yes please! It'd help other people discover it. Thank you. |
@kettanaito Not a problem. I’ve filed an issue for this here: #1411 |
Scope
Improves an existing behavior
Compatibility
Feature description
Current behavior
Right now MSW prints the
[MSW] /resource 200 OK
request log immediately once the mocked response has been sent to the worker.Proposed behavior
Instead, print the request log once the worker reports the response event. This way if the response has some delay, or took some time to process for other reasons, the developer would know that, translating the moment when the request log has appeared to the moment when the response has been truly handled by the worker.
Links
msw/src/setupWorker/start/createRequestListener.ts
Lines 66 to 80 in 6c6e119
This is the wrong place to call
handler.log()
. We should migrate from this and reconsider ifonMockedResponseSent
is used for any other purpose.We may also consider rewriting
onMockedResponseSent
to actually await the response event from the worker and then dispatching its callback. For example,handleRequest()
acceptscontext.emitter
as an input, so it can create a listener on the response events:The text was updated successfully, but these errors were encountered: