2022-02-21 13:34:13 +01:00
|
|
|
import * as common from '../common/index.mjs';
|
2022-02-01 09:17:50 +01:00
|
|
|
|
|
|
|
import assert from 'assert';
|
|
|
|
import events from 'events';
|
|
|
|
import http from 'http';
|
|
|
|
|
|
|
|
assert.strictEqual(typeof globalThis.fetch, 'function');
|
2022-02-18 16:46:32 +01:00
|
|
|
assert.strictEqual(typeof globalThis.FormData, 'function');
|
2022-02-01 09:17:50 +01:00
|
|
|
assert.strictEqual(typeof globalThis.Headers, 'function');
|
|
|
|
assert.strictEqual(typeof globalThis.Request, 'function');
|
|
|
|
assert.strictEqual(typeof globalThis.Response, 'function');
|
|
|
|
|
2023-09-30 20:48:36 +02:00
|
|
|
{
|
|
|
|
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() {}));
|
|
|
|
}
|
|
|
|
|
2022-11-05 16:15:07 +01:00
|
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
2022-02-01 09:17:50 +01:00
|
|
|
res.end('Hello world');
|
2022-11-05 16:15:07 +01:00
|
|
|
}));
|
2022-02-01 09:17:50 +01:00
|
|
|
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();
|