mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
d905b7598d
* chore: port karma tests * chore: port karma tests * chore: port karma tests * chore: tests * chore: tests * chore: tests * chore: fix issues with port collisions * refactor: utils tests * refactor: utils tests * refactor: utils tests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: ci * chore: install pw deps * chore: fixx ai feedback * chore: wip compatability tests * chore: wip compatability tests * chore: wip compatability tests * refactor: wip smoke * chore: smoke test run * chore: update unzip * chore: update testing * chore: update testing * chore: update testing * chore: update testing * chore: update testing * chore: skip tests that cannot run on node 16 and lower * chore: fix 16x under tests * chore: rest of tests * fix: functions and runs * feat: added tests for esm smoke * feat: added smoke * chore: ignore ai gen plans * chore: ci fixes * chore: fix small p2s
106 lines
2.7 KiB
JavaScript
106 lines
2.7 KiB
JavaScript
const { EventEmitter } = require('events');
|
|
const { PassThrough } = require('stream');
|
|
const axios = require('axios');
|
|
const { describe, it } = require('mocha');
|
|
const { expect } = require('chai');
|
|
|
|
const createTransportCapture = () => {
|
|
let capturedOptions;
|
|
|
|
const transport = {
|
|
request(options, onResponse) {
|
|
capturedOptions = options;
|
|
|
|
const req = new EventEmitter();
|
|
req.destroyed = false;
|
|
req.setTimeout = () => {};
|
|
req.write = () => true;
|
|
req.destroy = () => {
|
|
req.destroyed = true;
|
|
};
|
|
req.close = req.destroy;
|
|
req.end = () => {
|
|
const res = new PassThrough();
|
|
res.statusCode = 200;
|
|
res.statusMessage = 'OK';
|
|
res.headers = { 'content-type': 'application/json' };
|
|
res.req = req;
|
|
onResponse(res);
|
|
res.end('{"ok":true}');
|
|
};
|
|
|
|
return req;
|
|
},
|
|
};
|
|
|
|
return {
|
|
transport,
|
|
getCapturedOptions: () => capturedOptions,
|
|
};
|
|
};
|
|
|
|
describe('rateLimit compat (dist export only)', () => {
|
|
it('accepts numeric maxRate config', async () => {
|
|
const response = await axios.get('http://example.com/rate', {
|
|
maxRate: 1024,
|
|
adapter: async (config) => ({
|
|
data: { maxRate: config.maxRate },
|
|
status: 200,
|
|
statusText: 'OK',
|
|
headers: {},
|
|
config,
|
|
}),
|
|
});
|
|
|
|
expect(response.data.maxRate).to.equal(1024);
|
|
});
|
|
|
|
it('accepts tuple maxRate config [upload, download]', async () => {
|
|
const response = await axios.get('http://example.com/rate', {
|
|
maxRate: [2048, 4096],
|
|
adapter: async (config) => ({
|
|
data: { maxRate: config.maxRate },
|
|
status: 200,
|
|
statusText: 'OK',
|
|
headers: {},
|
|
config,
|
|
}),
|
|
});
|
|
|
|
expect(response.data.maxRate).to.deep.equal([2048, 4096]);
|
|
});
|
|
|
|
it('merges instance and request maxRate values', async () => {
|
|
const client = axios.create({
|
|
maxRate: [1000, 2000],
|
|
});
|
|
|
|
const response = await client.get('http://example.com/rate', {
|
|
maxRate: [3000, 4000],
|
|
adapter: async (config) => ({
|
|
data: { maxRate: config.maxRate },
|
|
status: 200,
|
|
statusText: 'OK',
|
|
headers: {},
|
|
config,
|
|
}),
|
|
});
|
|
|
|
expect(response.data.maxRate).to.deep.equal([3000, 4000]);
|
|
});
|
|
|
|
it('supports maxRate in node transport flow without errors', async () => {
|
|
const { transport, getCapturedOptions } = createTransportCapture();
|
|
|
|
const response = await axios.get('http://example.com/rate', {
|
|
proxy: false,
|
|
maxRate: [1500, 2500],
|
|
transport,
|
|
});
|
|
|
|
expect(response.status).to.equal(200);
|
|
expect(getCapturedOptions().method).to.equal('GET');
|
|
expect(getCapturedOptions().path).to.equal('/rate');
|
|
});
|
|
});
|