-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
Support Node.js v18 #1388
Comments
Hey! I actually have a PR for this. Well, I have one simple PR, and then a series of more robust PRs. Let me summarize... Background
Quick fix
Robust fix
SummaryTo fully migrate to Node 18, we need to open/merge the following PRs:
Note: These PRs are not as complicated/dangerous as they look. Most of the complexity only affects development/CI environment, and there are hardly any user-facing changes. And the high count of files changed is due to changing an import path to use the patched In the meantime, as a "quick fix," we could make the two-line change described above (milesforks#1). If @kettanaito is okay with that approach, I can rebase my PR and open it here, or he can just make the change himself, since it's literally two lines. Blockers
Next stepsI spent most of last week on this (thanks to ipv6...), so I would love to get this merged! Please let me know how you'd like to coordinate the order of merges here, and if you have any input on that last memory leak blocking my PR from being ready. |
@milesrichardson has put is perfectly. There's no Node 18 support at this moment but you can learn more about the strategy to support it above. I'm slowly getting through those pull requests to have it all in place. Be patient. |
The preparatory work on the Node 18 support should be done. Both |
What is left for this? Node 18.12.0 is now the LTS and this is preventing us from updating. |
I would also like to understand the status of this. I want to move my testing framework to Vitest from Jest. However, Vitest is unstable on anything less than Node 18. But I can't yet move to Node 18 (or Vitest) until MSW supports Node 18. |
We also have issues with it in Node 18. Any updates? |
Are there viable alternatives to MSW that are Node18 compatible? |
I was actually able to solve it using |
also works for node 19. thanks ❤️ |
Can you point to an example of what it means to use |
use the fetch from this library instead of the native one from node import { setupServer, rest } from "msw/node";
import fetch from "cross-fetch"; // <-- this is what it means
// application code
const myFetch = async () => {
const response = await fetch("https://some-url.com");
return response.json();
};
// test code
const server = setupServer(
rest.get("https://some-url.com", (req, res, ctx) =>
res(ctx.status(200), ctx.json({ someKey: "some value" }))
)
);
test("msw", async () => {
server.listen();
expect(await myFetch()).toEqual({ someKey: "some value" });
}); |
Thank you, @tobilen. Ill give this a try. |
For those looking for another workaround on Node 18 until this issue is completed, you can do this in your package.json: "scripts": {
"dev": "NODE_OPTIONS='--no-experimental-fetch' node server.js", // or any script to start your server
...
} Adding this Node flag will use the old Node fetch (fetch from node version < 18) |
UpdateMSW v2.0 will drop Node.js < 18 and will ship with Node.js 18+ support. This also includes proper ESM support that people have been requesting for quite some time now. |
Do you have an ETA please? 🙂 |
@ValentinH, as soon as it's sufficiently tested. You can contribute to that by giving the next version of MSW a try. I'd aim for sometime in late summer as I won't have much availability in the upcoming months. You can adopt |
Thanks for the answer. I missed this info, I'll give the next version a try next week then 🤞 |
Thank you for the great msw library and thank you @yairkukielkazunzunegui for solving my problem. Upgrated our cra react project to vite and vitest. But these tests continue to fail on Jenkins. This issue here helped me to figure the problem: The issue was fixed by adding the --no-experimental-fetch like this for integration test command in package.json: Here are my vitest.integrationtest.config.js and setupIntegrationTests.ts. Just in case someone is wondering. vitest.integrationtest.config.js
setupIntegrationTests.ts
|
UpdateNode.js 18 support has been a gigantic effort and it's finally complete! 🎉 MSW officially supports Node.js 18+ in its There's no intention of bringing Node.js 18 support to the 1.x version of the library due to the amount of refactoring required (which has been already done in |
Released: v2.0.0 🎉This has been released in v2.0.0! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Prerequisites
Environment check
msw
versionNode.js version
v18.8.0
Reproduction repository
https://github.com/ericmasiello/msw-node-18
Reproduction steps
npm ci
npm run test
Note that the tests pass but they actually should not. I'm using a
toMatchInlineSnapshot()
. That data snapshotted is the live data coming from real Pokemon API. what should be snapshotted is the mocked response I created infoo.test.ts
Current behavior
The tests pass because the msw is not intercepting the response. Therefore, the
toMatchInlineSnapshot
matches live data from the API.Expected behavior
The tests should fail because the data should match the mocked response in
foo.test.ts
.The text was updated successfully, but these errors were encountered: