mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
lib: make fetch sync and return a Promise
update test PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
01b01527d7
commit
b80e9497f3
2 files changed
+10
-1
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}));
|
||||
|
||||
Reference in new issue
Block a user