• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import * as common from '../common/index.mjs';
2
3import assert from 'assert';
4import events from 'events';
5import http from 'http';
6
7assert.strictEqual(typeof globalThis.fetch, 'function');
8assert.strictEqual(typeof globalThis.FormData, 'function');
9assert.strictEqual(typeof globalThis.Headers, 'function');
10assert.strictEqual(typeof globalThis.Request, 'function');
11assert.strictEqual(typeof globalThis.Response, 'function');
12
13const server = http.createServer(common.mustCall((req, res) => {
14  res.end('Hello world');
15}));
16server.listen(0);
17await events.once(server, 'listening');
18const port = server.address().port;
19
20const response = await fetch(`http://localhost:${port}`);
21
22assert(response instanceof Response);
23assert.strictEqual(response.status, 200);
24assert.strictEqual(response.statusText, 'OK');
25const body = await response.text();
26assert.strictEqual(body, 'Hello world');
27
28server.close();
29