Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: support the latest versions of node.js #188

Merged
merged 1 commit into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .babelrc

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [10, 12, 14, 16]
node: [14, 16, 18]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -33,7 +33,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm install
- run: npm run lint
license_check:
Expand All @@ -42,7 +42,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm install
- run: npm run license-check
release:
Expand All @@ -53,7 +53,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm install
- run: npm run compile
- run: npx semantic-release
Expand Down
17 changes: 0 additions & 17 deletions .prettierrc.js

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"bracketSpacing": false,
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "avoid"
}
46 changes: 18 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
"name": "retry-axios",
"version": "0.0.0",
"description": "Retry HTTP requests with Axios.",
"source": "src/index.ts",
"main": "dist/index.js",
"module": "dist/index.module.js",
"unpkg": "dist/index.umd.js",
"types": "dist/src/index.d.ts",
"exports": "./build/src/index.js",
"type": "module",
"types": "./build/src/index.d.ts",
"engines": {
"node": ">=10.7.0"
"node": ">=14"
},
"repository": {
"type": "git",
Expand All @@ -18,11 +16,8 @@
"lint": "gts check",
"clean": "gts clean",
"fix": "gts fix",
"compile": "tsc --target ES5 --module CommonJS",
"build-web": "microbundle",
"umd": "rm -rf umd && babel build/src -d umd --source-maps",
"compile": "tsc -p .",
"test": "c8 mocha build/test",
"prepare": "npm run build-web",
"pretest": "npm run compile",
"license-check": "jsgl --local ."
},
Expand All @@ -38,31 +33,26 @@
"axios": "*"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@types/mocha": "^9.0.0",
"@types/sinon": "^10.0.0",
"@types/node": "^16.0.0",
"@types/mocha": "^9.1.1",
"@types/sinon": "^10.0.11",
"@types/node": "^17.0.31",
"axios": "^0.26.0",
"babel-plugin-transform-es2015-modules-umd": "^6.24.1",
"c8": "^7.0.0",
"gts": "^3.0.0",
"js-green-licenses": "^3.0.0",
"microbundle": "^0.11.0",
"mocha": "^9.0.0",
"nock": "^13.0.0",
"semantic-release": "^18.0.0",
"sinon": "^13.0.0",
"typescript": "~4.3.0"
"c8": "^7.11.2",
"gts": "^3.1.0",
"js-green-licenses": "^3.0.1",
"mocha": "^10.0.0",
"nock": "^13.2.4",
"semantic-release": "^19.0.2",
"sinon": "^13.0.2",
"typescript": "~4.6.4"
},
"files": [
"dist"
"build/src"
],
"c8": {
"exclude": [
"build/test",
"dist"
]
},
"browserslist": "> 1%, last 2 versions, Firefox ESR"
}
}
60 changes: 36 additions & 24 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as assert from 'assert';
import axios, {AxiosRequestConfig} from 'axios';
import * as nock from 'nock';
import * as sinon from 'sinon';
import assert from 'assert';
import axios, {AxiosError, AxiosRequestConfig} from 'axios';
import nock from 'nock';
import sinon from 'sinon';
import {describe, it, afterEach} from 'mocha';
import * as rax from '../src';
import {RaxConfig} from '../src';
import * as rax from '../src/index.js';
import {RaxConfig} from '../src/index.js';

const url = 'http://test.local';

