mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +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,4 +1,6 @@
|
||||
var kindOf = require('../../../lib/utils').kindOf;
|
||||
import utils from '../../../lib/utils';
|
||||
|
||||
const {kindOf} = utils;
|
||||
|
||||
describe('utils::kindOf', function () {
|
||||
it('should return object tag', function () {
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
var extend = require('../../../lib/utils').extend;
|
||||
import utils from '../../../lib/utils';
|
||||
|
||||
const {extend} = utils;
|
||||
|
||||
describe('utils::extend', function () {
|
||||
it('should be mutable', function () {
|
||||
var a = {};
|
||||
var b = {foo: 123};
|
||||
const a = {};
|
||||
const b = {foo: 123};
|
||||
|
||||
extend(a, b);
|
||||
|
||||
expect(a.foo).toEqual(b.foo);
|
||||
});
|
||||
|
||||
|
||||
it('should extend properties', function () {
|
||||
var a = {foo: 123, bar: 456};
|
||||
var b = {bar: 789};
|
||||
let a = {foo: 123, bar: 456};
|
||||
const b = {bar: 789};
|
||||
|
||||
a = extend(a, b);
|
||||
|
||||
@@ -21,9 +23,9 @@ describe('utils::extend', function () {
|
||||
});
|
||||
|
||||
it('should bind to thisArg', function () {
|
||||
var a = {};
|
||||
var b = {getFoo: function getFoo() { return this.foo; }};
|
||||
var thisArg = { foo: 'barbaz' };
|
||||
const a = {};
|
||||
const b = {getFoo: function getFoo() { return this.foo; }};
|
||||
const thisArg = { foo: 'barbaz' };
|
||||
|
||||
extend(a, b, thisArg);
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
var forEach = require('../../../lib/utils').forEach;
|
||||
import utils from '../../../lib/utils';
|
||||
|
||||
const {forEach} = utils;
|
||||
|
||||
describe('utils::forEach', function () {
|
||||
it('should loop over an array', function () {
|
||||
var sum = 0;
|
||||
let sum = 0;
|
||||
|
||||
forEach([1, 2, 3, 4, 5], function (val) {
|
||||
sum += val;
|
||||
@@ -12,9 +14,9 @@ describe('utils::forEach', function () {
|
||||
});
|
||||
|
||||
it('should loop over object keys', function () {
|
||||
var keys = '';
|
||||
var vals = 0;
|
||||
var obj = {
|
||||
let keys = '';
|
||||
let vals = 0;
|
||||
const obj = {
|
||||
b: 1,
|
||||
a: 2,
|
||||
r: 3
|
||||
@@ -30,7 +32,7 @@ describe('utils::forEach', function () {
|
||||
});
|
||||
|
||||
it('should handle undefined gracefully', function () {
|
||||
var count = 0;
|
||||
let count = 0;
|
||||
|
||||
forEach(undefined, function () {
|
||||
count++;
|
||||
@@ -40,7 +42,7 @@ describe('utils::forEach', function () {
|
||||
});
|
||||
|
||||
it('should make an array out of non-array argument', function () {
|
||||
var count = 0;
|
||||
let count = 0;
|
||||
|
||||
forEach(function () {}, function () {
|
||||
count++;
|
||||
@@ -50,8 +52,8 @@ describe('utils::forEach', function () {
|
||||
});
|
||||
|
||||
it('should handle non object prototype gracefully', function () {
|
||||
var count = 0;
|
||||
var data = Object.create(null);
|
||||
let count = 0;
|
||||
const data = Object.create(null);
|
||||
data.foo = 'bar'
|
||||
|
||||
forEach(data, function () {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var utils = require('../../../lib/utils');
|
||||
var Stream = require('stream');
|
||||
import utils from '../../../lib/utils';
|
||||
|
||||
describe('utils::isX', function () {
|
||||
it('should validate Array', function () {
|
||||
@@ -7,12 +6,6 @@ describe('utils::isX', function () {
|
||||
expect(utils.isArray({length: 5})).toEqual(false);
|
||||
});
|
||||
|
||||
it('should validate Buffer', function () {
|
||||
expect(utils.isBuffer(Buffer.from('a'))).toEqual(true);
|
||||
expect(utils.isBuffer(null)).toEqual(false);
|
||||
expect(utils.isBuffer(undefined)).toEqual(false);
|
||||
});
|
||||
|
||||
it('should validate ArrayBuffer', function () {
|
||||
expect(utils.isArrayBuffer(new ArrayBuffer(2))).toEqual(true);
|
||||
expect(utils.isArrayBuffer({})).toEqual(false);
|
||||
@@ -68,11 +61,6 @@ describe('utils::isX', function () {
|
||||
expect(utils.isFunction('function')).toEqual(false);
|
||||
});
|
||||
|
||||
it('should validate Stream', function () {
|
||||
expect(utils.isStream(new Stream.Readable())).toEqual(true);
|
||||
expect(utils.isStream({ foo: 'bar' })).toEqual(false);
|
||||
});
|
||||
|
||||
it('should validate URLSearchParams', function () {
|
||||
expect(utils.isURLSearchParams(new URLSearchParams())).toEqual(true);
|
||||
expect(utils.isURLSearchParams('foo=1&bar=2')).toEqual(false);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var kindOfTest = require('../../../lib/utils').kindOfTest;
|
||||
import {kindOfTest} from '../../../lib/utils';
|
||||
|
||||
describe('utils::endsWith', function () {
|
||||
it('should return true if the string ends with passed substring', function () {
|
||||
var test = kindOfTest('number');
|
||||
const test = kindOfTest('number');
|
||||
|
||||
expect(test(123)).toEqual(true);
|
||||
expect(test('123')).toEqual(false);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
var kindOf = require('../../../lib/utils').kindOf;
|
||||
import utils from '../../../lib/utils';
|
||||
|
||||
const {kindOf} = utils;
|
||||
|
||||
describe('utils::kindOf', function () {
|
||||
it('should return object tag', function () {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
var merge = require('../../../lib/utils').merge;
|
||||
import utils from '../../../lib/utils';
|
||||
|
||||
const {merge} = utils;
|
||||
|
||||
describe('utils::merge', function () {
|
||||
it('should be immutable', function () {
|
||||
var a = {};
|
||||
var b = {foo: 123};
|
||||
var c = {bar: 456};
|
||||
const a = {};
|
||||
const b = {foo: 123};
|
||||
const c = {bar: 456};
|
||||
|
||||
merge(a, b, c);
|
||||
|
||||
@@ -13,21 +15,21 @@ describe('utils::merge', function () {
|
||||
expect(typeof b.bar).toEqual('undefined');
|
||||
expect(typeof c.foo).toEqual('undefined');
|
||||
});
|
||||
|
||||
|
||||
it('should merge properties', function () {
|
||||
var a = {foo: 123};
|
||||
var b = {bar: 456};
|
||||
var c = {foo: 789};
|
||||
var d = merge(a, b, c);
|
||||
const a = {foo: 123};
|
||||
const b = {bar: 456};
|
||||
const c = {foo: 789};
|
||||
const d = merge(a, b, c);
|
||||
|
||||
expect(d.foo).toEqual(789);
|
||||
expect(d.bar).toEqual(456);
|
||||
});
|
||||
|
||||
it('should merge recursively', function () {
|
||||
var a = {foo: {bar: 123}};
|
||||
var b = {foo: {baz: 456}, bar: {qux: 789}};
|
||||
|
||||
const a = {foo: {bar: 123}};
|
||||
const b = {foo: {baz: 456}, bar: {qux: 789}};
|
||||
|
||||
expect(merge(a, b)).toEqual({
|
||||
foo: {
|
||||
bar: 123,
|
||||
@@ -40,9 +42,9 @@ describe('utils::merge', function () {
|
||||
});
|
||||
|
||||
it('should remove all references from nested objects', function () {
|
||||
var a = {foo: {bar: 123}};
|
||||
var b = {};
|
||||
var d = merge(a, b);
|
||||
const a = {foo: {bar: 123}};
|
||||
const b = {};
|
||||
const d = merge(a, b);
|
||||
|
||||
expect(d).toEqual({
|
||||
foo: {
|
||||
@@ -75,8 +77,8 @@ describe('utils::merge', function () {
|
||||
});
|
||||
|
||||
it('should replace properties with cloned arrays', function () {
|
||||
var a = [1, 2, 3];
|
||||
var d = merge({}, {a: a});
|
||||
const a = [1, 2, 3];
|
||||
const d = merge({}, {a: a});
|
||||
|
||||
expect(d).toEqual({a: [1, 2, 3]});
|
||||
expect(d.a).not.toBe(a);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
var toArray = require('../../../lib/utils').toArray;
|
||||
import utils from '../../../lib/utils';
|
||||
|
||||
const {toArray} = utils;
|
||||
|
||||
describe('utils::kindOf', function () {
|
||||
it('should return object tag', function () {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
var toFlatObject = require('../../../lib/utils').toFlatObject;
|
||||
import utils from '../../../lib/utils';
|
||||
|
||||
const {toFlatObject} = utils;
|
||||
|
||||
describe('utils::toFlatObject', function () {
|
||||
it('should resolve object proto chain to a flat object representation', function () {
|
||||
var a = {x: 1};
|
||||
var b = Object.create(a, {y: {value: 2}});
|
||||
var c = Object.create(b, {z: {value: 3}});
|
||||
const a = {x: 1};
|
||||
const b = Object.create(a, {y: {value: 2}});
|
||||
const c = Object.create(b, {z: {value: 3}});
|
||||
expect(toFlatObject(c)).toEqual({x: 1, y: 2, z: 3});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
var trim = require('../../../lib/utils').trim;
|
||||
import utils from '../../../lib/utils';
|
||||
|
||||
describe('utils::trim', function () {
|
||||
it('should trim spaces', function () {
|
||||
expect(trim(' foo ')).toEqual('foo');
|
||||
expect(utils.trim(' foo ')).toEqual('foo');
|
||||
});
|
||||
|
||||
it('should trim tabs', function () {
|
||||
expect(trim('\tfoo\t')).toEqual('foo');
|
||||
expect(utils.trim('\tfoo\t')).toEqual('foo');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user