Skip to content

Commit cdaf757

Browse files
KhafraDevGeoffreyBooth
authored andcommitted
lib: make fetch sync and return a Promise
update test PR-URL: nodejs#49936 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent c705d70 commit cdaf757

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
@@ -302,7 +302,8 @@ function setupUndici() {
302302
}
303303

304304
if (!getOptionValue('--no-experimental-fetch')) {
305-
async function fetch(input, init = undefined) {
305+
// Fetch is meant to return a Promise, but not be async.
306+
function fetch(input, init = undefined) {
306307
return lazyUndici().fetch(input, init);
307308
}
308309

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)