Open danielszaniszlo opened 3 days ago
@danielszaniszlo from internet search I see sometimes NodeJs has problem accessing localhost due to DNS query use IPv6 first. Does 127.0.0.1
work?
127.0.0.1
The behavior is strange. If I change the address to 127.0.0.1
Node returns a different error DEPTH_ZERO_SELF_SIGNED_CERT
:
[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 REQUEST_SEND_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 localhost
browser works fine but node still fails.
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')
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.