-
Notifications
You must be signed in to change notification settings - Fork 1
fix(fetch): use current global fetch instead of cached one when env f… #2
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
base: pr_022_before
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -489,5 +489,32 @@ describe('supports fetch with nodejs', function () { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.strictEqual(data, 'OK'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('should use current global fetch when env fetch is not specified', async() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const globalFetch = fetch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fetch = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foo: '1' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text: async () => 'global' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server = await startHTTPServer((req, res) => res.end('OK')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const {data} = await fetchAxios.get('/', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| env: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fetch: undefined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.strictEqual(data, 'global'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fetch = globalFetch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+493
to
+517
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's examine the exact file and lines in question
wc -l test/unit/adapters/fetch.jsRepository: Signal65/axios-CodeRabbit Length of output: 100 🏁 Script executed: # Read the specific lines mentioned in the review (493-517)
sed -n '493,517p' test/unit/adapters/fetch.jsRepository: Signal65/axios-CodeRabbit Length of output: 649 🏁 Script executed: # Search for other global fetch stubs that might need the same treatment
rg -n -C2 '\bfetch\s*=' test/unit --max-count 20Repository: Signal65/axios-CodeRabbit Length of output: 598 🏁 Script executed: # Check if there's a eslint/biome configuration file to confirm the noGlobalAssign rule
fd -e .biomerc -e biome.json -e .eslintrc -e .eslintignore 2>/dev/null | head -5Repository: Signal65/axios-CodeRabbit Length of output: 51 🏁 Script executed: # Check for biome or eslint config in the root directory
ls -la | grep -E '(biome|eslint)'Repository: Signal65/axios-CodeRabbit Length of output: 199 🏁 Script executed: # Check if biome is configured in package.json
cat package.json | grep -A10 -B2 'biome'Repository: Signal65/axios-CodeRabbit Length of output: 51 🏁 Script executed: # Search the entire codebase for other uses of globalThis.fetch
rg 'globalThis\.fetch' --max-count 10Repository: Signal65/axios-CodeRabbit Length of output: 51 🏁 Script executed: # Check if there are any other test files using globalThis for stubbing
rg 'globalThis\s*\.' test/ --max-count 15Repository: Signal65/axios-CodeRabbit Length of output: 51 🏁 Script executed: # Read the biome.json file to check noGlobalAssign configuration
cat biome.jsonRepository: Signal65/axios-CodeRabbit Length of output: 1844 🏁 Script executed: # Also check the .eslintrc.cjs file
cat .eslintrc.cjsRepository: Signal65/axios-CodeRabbit Length of output: 317 🏁 Script executed: # Final verification: check if there are any other fetch reassignments in the entire test directory
rg 'fetch\s*=' test/ --type js -B2 -A2Repository: Signal65/axios-CodeRabbit Length of output: 558 Use 🛠️ Suggested fix- const globalFetch = fetch;
-
- fetch = async () => {
+ const globalFetch = globalThis.fetch;
+
+ globalThis.fetch = async () => {
return {
headers: {
foo: '1'
},
text: async () => 'global'
}
};
@@
- fetch = globalFetch;
+ globalThis.fetch = globalFetch;
}📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (2.3.13)[error] 496-496: A global variable should not be reassigned. Assigning to a global variable can override essential functionality. (lint/suspicious/noGlobalAssign) [error] 516-516: A global variable should not be reassigned. Assigning to a global variable can override essential functionality. (lint/suspicious/noGlobalAssign) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Signal65/axios-CodeRabbit
Length of output: 90
🏁 Script executed:
head -n 300 lib/adapters/fetch.js | tail -n 50Repository: Signal65/axios-CodeRabbit
Length of output: 1138
🏁 Script executed:
rg -n -C2 '\bgetFetch\s*\('Repository: Signal65/axios-CodeRabbit
Length of output: 255
🏁 Script executed:
rg -n 'getFetch' --type jsRepository: Signal65/axios-CodeRabbit
Length of output: 246
🏁 Script executed:
rg -n 'getFetch\s*\(' --type js -A 5Repository: Signal65/axios-CodeRabbit
Length of output: 199
🏁 Script executed:
Repository: Signal65/axios-CodeRabbit
Length of output: 2142
Guard against
config.envbeing undefined.When
getFetchis called with aconfigobject (line 60-61 inlib/adapters/adapters.js), the current code at line 265 can setenvtoundefinedifconfig.envis missing or falsy. This causes line 266 destructuring to throw aTypeError. The suggested fix ensuresenvalways defaults to an object:✅ Safer defaulting
🤖 Prompt for AI Agents