@lx-frontend/multi-ajax 0.2.1 → 0.2.2-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/build/scripts/patch-axios-post-install.js +1 -6
- package/build/utils.js +12 -0
- package/build/webpackPlugin/webpack4-replace-plugin.js +51 -0
- package/lib/adapters/index.js +1 -1
- package/lib/adapters/wx-adapter.js +1 -1
- package/lib/cancelLastSameRequest.js +1 -1
- package/lib/canceller.js +1 -1
- package/lib/compatibleMethods.js +1 -1
- package/lib/duplicateRequestPrevent.js +1 -1
- package/lib/helpers.js +1 -1
- package/lib/index.js +1 -1
- package/lib/methods.js +1 -1
- package/lib/types.js +1 -1
- package/lib/utils.js +1 -1
- package/package.json +1 -1
- package/coverage/coverage-summary.json +0 -12
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -131
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/adapters/index.html +0 -131
- package/coverage/lcov-report/src/adapters/index.ts.html +0 -100
- package/coverage/lcov-report/src/adapters/wx-adapter.ts.html +0 -436
- package/coverage/lcov-report/src/cancelLastSameRequest.ts.html +0 -211
- package/coverage/lcov-report/src/canceller.ts.html +0 -265
- package/coverage/lcov-report/src/compatibleMethods.ts.html +0 -301
- package/coverage/lcov-report/src/duplicateRequestPrevent.ts.html +0 -151
- package/coverage/lcov-report/src/helpers.ts.html +0 -319
- package/coverage/lcov-report/src/index.html +0 -221
- package/coverage/lcov-report/src/index.ts.html +0 -211
- package/coverage/lcov-report/src/methods.ts.html +0 -475
- package/coverage/lcov-report/src/utils.ts.html +0 -334
- package/coverage/lcov.info +0 -610
- package/lib/adapters/index.js.map +0 -1
- package/lib/adapters/wx-adapter.js.map +0 -1
- package/lib/cancelLastSameRequest.js.map +0 -1
- package/lib/canceller.js.map +0 -1
- package/lib/compatibleMethods.js.map +0 -1
- package/lib/duplicateRequestPrevent.js.map +0 -1
- package/lib/helpers.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/methods.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/utils.js.map +0 -1
- package/tests/duplicateRequestPrevent.test.ts +0 -39
- package/tests/helpers.test.ts +0 -73
- package/tests/index.test.ts +0 -877
- package/tests/jest-setup.ts +0 -4
- package/tests/utils.test.ts +0 -68
- package/tsconfig.json +0 -17
package/tests/helpers.test.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { addInstanceExtendMethod, normalizeConfig, proxyAxiosMethods } from '../lib/helpers'
|
|
2
|
-
import qs = require('qs')
|
|
3
|
-
import type { AjaxInstance } from '../lib/types.d'
|
|
4
|
-
|
|
5
|
-
describe('标准化Ajax配置函数normalizeConfig测试', () => {
|
|
6
|
-
const baseConfig = {
|
|
7
|
-
headers: {},
|
|
8
|
-
data: {
|
|
9
|
-
data1: 1,
|
|
10
|
-
data2: false,
|
|
11
|
-
data3: 'str'
|
|
12
|
-
},
|
|
13
|
-
baseUrl: 'https://base/url',
|
|
14
|
-
sendFormData: false
|
|
15
|
-
}
|
|
16
|
-
const context = {
|
|
17
|
-
$options: {}
|
|
18
|
-
}
|
|
19
|
-
test('发送JSON格式数据', () => {
|
|
20
|
-
const newConfig = normalizeConfig(context as AjaxInstance, baseConfig)
|
|
21
|
-
expect(newConfig.headers['content-type']).toBe('application/json')
|
|
22
|
-
})
|
|
23
|
-
test('发送FormData格式数据', () => {
|
|
24
|
-
const copyConfig = {
|
|
25
|
-
...baseConfig,
|
|
26
|
-
sendFormData: true
|
|
27
|
-
}
|
|
28
|
-
const newConfig = normalizeConfig(context as AjaxInstance, copyConfig)
|
|
29
|
-
expect(newConfig.headers['content-type']).toBe('application/x-www-form-urlencoded')
|
|
30
|
-
expect(newConfig.data).toEqual(qs.stringify(copyConfig.data))
|
|
31
|
-
})
|
|
32
|
-
test('baseUrl和baseURL兼容', () => {
|
|
33
|
-
const newConfig = normalizeConfig(context as AjaxInstance, baseConfig)
|
|
34
|
-
expect(newConfig.baseURL).not.toBeUndefined()
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
describe('设置代理函数proxyAxiosMethods测试', () => {
|
|
39
|
-
let target: Record<string, any>, source: { request: any, interceptors: any}
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
target = {} as any
|
|
42
|
-
source = {
|
|
43
|
-
request: {a: 1},
|
|
44
|
-
interceptors: {b: 1}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
test('代理测试', () => {
|
|
48
|
-
proxyAxiosMethods(target, source)
|
|
49
|
-
expect(target.request).not.toBeUndefined()
|
|
50
|
-
expect(target.interceptors).not.toBeUndefined()
|
|
51
|
-
})
|
|
52
|
-
test('不可写测试', () => {
|
|
53
|
-
proxyAxiosMethods(target, source)
|
|
54
|
-
expect(() => {target.request = {}}).toThrow()
|
|
55
|
-
expect(() => {target.interceptors = {}}).toThrow()
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
describe('addInstanceExtendMethod测试', () => {
|
|
60
|
-
test('添加extend函数测试', () => {
|
|
61
|
-
const ctx: any = {}
|
|
62
|
-
const source = {
|
|
63
|
-
testFn: jest.fn(),
|
|
64
|
-
testAttr: 'tst'
|
|
65
|
-
}
|
|
66
|
-
addInstanceExtendMethod(ctx)
|
|
67
|
-
expect(typeof ctx.extend).toBe('function')
|
|
68
|
-
ctx.extend(source)
|
|
69
|
-
ctx.testFn()
|
|
70
|
-
expect(source.testFn).toHaveBeenCalled()
|
|
71
|
-
expect(ctx.testAttr).toBe('tst')
|
|
72
|
-
})
|
|
73
|
-
})
|