MCPcopy
hub / github.com/axios/axios / createTransportCapture

Function createTransportCapture

tests/smoke/esm/tests/instance.smoke.test.js:7–40  ·  view source on GitHub ↗
(responseBody)

Source from the content-addressed store, hash-verified

5import axios from 'axios';
6
7const createTransportCapture = (responseBody) => {
8 const calls = [];
9
10 const transport = {
11 request(options, onResponse) {
12 calls.push(options);
13
14 const req = new EventEmitter();
15 req.destroyed = false;
16 req.setTimeout = () => {};
17 req.write = () => true;
18 req.destroy = () => {
19 req.destroyed = true;
20 };
21 req.close = req.destroy;
22 req.end = () => {
23 const res = new PassThrough();
24 res.statusCode = 200;
25 res.statusMessage = 'OK';
26 res.headers = { 'content-type': 'application/json' };
27 res.req = req;
28 onResponse(res);
29 res.end(responseBody ? responseBody : '{"ok":true}');
30 };
31
32 return req;
33 },
34 };
35
36 return {
37 transport,
38 getCalls: () => calls,
39 };
40};
41
42describe('instance compat (dist export only)', () => {
43 it('creates isolated instances with separate defaults', async () => {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected