Skip to content

Commit e79c73c

Browse files
committed
lib: make fetch sync and return a Promise
update test
1 parent 3f1936f commit e79c73c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/internal/process/pre_execution.js

Lines changed: 2 additions & 1 deletion
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

Lines changed: 8 additions & 0 deletions
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)