Skip to content

Commit

Permalink
lib: make fetch sync and return a Promise
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
KhafraDev authored Sep 30, 2023
1 parent 6c9625d commit fa250fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ function setupUndici() {
}

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

Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-fetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ assert.strictEqual(typeof globalThis.Headers, 'function');
assert.strictEqual(typeof globalThis.Request, 'function');
assert.strictEqual(typeof globalThis.Response, 'function');

{
const asyncFunction = async function() {}.constructor;

assert.ok(!(fetch instanceof asyncFunction));
assert.notStrictEqual(Reflect.getPrototypeOf(fetch), Reflect.getPrototypeOf(async function() {}));
assert.strictEqual(Reflect.getPrototypeOf(fetch), Reflect.getPrototypeOf(function() {}));
}

const server = http.createServer(common.mustCall((req, res) => {
res.end('Hello world');
}));
Expand Down

0 comments on commit fa250fd

Please sign in to comment.