-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
Error: Error: connect ECONNREFUSED 127.0.0.1:80 #494
Comments
@karuppiah7890 In your situation, I would have updated Also, this does not seem to be related to |
Ah okay. It's weird yarn upgrade didn't upgrade it. I thought that would have done it. And the logs mention about a connection and about node request interceptor. But yeah, I'll dig in and get back |
@karuppiah7890 it would be great if you can share a reproduction. |
Makes sense. I'll try to do that too with a demo setup 👍 |
Just a question, do you have a single instance of |
@marcosvega91 Ah yes. We have multiple instances 🙈 |
I was thinking a bit about that too - how jest runs tests in parallel (across test files) with server running like that (same port and all). I need to dig a bit more and understand things 😅 EDIT: I forgot that it's still an interception and no actual server is running. 🙈 So, I guess running multiple "servers" is not a problem (no port conflicting issues etc) |
I was also thinking about merging all the related servers with just one server implementation - since almost all of them work in the same way with same data. It's just that I need to see how to do it. The current idea is to at least reuse the request handler (merge all request handler code, remove duplicates) and run server with that in the beforeAll setup |
UPDATE: I upgraded the version, but I still saw the connection refused errors in the logs |
I asked you that because we have an issue with this approach. #474 Monkey patched modules are shared between tests, so if one test |
Thanks for the explanation @marcosvega91 ! And I think I understand why the current features are not supporting this, so need to be sorry :) I remember reading how it's good to have one implementation (the happy path) of the server and to run the server in the Jest Test setup, before any of the tests run and to have any specific changes needed for any tests (like bad request, error cases etc) in the particular tests using the programmatic API. I'll try to see if we can do that, and I'll also have an eye on #474 . Should I close this issue then? Assuming that this is just a duplicate or a side effect of what #474 describes? |
Yes we can close this and use the other issue. Thanks and sorry for your trouble 😞 |
No worries! |
I updated the node to
handlers.ts:
serverTests.ts:
I got this error:
I log the url called while testing and it's |
Hi @slim-hmidi your configuration seams right :) , Could I ask you to replace beforeAll(() => {
server.listen();
}); with beforeAll(() => {
server.listen({
onUnhandledRequest: 'warn',
})
}); and check then your console? Thanks, let me know |
@marcosvega91 I got the warning concerning the handlers for the api that are not implemented like:
|
The api that you are handled on your code is the one that has warned ? If not your are calling APIs in your code that are not handled by MSW. If you have missed them you can add as you have done for the other api. |
the api I handled does not been warned |
So the problem is that you have added only one handler while in your application you are making this requests. |
you are right. I added the different handlers mentioned by the warn and it works well now. thanks a lot for your time and your help. |
You're welcome :). If you need further help we are happy to help :) |
Hello there, I am facing the exact same error as @karuppiah7890 with whom I share the same msw config. I have an axios service that doesn't get mocked properly. Thanks to @marcosvega91 's tip, I found that URLs were not resolved well. The base url in my axios.create is not taken into account, that's why I end up with the error aforementionnend. Here is the full warning
Followed by this error
EDIT 1: Here are the related functions, // service
const postman = axios.create({
baseURL: X_SERVICE_BASE_URL,
});
export function getX(): Promise<X[] | undefined> {
return postman.get(GET_X_ENDPOINT)
.then((res: AxiosResponse<any[]>) => {
return res.data.map(
x=> doY(x),
);
},
); // test
test.only('should get a all X', async () => {
const result = await api.getX();
expect(result).toHaveLength(9);
},
); // handlers
export const handlers = [
rest.post(X_SERVICE_BASE_URL + CREATE_X_ENDPOINT, (req: RestRequest<any, any>, res: ResponseComposition, ctx: RestContext) => {
return res(
ctx.status(201),
ctx.json(fakeData),
);
},
), I am using
|
You need to make it being taken into account manually. The URL you provide to the handler contains variables that resolve to
Log out those variables and track why they are undefined. Perhaps you are not loading the environmental variables when running tests? Not a library issue. |
You're right @kettanaito ! added Thanks! |
Environment
Request handlers
Actual request
Current behavior
A lot of
Error: Error: connect ECONNREFUSED 127.0.0.1:80
in the console logs when running my tests. But the testspass most of the time. Sometimes there's failures - for example timeouts. Not sure if it's related to this though, just
saying.
Expected behavior
No errors about connection refused in the console logs - as it looks like something's wrong, but I don't know what's wrong
and the tests pass too. :/
Screenshots
I'll paste some logs instead
Something to add is, we do have some tests that get rid of components abruptly when they are in the middle of a
fetch
call (my assumption), which leads to a lot of the below logsThe text was updated successfully, but these errors were encountered: