-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
API requests in tests to https://localhost doesn't work with test:node but it works with test:browser #30215
Comments
@danielszaniszlo from internet search I see sometimes NodeJs has problem accessing localhost due to DNS query use IPv6 first. Does |
The behavior is strange. If I change the address to [vitest] RestError: self-signed certificate
[vitest] ❯ ClientRequest.<anonymous> ../../core/core-rest-pipeline/src/nodeHttpClient.ts:223:11
[vitest] ❯ Object.onceWrapper node:events:632:26
[vitest] ❯ ClientRequest.emit node:events:517:28
[vitest] ❯ TLSSocket.socketErrorListener node:_http_client:501:9
[vitest] ❯ TLSSocket.emit node:events:517:28 Browser also returns an error [vitest] RestError: Error sending request: Failed to fetch
[vitest] ❯ getError ../../core/core-rest-pipeline/dist/browser/fetchHttpClient.js:192:11
[vitest] 191| * however they are not yet supported by all browsers i.e Firefox
[vitest] 192| */
[vitest] 193| function buildBodyStream(readableStream, options = {}) {
[vitest] | ^
[vitest] 194| let loadedBytes = 0;
[vitest] 195| const { onProgress, onEnd } = options;
[vitest] ❯ FetchHttpClient.sendRequest ../../core/core-rest-pipeline/dist/browser/fetchHttpClient.js:48:12
[vitest] ❯ Object.sendRequest ../../core/core-rest-pipeline/dist/browser/policies/retryPolicy.js:57:21
[vitest] ❯ Object.sendRequest ../../core/core-rest-pipeline/dist/browser/policies/bearerTokenAuthenticationPolicy.js:189:19
[vitest] ❯ sendRequest ../../core/core-client-rest/dist/browser/sendRequest.js:39:19 If I use |
The nodejs error may be due to missing certificate. Would setting NODE_TLS_REJECT_UNAUTHORIZED env var to 0 helps? and for "localhost" some post suggests to call dns.setDefaultResultOrder('ipv4first') |
Hi @danielszaniszlo. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue. |
Hi @danielszaniszlo, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you! |
vitest.browser.shared.config.ts
Describe the bug
I have a local setup where our service runs on https://localhost/. I have written test cases that make REST API calls to this service.
These tests fail when executed in a Node.js environment, but they pass when run in a browser environment. If I use a real endpoint not localhost both node and browser test cases are passing.
Client configuration:
API call:
The error I get if I use
dev-tool run test:vitest
The same test with the same setup passes if I use
dev-tool run test:vitest --browser
To Reproduce
Steps to reproduce the behavior:
dev-tool run test:vitest
.Expected behavior
The test cases should have the same behavior on both node and browser environments
Screenshots
N/A
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: