Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/utils/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ describe('fetch utils', () => {
it('should fall back to no_proxy if NO_PROXY is not set', () => {
const proxyUrl = 'http://proxy.example.com';
const noProxyValue = 'localhost,127.0.0.1';
vi.stubEnv('NO_PROXY', undefined);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

According to the Repository Style Guide (Testing Conventions, lines 87-88), to "unset" an environment variable, we must use an empty string vi.stubEnv('NAME', '') instead of undefined.

However, simply changing this to vi.stubEnv('NO_PROXY', '') will cause this test to fail because the implementation in packages/core/src/utils/fetch.ts uses the nullish coalescing operator (??):

const noProxy = (
  process.env['NO_PROXY'] ??
  process.env['no_proxy'] ??
  ''
)?.trim();

Since '' is not nullish, it won't fall back to no_proxy.

To fix this and adhere to the style guide, and to ensure we trim the optional string and use the fallback if the result is empty (to avoid whitespace-only strings), please update the implementation in packages/core/src/utils/fetch.ts to:

const noProxy = 
  process.env['NO_PROXY']?.trim() ||
  process.env['no_proxy']?.trim() ||
  '';

And then update this test to use vi.stubEnv('NO_PROXY', '').

      vi.stubEnv('NO_PROXY', '');
References
  1. To "unset" an environment variable, use an empty string vi.stubEnv('NAME', ''). (link)
  2. When using an optional string with a fallback value, trim the optional string and use the fallback if the result is empty to avoid uninformative messages from whitespace-only strings.

vi.stubEnv('no_proxy', noProxyValue);

setGlobalProxy(proxyUrl);
Expand Down
Loading