Skip to content

Commit 7bda957

Browse files
author
Weffe
committed
improvement: start work on cleaning up build process
also, revert devDependency version on axios to 0.18.0 instead of 0.19.0
1 parent 36a7046 commit 7bda957

File tree

10 files changed

+3631
-1136
lines changed

10 files changed

+3631
-1136
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
node_modules/
22
*.log
3-
dist/
3+
dist/
4+
.DS_Store
5+
.rts2_cache_cjs
6+
.rts2_cache_es
7+
.rts2_cache_esm
8+
.rts2_cache_umd

package.json

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,18 @@
33
"author": "Rogelio Negrete (Weffe)",
44
"version": "2.1.0",
55
"description": "Adds api versioning for axios",
6-
"main": "dist/lib/index.js",
7-
"module": "dist/esm/index.js",
8-
"jsnext:main": "dist/esm/index.js",
9-
"types": "dist/lib/index.d.ts",
6+
"main": "dist/index.js",
7+
"module": "dist/axios-api-versioning.js",
8+
"typings": "dist/index.d.ts",
109
"sideEffects": false,
1110
"scripts": {
12-
"prestart": "run-s clean",
13-
"start": "tsc --watch",
14-
"build": "run-s clean build:cjs build:esm build:types",
15-
"build:cjs": "tsc",
16-
"build:esm": "tsc -p tsconfig.esm.json",
17-
"build:types": "tsc -p tsconfig.types.json",
11+
"start": "tsdx watch",
12+
"build": "tsdx build",
13+
"test": "tsdx test",
1814
"sandbox": "tsc -p sandbox/tsconfig.sandbox.json",
1915
"clean": "rimraf dist/",
2016
"release": "standard-version",
21-
"docs": "docsify serve docs -o --port 2065",
22-
"test": "jest"
17+
"docs": "docsify serve docs -o --port 2065"
2318
},
2419
"keywords": [
2520
"axios",
@@ -38,41 +33,27 @@
3833
"axios": "^0.18.0"
3934
},
4035
"devDependencies": {
41-
"@types/jest": "^24.0.11",
42-
"axios": "^0.19.0",
36+
"@types/jest": "^24.0.15",
37+
"axios": "0.18.0",
4338
"axios-mock-adapter": "^1.16.0",
4439
"docsify-cli": "^4.3.0",
4540
"http-status-codes": "^1.3.2",
46-
"jest": "^24.1.0",
47-
"npm-run-all": "^4.1.5",
48-
"rimraf": "^2.6.3",
41+
"husky": "^2.4.1",
42+
"prettier": "^1.18.2",
43+
"pretty-quick": "^1.11.1",
4944
"standard-version": "^6.0.1",
50-
"ts-jest": "^24.0.2",
51-
"typescript": "^3.3.3333"
52-
},
53-
"dependencies": {
54-
"tslib": "^1.9.3"
45+
"tsdx": "^0.7.1",
46+
"tslib": "^1.10.0",
47+
"typescript": "^3.5.2"
5548
},
5649
"files": [
5750
"dist",
5851
"README.md",
5952
"LICENSE"
6053
],
61-
"jest": {
62-
"roots": [
63-
"<rootDir>/src"
64-
],
65-
"moduleFileExtensions": [
66-
"ts",
67-
"tsx",
68-
"js",
69-
"jsx",
70-
"json",
71-
"node"
72-
],
73-
"transform": {
74-
"^.+\\.ts$": "ts-jest"
75-
},
76-
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.ts$"
54+
"husky": {
55+
"hooks": {
56+
"pre-commit": "pretty-quick --staged"
57+
}
7758
}
7859
}

src/__tests__/axios-api-versioning.mock.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/__tests__/axios-api-versioning.spec.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.

tests/axios-api-versioning.mock.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import axios from "axios";
2+
import MockAdapter from "axios-mock-adapter";
3+
import * as status from "http-status-codes";
4+
import { withVersioning } from "../axios-api-versioning";
5+
import { IWithVersioningConfig, VersioningStrategy } from "../types";
6+
import { AxiosInstanceWithVersioning } from "../types/axios";
7+
8+
const test_url = "http://localhost:3000";
9+
const MOCK_RES = "hello_world";
10+
let mock: MockAdapter;
11+
let instance: AxiosInstanceWithVersioning;
12+
13+
describe('Testing correct response config of "QueryString" strategy', () => {
14+
let versioningConfig: IWithVersioningConfig = {
15+
apiVersion: "1.0",
16+
versioningStrategy: VersioningStrategy.QueryString
17+
};
18+
19+
beforeAll(() => {
20+
instance = withVersioning(axios, versioningConfig);
21+
mock = new MockAdapter(instance);
22+
});
23+
24+
test('it should have the "apiVersion" as a query param in the response config', async () => {
25+
mock.onGet(test_url).reply(status.OK, MOCK_RES);
26+
27+
const res = await instance.get(test_url);
28+
const { params } = res.config;
29+
30+
expect(params).toHaveProperty("api-version");
31+
expect(params["api-version"]).toBe(versioningConfig.apiVersion);
32+
});
33+
});
34+
35+
describe('Testing correct response config of "MediaType" strategy', () => {
36+
let versioningConfig: IWithVersioningConfig = {
37+
apiVersion: "1.0",
38+
versioningStrategy: VersioningStrategy.MediaType
39+
};
40+
41+
beforeAll(() => {
42+
instance = withVersioning(axios, versioningConfig);
43+
mock = new MockAdapter(instance);
44+
});
45+
46+
test('it should have the "apiVersion" as an accept-param in the Accept header', async () => {
47+
mock.onGet(test_url).reply(status.OK, MOCK_RES);
48+
49+
const res = await instance.get(test_url);
50+
const { headers } = res.config;
51+
52+
expect(headers).toHaveProperty("Accept");
53+
expect(headers["Accept"]).toMatch(`v=${versioningConfig.apiVersion}`);
54+
});
55+
});
56+
57+
describe('Testing correct response config of "UrlPath" strategy', () => {
58+
let versioningConfig: IWithVersioningConfig = {
59+
apiVersion: "1",
60+
versioningStrategy: VersioningStrategy.UrlPath
61+
};
62+
63+
const blank_test_url = test_url + "/v{apiVersion}";
64+
const versioned_test_url = test_url + `/v${versioningConfig.apiVersion}`;
65+
66+
beforeAll(() => {
67+
instance = withVersioning(axios, versioningConfig);
68+
mock = new MockAdapter(instance);
69+
});
70+
71+
test('it should have the "apiVersion" as a url param in the url', async () => {
72+
mock.onGet(versioned_test_url).reply(status.OK, MOCK_RES);
73+
74+
const res = await instance.get(blank_test_url);
75+
const { url } = res.config;
76+
77+
expect(url).toBe(versioned_test_url);
78+
});
79+
});

0 commit comments

Comments
 (0)