docs: 修改 readme 里的链接
parent
1aac6f3154
commit
01e4167ad4
|
@ -3,7 +3,7 @@
|
|||
[](https://badge.fury.io/js/axios-miniprogram)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
|
||||
[中文文档](axios-miniprogram.com)
|
||||
[中文文档](https://axios-miniprogram.com)
|
||||
|
||||
## 安装
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
```typescript
|
||||
axios.defaults.adapter = function adapter(adapterConfig) {
|
||||
const {
|
||||
// 请求类型
|
||||
type,
|
||||
// 请求地址
|
||||
url,
|
||||
// 请求方法
|
||||
|
@ -38,13 +40,34 @@ axios.defaults.adapter = function adapter(adapterConfig) {
|
|||
} = adapterConfig;
|
||||
|
||||
// 在 adapterConfig 中选择您需要的参数发送请求
|
||||
return wx.request({
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
headers,
|
||||
success,
|
||||
fail,
|
||||
});
|
||||
switch (type) {
|
||||
case 'request': // 数据请求
|
||||
return wx.request({
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
headers,
|
||||
success,
|
||||
fail,
|
||||
});
|
||||
case 'upload': // 上传
|
||||
return wx.uploadFile({
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
headers,
|
||||
success,
|
||||
fail,
|
||||
});
|
||||
case 'download': // 下载
|
||||
return wx.downloadFile({
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
headers,
|
||||
success,
|
||||
fail,
|
||||
});
|
||||
}
|
||||
};
|
||||
```
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
||||
"upload:asset": "esno scripts/upload-asset.ts",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"lint": "eslint --cache .",
|
||||
"lint:fix": "pnpm lint --fix",
|
||||
"docs:dev": "pnpm -C docs dev",
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
isArray,
|
||||
isDate,
|
||||
|
@ -11,7 +12,7 @@ import {
|
|||
} from '../../src/helpers/is';
|
||||
|
||||
describe('对 src/helpers/is.ts 进行测试', () => {
|
||||
it('测试 isArray() 执行结果是否符合预期', () => {
|
||||
test('传入数组应该返回 true,其他参数应该返回 fasle', () => {
|
||||
expect(isArray([0])).toBe(true);
|
||||
expect(isArray([])).toBe(true);
|
||||
expect(isArray({})).toBe(false);
|
||||
|
@ -21,7 +22,7 @@ describe('对 src/helpers/is.ts 进行测试', () => {
|
|||
expect(isArray(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('测试 isDate() 执行结果是否符合预期', () => {
|
||||
test('传入 Date 实例应该返回 true,其他参数应该返回 fasle', () => {
|
||||
expect(isDate(new Date())).toBe(true);
|
||||
expect(isDate({})).toBe(false);
|
||||
expect(isDate([])).toBe(false);
|
||||
|
@ -31,7 +32,7 @@ describe('对 src/helpers/is.ts 进行测试', () => {
|
|||
expect(isDate(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('测试 isEmptyArray() 执行结果是否符合预期', () => {
|
||||
test('传入空数组应该返回 true,其他参数应该返回 fasle', () => {
|
||||
expect(isEmptyArray([])).toBe(true);
|
||||
expect(isEmptyArray([0])).toBe(false);
|
||||
expect(isEmptyArray({})).toBe(false);
|
||||
|
@ -41,7 +42,7 @@ describe('对 src/helpers/is.ts 进行测试', () => {
|
|||
expect(isEmptyArray(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('测试 isEmptyObject() 执行结果是否符合预期', () => {
|
||||
test('传入空对象应该返回 true,其他参数应该返回 fasle', () => {
|
||||
expect(isEmptyObject({})).toBe(true);
|
||||
expect(isEmptyObject({ a: 0 })).toBe(false);
|
||||
expect(isEmptyObject([0])).toBe(false);
|
||||
|
@ -52,7 +53,7 @@ describe('对 src/helpers/is.ts 进行测试', () => {
|
|||
expect(isEmptyObject(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('测试 isFunction() 执行结果是否符合预期', () => {
|
||||
test('传入空函数应该返回 true,其他参数应该返回 fasle', () => {
|
||||
expect(
|
||||
isFunction(() => {
|
||||
return;
|
||||
|
@ -71,7 +72,7 @@ describe('对 src/helpers/is.ts 进行测试', () => {
|
|||
expect(isFunction(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('测试 isNull() 执行结果是否符合预期', () => {
|
||||
test('传入空 null 应该返回 true,其他参数应该返回 fasle', () => {
|
||||
expect(isNull(null)).toBe(true);
|
||||
expect(isNull({ a: 0 })).toBe(false);
|
||||
expect(isNull([0])).toBe(false);
|
||||
|
@ -81,7 +82,7 @@ describe('对 src/helpers/is.ts 进行测试', () => {
|
|||
expect(isNull(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it('测试 isPlainObject() 执行结果是否符合预期', () => {
|
||||
test('传入普通对象应该返回 true,其他参数应该返回 fasle', () => {
|
||||
expect(isPlainObject({})).toBe(true);
|
||||
expect(isPlainObject({ a: 0 })).toBe(true);
|
||||
expect(isPlainObject([0])).toBe(false);
|
||||
|
@ -92,7 +93,7 @@ describe('对 src/helpers/is.ts 进行测试', () => {
|
|||
expect(isPlainObject(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('测试 isString() 执行结果是否符合预期', () => {
|
||||
test('传入字符串应该返回 true,其他参数应该返回 fasle', () => {
|
||||
expect(isString('')).toBe(true);
|
||||
expect(isString({})).toBe(false);
|
||||
expect(isString({ a: 0 })).toBe(false);
|
||||
|
@ -103,7 +104,7 @@ describe('对 src/helpers/is.ts 进行测试', () => {
|
|||
expect(isString(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('测试 isUndefined() 执行结果是否符合预期', () => {
|
||||
test('传入 undefined 应该返回 true,其他参数应该返回 fasle', () => {
|
||||
expect(isUndefined(undefined)).toBe(true);
|
||||
expect(isUndefined('')).toBe(false);
|
||||
expect(isUndefined({})).toBe(false);
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
import {
|
||||
buildURL,
|
||||
combineURL,
|
||||
dynamicInterpolation,
|
||||
isAbsoluteURL,
|
||||
isDynamicURL,
|
||||
} from '../../src/helpers/url';
|
||||
|
||||
describe('对 src/helpers/url.ts 进行测试', () => {
|
||||
it('测试 buildURL() 执行结果是否符合预期', () => {
|
||||
expect(buildURL('/api')).toBe('/api');
|
||||
expect(buildURL('/api', {})).toBe('/api');
|
||||
expect(buildURL('/api#id=1', {})).toBe('/api');
|
||||
expect(
|
||||
buildURL('/api', {
|
||||
id: 1,
|
||||
}),
|
||||
).toBe('/api?id=1');
|
||||
expect(buildURL('/api', { id: 100 }, () => 'id=1')).toBe('/api?id=1');
|
||||
expect(
|
||||
buildURL('/api?sid=0', {
|
||||
id: 1,
|
||||
}),
|
||||
).toBe('/api?sid=0&id=1');
|
||||
expect(buildURL('/api?sid=0', { id: 100 }, () => 'id=1')).toBe(
|
||||
'/api?sid=0&id=1',
|
||||
);
|
||||
});
|
||||
|
||||
it('测试 combineURL() 执行结果是否符合预期', () => {
|
||||
expect(combineURL('https://www.server.com', 'api')).toBe(
|
||||
'https://www.server.com/api',
|
||||
);
|
||||
expect(combineURL('https://www.server.com/', '/api')).toBe(
|
||||
'https://www.server.com/api',
|
||||
);
|
||||
expect(combineURL('https://www.server.com:8080//', '//api//')).toBe(
|
||||
'https://www.server.com:8080/api/',
|
||||
);
|
||||
});
|
||||
|
||||
it('测试 dynamicInterpolation() 执行结果是否符合预期', () => {
|
||||
expect(
|
||||
dynamicInterpolation('https://www.server.com/api/user/:id', {
|
||||
id: 1,
|
||||
name: 'user',
|
||||
}),
|
||||
).toBe('https://www.server.com/api/user/1');
|
||||
expect(
|
||||
dynamicInterpolation('https://www.server.com:8080/api/user/:id', {
|
||||
id: 1,
|
||||
name: 'user',
|
||||
}),
|
||||
).toBe('https://www.server.com:8080/api/user/1');
|
||||
expect(
|
||||
dynamicInterpolation('https://www.server.com/api/user/:id/:name', {
|
||||
id: 1,
|
||||
}),
|
||||
).toBe('https://www.server.com/api/user/1/undefined');
|
||||
expect(
|
||||
dynamicInterpolation('https://www.server.com/api/user/:id:name', {
|
||||
id: 1,
|
||||
}),
|
||||
).toBe('https://www.server.com/api/user/1undefined');
|
||||
});
|
||||
|
||||
it('测试 isAbsoluteURL() 执行结果是否符合预期', () => {
|
||||
expect(isAbsoluteURL('')).toBe(false);
|
||||
expect(isAbsoluteURL('/api')).toBe(false);
|
||||
expect(isAbsoluteURL('http:')).toBe(false);
|
||||
expect(isAbsoluteURL('//file')).toBe(true);
|
||||
expect(isAbsoluteURL('https://www.server.com')).toBe(true);
|
||||
expect(isAbsoluteURL('file://')).toBe(true);
|
||||
});
|
||||
|
||||
it('测试 isDynamicURL() 执行结果是否符合预期', () => {
|
||||
expect(isDynamicURL('')).toBe(false);
|
||||
expect(isDynamicURL(':id')).toBe(true);
|
||||
expect(isDynamicURL(':8080')).toBe(false);
|
||||
expect(isDynamicURL('/:id')).toBe(true);
|
||||
expect(isDynamicURL('/:8080')).toBe(false);
|
||||
expect(isDynamicURL('https://www.server.com:8080')).toBe(false);
|
||||
expect(isDynamicURL('/api')).toBe(false);
|
||||
expect(isDynamicURL('/api:id')).toBe(true);
|
||||
expect(isDynamicURL('/api/:id')).toBe(true);
|
||||
});
|
||||
});
|
|
@ -1,3 +1,4 @@
|
|||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
assert,
|
||||
deepMerge,
|
||||
|
@ -9,13 +10,13 @@ import {
|
|||
} from '../../src/helpers/utils';
|
||||
|
||||
describe('对 src/helpers/utils.ts 进行测试', () => {
|
||||
it('测试 assert() 执行结果是否符合预期', () => {
|
||||
test('测试 assert() 是否符合预期', () => {
|
||||
expect(assert(true, '')).toBeUndefined();
|
||||
expect(() => assert(false, '')).toThrow();
|
||||
expect(() => assert(false, 'msg')).toThrowError('[axios-miniprogram]: msg');
|
||||
});
|
||||
|
||||
it('测试 deepMerge() 执行结果是否符合预期', () => {
|
||||
test('测试 deepMerge() 是否符合预期', () => {
|
||||
expect(deepMerge({})).toEqual({});
|
||||
expect(deepMerge({ a: 1 }, { b: 2 })).toEqual({ a: 1, b: 2 });
|
||||
expect(deepMerge({ a: { a: 1 } }, { a: { b: 2 } })).toEqual({
|
||||
|
@ -29,19 +30,19 @@ describe('对 src/helpers/utils.ts 进行测试', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('测试 omit() 执行结果是否符合预期', () => {
|
||||
test('测试 omit() 是否符合预期', () => {
|
||||
expect(omit({})).toEqual({});
|
||||
expect(omit({ a: 1, b: 1 }, 'a')).toEqual({ b: 1 });
|
||||
expect(omit({ a: 1, b: 1 }, 'a', 'b')).toEqual({});
|
||||
});
|
||||
|
||||
it('测试 pick() 执行结果是否符合预期', () => {
|
||||
test('测试 pick() 是否符合预期', () => {
|
||||
expect(pick({})).toEqual({});
|
||||
expect(pick({ a: 1, b: 1 }, 'a')).toEqual({ a: 1 });
|
||||
expect(pick({ a: 1, b: 1 }, 'a', 'b')).toEqual({ a: 1, b: 1 });
|
||||
});
|
||||
|
||||
it('测试 throwError() 执行结果是否符合预期', () => {
|
||||
test('测试 throwError() 是否符合预期', () => {
|
||||
expect(() => throwError('')).toThrowError('[axios-miniprogram]: ');
|
||||
expect(() => throwError('msg')).toThrowError('[axios-miniprogram]: msg');
|
||||
expect(() => throwError(' msg ')).toThrowError(
|
||||
|
@ -49,14 +50,14 @@ describe('对 src/helpers/utils.ts 进行测试', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('测试 toLowerCase() 执行结果是否符合预期', () => {
|
||||
test('测试 toLowerCase() 是否符合预期', () => {
|
||||
expect(toLowerCase('', 'GET')).toBe('');
|
||||
expect(toLowerCase(undefined, 'GET')).toBe('get');
|
||||
expect(toLowerCase('GET', '')).toBe('get');
|
||||
expect(toLowerCase('Get', '')).toBe('get');
|
||||
});
|
||||
|
||||
it('测试 toUpperCase() 执行结果是否符合预期', () => {
|
||||
test('测试 toUpperCase() 是否符合预期', () => {
|
||||
expect(toUpperCase('', 'get')).toBe('');
|
||||
expect(toUpperCase(undefined, 'get')).toBe('GET');
|
||||
expect(toUpperCase('get', '')).toBe('GET');
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"strict": true,
|
||||
"noEmit": true
|
||||
"noEmit": true,
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["./src", "./test", "./global.d.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
|
|
Loading…
Reference in New Issue