mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
fa250fdec1
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>
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import * as common from '../common/index.mjs';
|
|
|
|
import assert from 'assert';
|
|
import events from 'events';
|
|
import http from 'http';
|
|
|
|
assert.strictEqual(typeof globalThis.fetch, 'function');
|
|
assert.strictEqual(typeof globalThis.FormData, 'function');
|
|
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');
|
|
}));
|
|
server.listen(0);
|
|
await events.once(server, 'listening');
|
|
const port = server.address().port;
|
|
|
|
const response = await fetch(`http://localhost:${port}`);
|
|
|
|
assert(response instanceof Response);
|
|
assert.strictEqual(response.status, 200);
|
|
assert.strictEqual(response.statusText, 'OK');
|
|
const body = await response.text();
|
|
assert.strictEqual(body, 'Hello world');
|
|
|
|
server.close();
|