Expand All @@ -25,7 +25,8 @@ describe('retry-axios', () => {
interceptorId = rax.attach();
try {
await axios(url);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
scope.done();
const config = rax.getConfig(e);
assert.strictEqual(config!.currentRetryAttempt, 3, 'currentRetryAttempt');
Expand Down Expand Up @@ -73,7 +74,8 @@ describe('retry-axios', () => {
interceptorId = rax.attach();
try {
await axios.post(url);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
const config = rax.getConfig(e);
assert.strictEqual(config!.currentRetryAttempt, 0);
scope.done();
Expand Down Expand Up @@ -101,7 +103,8 @@ describe('retry-axios', () => {
const cfg: rax.RaxConfig = {url, raxConfig: {retry: 1}};
try {
await axios(cfg);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
assert.strictEqual(rax.getConfig(e)!.currentRetryAttempt, 1);
scope.done();
return;
Expand All @@ -114,13 +117,13 @@ describe('retry-axios', () => {
const scopes = [
nock(url)
.get('/')
.reply((_, __) => {
.reply(() => {
requesttimes.push(process.hrtime.bigint());
return [500, 'foo'];
}),
nock(url)
.get('/')
.reply((_, __) => {
.reply(() => {
requesttimes.push(process.hrtime.bigint());
return [200, 'bar'];
}),
Expand Down Expand Up @@ -154,13 +157,13 @@ describe('retry-axios', () => {
const scopes = [
nock(url)
.get('/')
.reply((_, __) => {
.reply(() => {
requesttimes.push(process.hrtime.bigint());
return [500, 'foo'];
}),
nock(url)
.get('/')
.reply((_, __) => {
.reply(() => {
requesttimes.push(process.hrtime.bigint());
return [200, 'bar'];
}),
Expand Down Expand Up @@ -194,13 +197,13 @@ describe('retry-axios', () => {
const scopes = [
nock(url)
.get('/')
.reply((_, __) => {
.reply(() => {
requesttimes.push(process.hrtime.bigint());
return [500, 'foo'];
}),
nock(url)
.get('/')
.reply((_, __) => {
.reply(() => {
requesttimes.push(process.hrtime.bigint());
return [200, 'bar'];
}),
Expand Down Expand Up @@ -246,7 +249,8 @@ describe('retry-axios', () => {
assert.notStrictEqual(ax, axios);
try {
await axios({url});
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
assert.strictEqual(undefined, rax.getConfig(e));
scope.done();
return;
Expand Down Expand Up @@ -278,7 +282,8 @@ describe('retry-axios', () => {
interceptorId = rax.attach();
try {
await axios.get(url);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
const cfg = rax.getConfig(e);
assert.strictEqual(cfg!.currentRetryAttempt, 0);
scope.done();
Expand All @@ -293,7 +298,8 @@ describe('retry-axios', () => {
try {
const cfg: rax.RaxConfig = {url, raxConfig: {retry: 0}};
await axios(cfg);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
const cfg = rax.getConfig(e);
assert.strictEqual(0, cfg!.currentRetryAttempt);
scope.done();
Expand All @@ -311,7 +317,8 @@ describe('retry-axios', () => {
};
try {
await axios(config);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
const cfg = rax.getConfig(e);
assert.strictEqual(cfg!.backoffType, 'exponential');
scope.isDone();
Expand Down Expand Up @@ -381,7 +388,8 @@ describe('retry-axios', () => {
};
try {
await axios(config);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
const cfg = rax.getConfig(e);
assert.strictEqual(cfg!.currentRetryAttempt, 0);
scope.done();
Expand Down Expand Up @@ -418,7 +426,8 @@ describe('retry-axios', () => {
const config = {url, raxConfig: {noResponseRetries: 0}};
try {
await axios(config);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
const cfg = rax.getConfig(e);
assert.strictEqual(cfg!.currentRetryAttempt, 0);
scope.isDone();
Expand Down Expand Up @@ -477,7 +486,8 @@ describe('retry-axios', () => {
};
try {
await axios(config);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
const cfg = rax.getConfig(e);
assert.strictEqual(cfg!.retryDelay, 0);
scope.isDone();
Expand All @@ -495,7 +505,8 @@ describe('retry-axios', () => {
};
try {
await axios(config);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
const cfg = rax.getConfig(e);
assert.strictEqual(cfg!.retry, 0);
scope.isDone();
Expand All @@ -513,7 +524,8 @@ describe('retry-axios', () => {
};
try {
await axios(config);
} catch (e) {
} catch (ex) {
const e = ex as AxiosError;
const cfg = rax.getConfig(e);
assert.strictEqual(cfg!.noResponseRetries, 0);
scope.isDone();
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"rootDir": ".",
"outDir": "build",
"moduleResolution": "node",
"module": "ES2015"
"module": "ES2022",
"esModuleInterop": true
},
"include": [
"src/*.ts",
Expand Down