-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
Always 404 / Not Intercepted on homepage set CRA #2274
Comments
Hi, @chiahao. Thanks for reporting this. Can you please follow the Debugging runbook and let me know how far you got? |
Hi, @kettanaito . Thanks for so fast response. Modified import { setupWorker } from "msw/browser";
import { handlers } from "./handler";
export const worker = setupWorker(...handlers);
worker.events.on('request:start', async ({ request }) => {
// Read the request body as text for every request
// that occurs in your application.
const payload = await request.clone().text()
});
worker.events.on('request:start', ({ request }) => {
console.log('Outgoing:', request.method, request.url)
}); Test the version where the But still, once |
Hi, @kettanaito , does this test right? |
Can you please await the worker.start() promise? That doesn't look right. |
Hi, @kettanaito , import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
async function enableMocking() {
if (process.env.NODE_ENV !== 'development') {
return;
}
const packageJson = await import("../package.json");
const { worker } = await import("./mocks/browser");
// `worker.start()` returns a Promise that resolves
// once the Service Worker is up and ready to intercept requests.
await worker.start({
serviceWorker: {
// Provide a custom worker script URL, taking
// the "homepage" into account.
url: `${packageJson.homepage}/mockServiceWorker.js`,
},
});
console.log(worker.listHandlers());
}
enableMocking().then(() => {
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
}); still no luck with Does this mean MSW not support custom project path? |
Prerequisites
Environment check
msw
versionBrowsers
Firefox, Safari
Reproduction repository
https://github.com/chiahao/mymswtestapp.git
Reproduction steps
Describe the bug
create-react-app with homepage setted causes MSW not to mock
Environment
react: "^18.3.1"
msw: "^2.4.4"
nodejs: 21.1.0
To Reproduce
in firefox, send request
http://localhost:3000/api/code/NAT/1
can be succefully intercepted.Add
"homepage": "myPage",
topackage.json
.Modify
mytestapp/index.js
:npm start
still can start server, and show[MSW] Mocking enabled.
.But requests won't intercepted.
Current behavior
Firefox get this:
Cannot POST /myPage/api/code/NAT/1
Expected behavior
"data": [
{"CODE": "11", "DESCR": "UNIT1"},
{"CODE": "22", "DESCR": "UNIT2"}
]
The text was updated successfully, but these errors were encountered: