mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
Axios ES2017 (#4787)
* Added AxiosHeaders class; * Fixed README.md href; * Fixed a potential bug with headers normalization; * Fixed a potential bug with headers normalization; Refactored accessor building routine; Refactored default transforms; Removed `normalizeHeaderName` helper; * Added `Content-Length` accessor; Added missed `has` accessor to TS types; * Added `AxiosTransformStream` class; Added progress capturing ability for node.js environment; Added `maxRate` option to limit the data rate in node.js environment; Refactored event handled by `onUploadProgress` && `onDownloadProgress` listeners in browser environment; Added progress & data rate tests for the http adapter; Added response stream aborting test; Added a manual progress capture test for the browser; Updated TS types; Added TS tests; Refactored request abort logic for the http adapter; Added ability to abort the response stream; * Remove `stream/promises` & `timers/promises` modules usage in tests; * Use `abortcontroller-polyfill`; * Fixed AxiosTransformStream dead-lock in legacy node versions; Fixed CancelError emitting in streams; * Reworked AxiosTransformStream internal logic to optimize memory consumption; Added throwing an error if the request stream was silently destroying (without error) Refers to #3966; * Treat the destruction of the request stream as a cancellation of the request; Fixed tests; * Emit `progress` event in the next tick; * Initial refactoring; * Refactored Mocha tests to use ESM; * Refactored Karma tests to use rollup preprocessor & ESM; Replaced grunt with gulp; Improved dev scripts; Added Babel for rollup build; * Added default commonjs package export for Node build; Added automatic contributors list generator for package.json; Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
var bind = require('../../../lib/helpers/bind');
|
||||
import bind from '../../../lib/helpers/bind';
|
||||
|
||||
describe('bind', function () {
|
||||
it('should bind an object to a function', function () {
|
||||
var o = { val: 123 };
|
||||
var f = bind(function (num) {
|
||||
const o = { val: 123 };
|
||||
const f = bind(function (num) {
|
||||
return this.val * num;
|
||||
}, o);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var buildURL = require('../../../lib/helpers/buildURL');
|
||||
var URLSearchParams = require('url-search-params');
|
||||
import buildURL from '../../../lib/helpers/buildURL';
|
||||
import URLSearchParams from 'url-search-params';
|
||||
|
||||
describe('helpers::buildURL', function () {
|
||||
it('should support null params', function () {
|
||||
@@ -21,7 +21,7 @@ describe('helpers::buildURL', function () {
|
||||
});
|
||||
|
||||
it('should support date params', function () {
|
||||
var date = new Date();
|
||||
const date = new Date();
|
||||
|
||||
expect(buildURL('/foo', {
|
||||
date: date
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var combineURLs = require('../../../lib/helpers/combineURLs');
|
||||
import combineURLs from '../../../lib/helpers/combineURLs';
|
||||
|
||||
describe('helpers::combineURLs', function () {
|
||||
it('should combine URLs', function () {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var cookies = require('../../../lib/helpers/cookies');
|
||||
import cookies from '../../../lib/helpers/cookies';
|
||||
|
||||
describe('helpers::cookies', function () {
|
||||
afterEach(function () {
|
||||
// Remove all the cookies
|
||||
var expires = Date.now() - (60 * 60 * 24 * 7);
|
||||
const expires = Date.now() - (60 * 60 * 24 * 7);
|
||||
document.cookie.split(';').map(function (cookie) {
|
||||
return cookie.split('=')[0];
|
||||
}).forEach(function (name) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var formDataToJSON = require('../../../lib/helpers/formDataToJSON');
|
||||
import formDataToJSON from '../../../lib/helpers/formDataToJSON';
|
||||
|
||||
describe('formDataToJSON', function () {
|
||||
it('should convert a FormData Object to JSON Object', function () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var isAbsoluteURL = require('../../../lib/helpers/isAbsoluteURL');
|
||||
import isAbsoluteURL from '../../../lib/helpers/isAbsoluteURL';
|
||||
|
||||
describe('helpers::isAbsoluteURL', function () {
|
||||
it('should return true if URL begins with valid scheme name', function () {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var AxiosError = require('../../../lib/core/AxiosError');
|
||||
var isAxiosError = require('../../../lib/helpers/isAxiosError');
|
||||
import AxiosError from '../../../lib/core/AxiosError';
|
||||
import isAxiosError from '../../../lib/helpers/isAxiosError';
|
||||
|
||||
describe('helpers::isAxiosError', function() {
|
||||
it('should return true if the error is created by core::createError', function() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var isURLSameOrigin = require('../../../lib/helpers/isURLSameOrigin');
|
||||
import isURLSameOrigin from '../../../lib/helpers/isURLSameOrigin';
|
||||
|
||||
describe('helpers::isURLSameOrigin', function () {
|
||||
it('should detect same origin', function () {
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
var normalizeHeaderName = require('../../../lib/helpers/normalizeHeaderName');
|
||||
|
||||
describe('helpers::normalizeHeaderName', function () {
|
||||
it('should normalize matching header name', function () {
|
||||
var headers = {
|
||||
'conTenT-Type': 'foo/bar',
|
||||
};
|
||||
normalizeHeaderName(headers, 'Content-Type');
|
||||
expect(headers['Content-Type']).toBe('foo/bar');
|
||||
expect(headers['conTenT-Type']).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not change non-matching header name', function () {
|
||||
var headers = {
|
||||
'content-type': 'foo/bar',
|
||||
};
|
||||
normalizeHeaderName(headers, 'Content-Length');
|
||||
expect(headers['content-type']).toBe('foo/bar');
|
||||
expect(headers['Content-Length']).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,9 @@
|
||||
var parseHeaders = require('../../../lib/helpers/parseHeaders');
|
||||
import parseHeaders from '../../../lib/helpers/parseHeaders';
|
||||
|
||||
describe('helpers::parseHeaders', function () {
|
||||
it('should parse headers', function () {
|
||||
var date = new Date();
|
||||
var parsed = parseHeaders(
|
||||
const date = new Date();
|
||||
const parsed = parseHeaders(
|
||||
'Date: ' + date.toISOString() + '\n' +
|
||||
'Content-Type: application/json\n' +
|
||||
'Connection: keep-alive\n' +
|
||||
@@ -17,11 +17,11 @@ describe('helpers::parseHeaders', function () {
|
||||
});
|
||||
|
||||
it('should use array for set-cookie', function() {
|
||||
var parsedZero = parseHeaders('');
|
||||
var parsedSingle = parseHeaders(
|
||||
const parsedZero = parseHeaders('');
|
||||
const parsedSingle = parseHeaders(
|
||||
'Set-Cookie: key=val;'
|
||||
);
|
||||
var parsedMulti = parseHeaders(
|
||||
const parsedMulti = parseHeaders(
|
||||
'Set-Cookie: key=val;\n' +
|
||||
'Set-Cookie: key2=val2;\n'
|
||||
);
|
||||
@@ -32,7 +32,7 @@ describe('helpers::parseHeaders', function () {
|
||||
});
|
||||
|
||||
it('should handle duplicates', function() {
|
||||
var parsed = parseHeaders(
|
||||
const parsed = parseHeaders(
|
||||
'Age: age-a\n' + // age is in ignore duplicates blocklist
|
||||
'Age: age-b\n' +
|
||||
'Foo: foo-a\n' +
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var spread = require('../../../lib/helpers/spread');
|
||||
import spread from '../../../lib/helpers/spread';
|
||||
|
||||
describe('helpers::spread', function () {
|
||||
it('should spread array to arguments', function () {
|
||||
var value = 0;
|
||||
let value = 0;
|
||||
spread(function (a, b) {
|
||||
value = a * b;
|
||||
})([5, 10]);
|
||||
@@ -11,7 +11,7 @@ describe('helpers::spread', function () {
|
||||
});
|
||||
|
||||
it('should return callback result', function () {
|
||||
var value = spread(function (a, b) {
|
||||
const value = spread(function (a, b) {
|
||||
return a * b;
|
||||
})([5, 10]);
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
var toFormData = require('../../../lib/helpers/toFormData');
|
||||
import toFormData from '../../../lib/helpers/toFormData';
|
||||
|
||||
describe('toFormData', function () {
|
||||
it('should convert nested data object to FormData with dots option enabled', function () {
|
||||
var o = {
|
||||
const o = {
|
||||
val: 123,
|
||||
nested: {
|
||||
arr: ['hello', 'world']
|
||||
}
|
||||
};
|
||||
|
||||
var form = toFormData(o, null, {dots: true});
|
||||
const form = toFormData(o, null, {dots: true});
|
||||
expect(form instanceof FormData).toEqual(true);
|
||||
expect(Array.from(form.keys()).length).toEqual(3);
|
||||
expect(form.get('val')).toEqual('123');
|
||||
@@ -17,13 +17,13 @@ describe('toFormData', function () {
|
||||
});
|
||||
|
||||
it('should respect metaTokens option', function () {
|
||||
var data = {
|
||||
const data = {
|
||||
'obj{}': {x: 1, y: 2}
|
||||
};
|
||||
|
||||
var str = JSON.stringify(data['obj{}']);
|
||||
const str = JSON.stringify(data['obj{}']);
|
||||
|
||||
var form = toFormData(data, null, {metaTokens: false});
|
||||
const form = toFormData(data, null, {metaTokens: false});
|
||||
|
||||
expect(Array.from(form.keys()).length).toEqual(1);
|
||||
expect(form.getAll('obj')).toEqual([str]);
|
||||
@@ -31,12 +31,12 @@ describe('toFormData', function () {
|
||||
|
||||
describe('Flat arrays serialization', function () {
|
||||
it('should include full indexes when the `indexes` option is set to true', function () {
|
||||
var data = {
|
||||
const data = {
|
||||
arr: [1, 2, 3],
|
||||
arr2: [1, [2], 3]
|
||||
};
|
||||
|
||||
var form = toFormData(data, null, {indexes: true});
|
||||
const form = toFormData(data, null, {indexes: true});
|
||||
|
||||
expect(Array.from(form.keys()).length).toEqual(6);
|
||||
|
||||
@@ -50,12 +50,12 @@ describe('toFormData', function () {
|
||||
});
|
||||
|
||||
it('should include brackets only when the `indexes` option is set to false', function () {
|
||||
var data = {
|
||||
const data = {
|
||||
arr: [1, 2, 3],
|
||||
arr2: [1, [2], 3]
|
||||
};
|
||||
|
||||
var form = toFormData(data, null, {indexes: false});
|
||||
const form = toFormData(data, null, {indexes: false});
|
||||
|
||||
expect(Array.from(form.keys()).length).toEqual(6);
|
||||
|
||||
@@ -67,12 +67,12 @@ describe('toFormData', function () {
|
||||
});
|
||||
|
||||
it('should omit brackets when the `indexes` option is set to null', function () {
|
||||
var data = {
|
||||
const data = {
|
||||
arr: [1, 2, 3],
|
||||
arr2: [1, [2], 3]
|
||||
};
|
||||
|
||||
var form = toFormData(data, null, {indexes: null});
|
||||
const form = toFormData(data, null, {indexes: null});
|
||||
|
||||
expect(Array.from(form.keys()).length).toEqual(6);
|
||||
|
||||
@@ -85,14 +85,14 @@ describe('toFormData', function () {
|
||||
});
|
||||
|
||||
it('should convert nested data object to FormData', function () {
|
||||
var o = {
|
||||
const o = {
|
||||
val: 123,
|
||||
nested: {
|
||||
arr: ['hello', 'world']
|
||||
}
|
||||
};
|
||||
|
||||
var form = toFormData(o);
|
||||
const form = toFormData(o);
|
||||
expect(form instanceof FormData).toEqual(true);
|
||||
expect(Array.from(form.keys()).length).toEqual(3);
|
||||
expect(form.get('val')).toEqual('123');
|
||||
@@ -100,24 +100,24 @@ describe('toFormData', function () {
|
||||
});
|
||||
|
||||
it('should append value whose key ends with [] as separate values with the same key', function () {
|
||||
var data = {
|
||||
const data = {
|
||||
'arr[]': [1, 2, 3]
|
||||
};
|
||||
|
||||
var form = toFormData(data);
|
||||
const form = toFormData(data);
|
||||
|
||||
expect(Array.from(form.keys()).length).toEqual(3);
|
||||
expect(form.getAll('arr[]')).toEqual(['1', '2', '3']);
|
||||
});
|
||||
|
||||
it('should append value whose key ends with {} as a JSON string', function () {
|
||||
var data = {
|
||||
const data = {
|
||||
'obj{}': {x: 1, y: 2}
|
||||
};
|
||||
|
||||
var str = JSON.stringify(data['obj{}']);
|
||||
const str = JSON.stringify(data['obj{}']);
|
||||
|
||||
var form = toFormData(data);
|
||||
const form = toFormData(data);
|
||||
|
||||
expect(Array.from(form.keys()).length).toEqual(1);
|
||||
expect(form.getAll('obj{}')).toEqual([str]);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var validator = require('../../../lib/helpers/validator');
|
||||
import validator from '../../../lib/helpers/validator';
|
||||
|
||||
describe('validator::assertOptions', function() {
|
||||
it('should throw only if unknown an option was passed', function() {
|
||||
|
||||
Reference in New Issue
Block a user