Skip to content

Commit b80e949

Browse files
KhafraDevtargos
authored andcommitted
lib: make fetch sync and return a Promise
update test PR-URL: #49936 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 01b0152 commit b80e949

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/internal/process/pre_execution.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ function setupUndici() {
292292
}
293293

294294
if (!getOptionValue('--no-experimental-fetch')) {
295-
async function fetch(input, init = undefined) {
295+
// Fetch is meant to return a Promise, but not be async.
296+
function fetch(input, init = undefined) {
296297
return lazyUndici().fetch(input, init);
297298
}
298299

test/parallel/test-fetch.mjs

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ assert.strictEqual(typeof globalThis.Headers, 'function');
1010
assert.strictEqual(typeof globalThis.Request, 'function');
1111
assert.strictEqual(typeof globalThis.Response, 'function');
1212

13+
{
14+
const asyncFunction = async function() {}.constructor;
15+
16+
assert.ok(!(fetch instanceof asyncFunction));
17+
assert.notStrictEqual(Reflect.getPrototypeOf(fetch), Reflect.getPrototypeOf(async function() {}));
18+
assert.strictEqual(Reflect.getPrototypeOf(fetch), Reflect.getPrototypeOf(function() {}));
19+
}
20+
1321
const server = http.createServer(common.mustCall((req, res) => {
1422
res.end('Hello world');
1523
}));

0 commit comments

Comments
 (0)