MCPcopy
hub / github.com/sindresorhus/got / createHttpTestServer

Function createHttpTestServer

test/helpers/create-http-test-server.ts:18–66  ·  view source on GitHub ↗
(options: HttpServerOptions = {})

Source from the content-addressed store, hash-verified

16} & Express;
17
18const createHttpTestServer = async (options: HttpServerOptions = {}): Promise<ExtendedHttpTestServer> => {
19 const server = express() as ExtendedHttpTestServer;
20 server.http = http.createServer(server as unknown as http.RequestListener);
21
22 server.set('etag', false);
23
24 if (options.bodyParser !== false) {
25 server.use(bodyParser.json({limit: '1mb', type: 'application/json', ...options.bodyParser}));
26 server.use(bodyParser.text({limit: '1mb', type: 'text/plain', ...options.bodyParser}));
27
28 server.use(bodyParser.urlencoded({
29 limit: '1mb',
30 type: 'application/x-www-form-urlencoded',
31 extended: true,
32 ...options.bodyParser,
33 }));
34
35 server.use(bodyParser.raw({limit: '1mb', type: 'application/octet-stream', ...options.bodyParser}));
36 }
37
38 await new Promise<void>((resolve, reject) => {
39 const onError = (error: Error): void => {
40 reject(error);
41 };
42
43 server.http.once('error', onError);
44 server.http.listen(0, () => {
45 server.http.off('error', onError);
46 resolve();
47 });
48 });
49 server.port = (server.http.address() as net.AddressInfo).port;
50 server.url = `http://localhost:${server.port}`;
51 server.hostname = 'localhost';
52
53 server.close = async () => new Promise<void>((resolve, reject) => {
54 server.http.closeAllConnections?.();
55 server.http.close(error => {
56 if (error) {
57 reject(error);
58 return;
59 }
60
61 resolve();
62 });
63 });
64
65 return server;
66};
67
68export default createHttpTestServer;

Callers 6

hooks.tsFile · 0.85
pagination.tsFile · 0.85
createRetryUrlServerFunction · 0.85
execFunction · 0.85

Calls 2

setMethod · 0.80
jsonMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…