@tarojs/taro-rn 4.0.1 → 4.0.3-alpha.0
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/LICENSE +8 -8
- package/apiList.js +31 -31
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/lib/Mask.js +2 -2
- package/dist/lib/Mask.js.map +1 -1
- package/dist/lib/Popup.js +20 -13
- package/dist/lib/Popup.js.map +1 -1
- package/dist/lib/StyleSheet.js +1 -1
- package/dist/lib/StyleSheet.js.map +1 -1
- package/dist/lib/accelerometer.js +1 -1
- package/dist/lib/accelerometer.js.map +1 -1
- package/dist/lib/chooseImage/index.js +3 -151
- package/dist/lib/chooseImage/index.js.map +1 -1
- package/dist/lib/chooseMedia/index.js +19 -0
- package/dist/lib/chooseMedia/index.js.map +1 -0
- package/dist/lib/chooseVideo/index.js +1 -55
- package/dist/lib/chooseVideo/index.js.map +1 -1
- package/dist/lib/clearStorage/index.js +2 -2
- package/dist/lib/clearStorage/index.js.map +1 -1
- package/dist/lib/compressImage/index.js +1 -1
- package/dist/lib/compressImage/index.js.map +1 -1
- package/dist/lib/connectSocket/index.js.map +1 -1
- package/dist/lib/connectSocket/socketTask.js +1 -1
- package/dist/lib/connectSocket/socketTask.js.map +1 -1
- package/dist/lib/createCameraContext/index.js +3 -3
- package/dist/lib/createCameraContext/index.js.map +1 -1
- package/dist/lib/createInnerAudioContext/index.js +2 -2
- package/dist/lib/createInnerAudioContext/index.js.map +1 -1
- package/dist/lib/createVideoContext/index.js +7 -7
- package/dist/lib/createVideoContext/index.js.map +1 -1
- package/dist/lib/deviceMotion.js +2 -2
- package/dist/lib/deviceMotion.js.map +1 -1
- package/dist/lib/file.js +4 -4
- package/dist/lib/file.js.map +1 -1
- package/dist/lib/getAppBaseInfo/index.js +2 -2
- package/dist/lib/getAppBaseInfo/index.js.map +1 -1
- package/dist/lib/getClipboardData/index.js.map +1 -1
- package/dist/lib/getImageInfo/index.js +2 -2
- package/dist/lib/getImageInfo/index.js.map +1 -1
- package/dist/lib/getLocation/index.js +8 -4
- package/dist/lib/getLocation/index.js.map +1 -1
- package/dist/lib/getRecorderManager/index.js +11 -6
- package/dist/lib/getRecorderManager/index.js.map +1 -1
- package/dist/lib/getStorage/index.js.map +1 -1
- package/dist/lib/getStorageInfo/index.js +2 -2
- package/dist/lib/getStorageInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfo/index.js +1 -1
- package/dist/lib/getSystemInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfoSync/index.js +2 -2
- package/dist/lib/getSystemInfoSync/index.js.map +1 -1
- package/dist/lib/gyroscope.js +1 -1
- package/dist/lib/gyroscope.js.map +1 -1
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/keyboard.js +3 -3
- package/dist/lib/keyboard.js.map +1 -1
- package/dist/lib/location.js.map +1 -1
- package/dist/lib/makePhoneCall/index.js +1 -1
- package/dist/lib/makePhoneCall/index.js.map +1 -1
- package/dist/lib/media.js +61 -30
- package/dist/lib/media.js.map +1 -1
- package/dist/lib/network.js +1 -1
- package/dist/lib/network.js.map +1 -1
- package/dist/lib/offWindowResize/index.js.map +1 -1
- package/dist/lib/onWindowResize/index.js +1 -1
- package/dist/lib/onWindowResize/index.js.map +1 -1
- package/dist/lib/openUrl/index.js +1 -1
- package/dist/lib/openUrl/index.js.map +1 -1
- package/dist/lib/permission.js +6 -5
- package/dist/lib/permission.js.map +1 -1
- package/dist/lib/previewImage/index.js +3 -3
- package/dist/lib/previewImage/index.js.map +1 -1
- package/dist/lib/request/index.js +1 -1
- package/dist/lib/request/index.js.map +1 -1
- package/dist/lib/scanCode/index.js +23 -23
- package/dist/lib/scanCode/index.js.map +1 -1
- package/dist/lib/screen.js +2 -2
- package/dist/lib/screen.js.map +1 -1
- package/dist/lib/setClipboardData/index.js +2 -2
- package/dist/lib/setClipboardData/index.js.map +1 -1
- package/dist/lib/setKeepScreenOn/index.js +1 -1
- package/dist/lib/setKeepScreenOn/index.js.map +1 -1
- package/dist/lib/setStorage/index.js.map +1 -1
- package/dist/lib/showActionSheet/ActionSheet.js +11 -23
- package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
- package/dist/lib/showActionSheet/index.js +10 -24
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/lib/showModal/Dialog.js +22 -36
- package/dist/lib/showModal/Dialog.js.map +1 -1
- package/dist/lib/showModal/index.js.map +1 -1
- package/dist/lib/showModal/toast.js +6 -6
- package/dist/lib/showModal/toast.js.map +1 -1
- package/dist/lib/unsupportedApi.js +2 -4
- package/dist/lib/unsupportedApi.js.map +1 -1
- package/dist/lib/variable.js +1 -1
- package/dist/lib/variable.js.map +1 -1
- package/dist/lib/vibrate.js +1 -1
- package/dist/lib/vibrate.js.map +1 -1
- package/dist/lib/window.js.map +1 -1
- package/dist/utils/callbackManager.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/libList.js +1 -0
- package/package.json +70 -69
- package/src/api/index.ts +31 -31
- package/src/lib/ENV_TYPE/index.ts +1 -1
- package/src/lib/Mask.tsx +2 -2
- package/src/lib/Popup.tsx +26 -19
- package/src/lib/StyleSheet.ts +1 -1
- package/src/lib/accelerometer.ts +2 -1
- package/src/lib/arrayBufferToBase64/index.ts +1 -1
- package/src/lib/base64ToArrayBuffer/index.ts +1 -1
- package/src/lib/chooseImage/index.ts +3 -155
- package/src/lib/chooseMedia/index.ts +15 -0
- package/src/lib/chooseVideo/index.ts +1 -56
- package/src/lib/clearStorage/index.ts +1 -0
- package/src/lib/clearStorageSync/index.ts +1 -1
- package/src/lib/compressImage/index.ts +1 -0
- package/src/lib/connectSocket/socketTask.ts +7 -9
- package/src/lib/createCameraContext/index.ts +6 -4
- package/src/lib/createInnerAudioContext/index.ts +1 -0
- package/src/lib/createSelectorQuery/index.ts +1 -1
- package/src/lib/deviceMotion.ts +4 -3
- package/src/lib/file.ts +9 -8
- package/src/lib/getClipboardData/index.ts +1 -0
- package/src/lib/getEnv/index.ts +1 -1
- package/src/lib/getFileSystemManager/index.ts +1 -1
- package/src/lib/getLocation/index.ts +7 -2
- package/src/lib/getRecorderManager/index.ts +7 -2
- package/src/lib/getStorage/index.ts +1 -0
- package/src/lib/getStorageInfo/index.ts +1 -0
- package/src/lib/getStorageInfoSync/index.ts +1 -1
- package/src/lib/getStorageSync/index.ts +1 -1
- package/src/lib/getSystemInfo/index.ts +2 -2
- package/src/lib/getSystemInfoSync/index.ts +3 -3
- package/src/lib/gyroscope.ts +47 -46
- package/src/lib/index.ts +1 -0
- package/src/lib/keyboard.ts +5 -4
- package/src/lib/location.ts +6 -5
- package/src/lib/makePhoneCall/index.ts +2 -1
- package/src/lib/media.ts +83 -31
- package/src/lib/network.ts +5 -5
- package/src/lib/offLocationChange/index.ts +1 -1
- package/src/lib/offUserCaptureScreen/index.ts +1 -1
- package/src/lib/onLocationChange/index.ts +1 -1
- package/src/lib/onUserCaptureScreen/index.ts +1 -1
- package/src/lib/onWindowResize/index.ts +2 -2
- package/src/lib/openUrl/index.d.ts +23 -22
- package/src/lib/openUrl/index.ts +2 -1
- package/src/lib/permission.ts +33 -25
- package/src/lib/previewImage/index.tsx +4 -3
- package/src/lib/removeStorageSync/index.ts +1 -1
- package/src/lib/request/index.ts +2 -2
- package/src/lib/scanCode/index.tsx +18 -16
- package/src/lib/screen.ts +1 -0
- package/src/lib/setClipboardData/index.ts +3 -2
- package/src/lib/setKeepScreenOn/index.ts +2 -1
- package/src/lib/setStorage/index.ts +1 -0
- package/src/lib/setStorageSync/index.ts +1 -1
- package/src/lib/showActionSheet/ActionSheet.tsx +34 -43
- package/src/lib/showActionSheet/index.tsx +11 -36
- package/src/lib/showModal/Dialog.tsx +34 -39
- package/src/lib/showModal/index.tsx +1 -0
- package/src/lib/showModal/toast.tsx +14 -13
- package/src/lib/startGyroscope/index.ts +1 -1
- package/src/lib/startLocationUpdate/index.ts +1 -1
- package/src/lib/unsupportedApi.ts +3 -5
- package/src/lib/vibrate.ts +11 -10
- package/src/lib/window.ts +3 -2
- package/src/utils/callbackManager.ts +5 -5
- package/src/utils/index.ts +4 -4
- package/{src/types → types}/vue/index.d.ts +2 -3
- package/dist/setup.js +0 -75
- package/dist/setup.js.map +0 -1
- package/src/__tests__/__mock__/mockAsyncStorage.js +0 -47
- package/src/__tests__/__mock__/mockClipboard.js +0 -15
- package/src/__tests__/__mock__/mockNavigator.js +0 -20
- package/src/__tests__/__mock__/mockNetwork.js +0 -59
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +0 -16
- package/src/__tests__/__mock__/mockRNCGeolocation.js +0 -13
- package/src/__tests__/__mock__/mockVibrate.js +0 -6
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +0 -125
- package/src/__tests__/clipboard.test.ts +0 -88
- package/src/__tests__/deviceMotion.test.ts +0 -37
- package/src/__tests__/geolocation.test.ts +0 -60
- package/src/__tests__/interactive.test.tsx +0 -101
- package/src/__tests__/keyboard.test.ts +0 -46
- package/src/__tests__/media.test.ts +0 -104
- package/src/__tests__/network.test.ts +0 -57
- package/src/__tests__/others.test.ts +0 -25
- package/src/__tests__/phone.test.ts +0 -31
- package/src/__tests__/request.test.ts +0 -146
- package/src/__tests__/scanCode.test.tsx +0 -14
- package/src/__tests__/storage.test.ts +0 -202
- package/src/__tests__/system.test.ts +0 -69
- package/src/__tests__/vibrate.test.ts +0 -27
- package/src/__tests__/websocket.test.ts +0 -169
- package/src/setup.ts +0 -84
- /package/{src/types → types}/definition.d.ts +0 -0
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import * as request from '../lib/request'
|
|
2
|
-
|
|
3
|
-
const Taro = Object.assign({}, request)
|
|
4
|
-
|
|
5
|
-
describe('request', () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
const fetch = jest.fn(() => {
|
|
8
|
-
return new Promise((resolve) => {
|
|
9
|
-
resolve({
|
|
10
|
-
ok: true,
|
|
11
|
-
status: 200,
|
|
12
|
-
headers: {},
|
|
13
|
-
json: () => {
|
|
14
|
-
return Promise.resolve({ data: 'calorie' })
|
|
15
|
-
},
|
|
16
|
-
text: () => {
|
|
17
|
-
return Promise.resolve('卡路里卡路里卡路')
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
global.fetch = fetch
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
describe('request', () => {
|
|
27
|
-
// taro@3 不支持
|
|
28
|
-
// test('直接传入url时能正常返回', async () => {
|
|
29
|
-
// const expectData = { data: 'calorie' }
|
|
30
|
-
|
|
31
|
-
// const url = 'https://test.taro.com/v1'
|
|
32
|
-
// const res = await Taro.request(url)
|
|
33
|
-
|
|
34
|
-
// expect(res.data).toEqual(expectData)
|
|
35
|
-
// })
|
|
36
|
-
|
|
37
|
-
test('接口数据返回json对象', async () => {
|
|
38
|
-
const expectData = { data: 'calorie' }
|
|
39
|
-
|
|
40
|
-
const url = 'https://test.taro.com/v1'
|
|
41
|
-
const options = {
|
|
42
|
-
url,
|
|
43
|
-
dataType: 'json'
|
|
44
|
-
}
|
|
45
|
-
const res = await Taro.request(options)
|
|
46
|
-
|
|
47
|
-
expect(res.data).toEqual(expectData)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('接口数据返回text', async () => {
|
|
51
|
-
const expectData = { data: 'calorie' }
|
|
52
|
-
|
|
53
|
-
const url = 'https://test.taro.com/v1'
|
|
54
|
-
const options = {
|
|
55
|
-
url,
|
|
56
|
-
responseType: 'text'
|
|
57
|
-
}
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
const res = await Taro.request(options)
|
|
60
|
-
expect(res.data).toEqual(expectData)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('RN请求入参同于微信小程序', () => {
|
|
64
|
-
const url = 'https://test.taro.com/v1'
|
|
65
|
-
const expectData = JSON.stringify({ data: 'calorie' })
|
|
66
|
-
const options = {
|
|
67
|
-
url,
|
|
68
|
-
dataType: 'json',
|
|
69
|
-
complete: jest.fn(),
|
|
70
|
-
success: (res) => {
|
|
71
|
-
expect(JSON.stringify(res.data)).toMatch(expectData)
|
|
72
|
-
},
|
|
73
|
-
fail: jest.fn()
|
|
74
|
-
}
|
|
75
|
-
Taro.request(options)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
test('数据被序列化', async () => {
|
|
79
|
-
const fetch = jest.fn((url, params) => {
|
|
80
|
-
return new Promise((resolve) => {
|
|
81
|
-
resolve({
|
|
82
|
-
ok: true,
|
|
83
|
-
status: 200,
|
|
84
|
-
headers: {},
|
|
85
|
-
json: () => {
|
|
86
|
-
return Promise.resolve({ url, params })
|
|
87
|
-
},
|
|
88
|
-
text: () => {
|
|
89
|
-
return Promise.resolve('卡路里卡路里卡路')
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
// @ts-ignore
|
|
95
|
-
global.fetch = fetch
|
|
96
|
-
|
|
97
|
-
const url = 'https://test.taro.com/v1'
|
|
98
|
-
const optionsOne = {
|
|
99
|
-
url,
|
|
100
|
-
dataType: 'json',
|
|
101
|
-
data: {
|
|
102
|
-
a: 1
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const expectUrl = `https://test.taro.com/v1?${encodeURIComponent('a')}=${encodeURIComponent(1)}`
|
|
107
|
-
// @ts-ignore
|
|
108
|
-
const res = await Taro.request(optionsOne)
|
|
109
|
-
expect(res.data.url).toMatch(expectUrl)
|
|
110
|
-
|
|
111
|
-
const optionsTwo = {
|
|
112
|
-
url,
|
|
113
|
-
method: 'post',
|
|
114
|
-
dataType: 'json',
|
|
115
|
-
header: {
|
|
116
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
117
|
-
},
|
|
118
|
-
data: {
|
|
119
|
-
a: 1
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const expectBodyOne = JSON.stringify({ a: 1 })
|
|
124
|
-
// @ts-ignore
|
|
125
|
-
const resTwo = await Taro.request(optionsTwo)
|
|
126
|
-
expect(resTwo.data.params.body).toMatch(expectBodyOne)
|
|
127
|
-
|
|
128
|
-
const optionsThree = {
|
|
129
|
-
url,
|
|
130
|
-
method: 'POST',
|
|
131
|
-
dataType: 'json',
|
|
132
|
-
header: {
|
|
133
|
-
'content-type': 'application/x-www-form-urlencoded'
|
|
134
|
-
},
|
|
135
|
-
data: {
|
|
136
|
-
a: 1
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const expectBodyTwo = `${encodeURIComponent('a')}=${encodeURIComponent(1)}`
|
|
141
|
-
// @ts-ignore
|
|
142
|
-
const resThree = await Taro.request(optionsThree)
|
|
143
|
-
expect(resThree.data.params.body).toMatch(expectBodyTwo)
|
|
144
|
-
})
|
|
145
|
-
})
|
|
146
|
-
})
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { RootSiblingParent } from 'react-native-root-siblings';
|
|
3
|
-
import { render, waitFor } from '@testing-library/react-native';
|
|
4
|
-
import { scanCode } from '../lib/scanCode'
|
|
5
|
-
|
|
6
|
-
describe('scanCode', () => {
|
|
7
|
-
it('should render scanCode success', async () => {
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
const { toJSON, getByLabelText } = render(<RootSiblingParent />)
|
|
10
|
-
scanCode()
|
|
11
|
-
await waitFor(() => getByLabelText('Close'));
|
|
12
|
-
expect(toJSON()).toMatchSnapshot()
|
|
13
|
-
})
|
|
14
|
-
})
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
-
import { setStorage } from '../lib/setStorage'
|
|
3
|
-
import { getStorage } from '../lib/getStorage'
|
|
4
|
-
import { clearStorage } from '../lib/clearStorage'
|
|
5
|
-
import { getStorageInfo } from '../lib/getStorageInfo'
|
|
6
|
-
import { removeStorage } from '../lib/removeStorage'
|
|
7
|
-
|
|
8
|
-
const Taro = {
|
|
9
|
-
setStorage,
|
|
10
|
-
getStorage,
|
|
11
|
-
clearStorage,
|
|
12
|
-
getStorageInfo,
|
|
13
|
-
removeStorage,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// NativeModules.RNCAsyncStorage setup mock
|
|
17
|
-
describe('storage', () => {
|
|
18
|
-
describe('setStorage', () => {
|
|
19
|
-
test('should set value into storage', async () => {
|
|
20
|
-
await Taro.clearStorage({})
|
|
21
|
-
const key = 'bar'
|
|
22
|
-
const data = 'foo'
|
|
23
|
-
const success = jest.fn()
|
|
24
|
-
const fail = jest.fn()
|
|
25
|
-
const complete = jest.fn()
|
|
26
|
-
|
|
27
|
-
const res = await Taro.setStorage({
|
|
28
|
-
key,
|
|
29
|
-
data,
|
|
30
|
-
success,
|
|
31
|
-
fail,
|
|
32
|
-
complete
|
|
33
|
-
})
|
|
34
|
-
const expectMsg = 'setStorage:ok'
|
|
35
|
-
|
|
36
|
-
expect.assertions(7)
|
|
37
|
-
|
|
38
|
-
expect(success.mock.calls.length).toBe(1)
|
|
39
|
-
expect(success.mock.calls[0][0]).toEqual({ errMsg: expectMsg })
|
|
40
|
-
expect(fail.mock.calls.length).toBe(0)
|
|
41
|
-
expect(complete.mock.calls.length).toBe(1)
|
|
42
|
-
expect(complete.mock.calls[0][0]).toEqual({ errMsg: expectMsg })
|
|
43
|
-
expect(res.errMsg).toMatch(expectMsg)
|
|
44
|
-
|
|
45
|
-
const getData = await AsyncStorage.getItem(key) || ''
|
|
46
|
-
expect(JSON.parse(getData)).toBe(data)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
test('should fail when error occur', async () => {
|
|
50
|
-
await Taro.clearStorage({})
|
|
51
|
-
const data = {}
|
|
52
|
-
const success = jest.fn().mockImplementation(() => {
|
|
53
|
-
throw new Error('setStorage:fail')
|
|
54
|
-
})
|
|
55
|
-
const fail = jest.fn()
|
|
56
|
-
const complete = jest.fn()
|
|
57
|
-
|
|
58
|
-
expect.assertions(4)
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
return Taro.setStorage({
|
|
61
|
-
data,
|
|
62
|
-
success,
|
|
63
|
-
fail,
|
|
64
|
-
complete
|
|
65
|
-
}).catch(err => {
|
|
66
|
-
const expectErrMsg = err.errMsg
|
|
67
|
-
expect(fail.mock.calls.length).toBe(1)
|
|
68
|
-
expect(fail.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
|
|
69
|
-
expect(complete.mock.calls.length).toBe(1)
|
|
70
|
-
expect(complete.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
describe('getStorage', () => {
|
|
76
|
-
test('should get value from storage by key', async () => {
|
|
77
|
-
await Taro.clearStorage({})
|
|
78
|
-
const key = 'bar'
|
|
79
|
-
const data = 'foo'
|
|
80
|
-
const success = jest.fn()
|
|
81
|
-
const fail = jest.fn()
|
|
82
|
-
const complete = jest.fn()
|
|
83
|
-
|
|
84
|
-
await AsyncStorage.setItem(key, JSON.stringify(data))
|
|
85
|
-
const res = await Taro.getStorage({
|
|
86
|
-
key,
|
|
87
|
-
success,
|
|
88
|
-
fail,
|
|
89
|
-
complete
|
|
90
|
-
})
|
|
91
|
-
const expectMsg = 'getStorage:ok'
|
|
92
|
-
|
|
93
|
-
expect.assertions(7)
|
|
94
|
-
|
|
95
|
-
expect(success.mock.calls.length).toBe(1)
|
|
96
|
-
expect(success.mock.calls[0][0]).toEqual(res)
|
|
97
|
-
expect(fail.mock.calls.length).toBe(0)
|
|
98
|
-
expect(complete.mock.calls.length).toBe(1)
|
|
99
|
-
expect(complete.mock.calls[0][0]).toEqual(res)
|
|
100
|
-
expect(res.errMsg).toMatch(expectMsg)
|
|
101
|
-
expect(res.data).toBe(data)
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
describe('removeStorage', () => {
|
|
106
|
-
test('能根据key删除Storage里的值', async () => {
|
|
107
|
-
await Taro.clearStorage({})
|
|
108
|
-
const key = 'bar'
|
|
109
|
-
const data = 'foo'
|
|
110
|
-
const success = jest.fn()
|
|
111
|
-
const fail = jest.fn()
|
|
112
|
-
const complete = jest.fn()
|
|
113
|
-
|
|
114
|
-
await AsyncStorage.setItem(key, JSON.stringify(data))
|
|
115
|
-
const getData = await AsyncStorage.getItem(key) || ''
|
|
116
|
-
|
|
117
|
-
expect(JSON.parse(getData)).toBe(data)
|
|
118
|
-
|
|
119
|
-
const res = await Taro.removeStorage({
|
|
120
|
-
key,
|
|
121
|
-
success,
|
|
122
|
-
fail,
|
|
123
|
-
complete
|
|
124
|
-
})
|
|
125
|
-
const expectMsg = 'removeStorage:ok'
|
|
126
|
-
|
|
127
|
-
expect.assertions(8)
|
|
128
|
-
|
|
129
|
-
expect(success.mock.calls.length).toBe(1)
|
|
130
|
-
expect(success.mock.calls[0][0]).toEqual(res)
|
|
131
|
-
expect(fail.mock.calls.length).toBe(0)
|
|
132
|
-
expect(complete.mock.calls.length).toBe(1)
|
|
133
|
-
expect(complete.mock.calls[0][0]).toEqual(res)
|
|
134
|
-
expect(res.errMsg).toMatch(expectMsg)
|
|
135
|
-
// @ts-ignore
|
|
136
|
-
expect(res.data).toBeUndefined()
|
|
137
|
-
})
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
describe('getStorageInfo', () => {
|
|
141
|
-
test('获得正确的StorageInfo', async () => {
|
|
142
|
-
await Taro.clearStorage({})
|
|
143
|
-
const key1 = 'bar'
|
|
144
|
-
const key2 = 'foo'
|
|
145
|
-
const data = 'data'
|
|
146
|
-
const success = jest.fn()
|
|
147
|
-
const fail = jest.fn()
|
|
148
|
-
const complete = jest.fn()
|
|
149
|
-
|
|
150
|
-
await AsyncStorage.setItem(key1, JSON.stringify(data))
|
|
151
|
-
await AsyncStorage.setItem(key2, JSON.stringify(data))
|
|
152
|
-
|
|
153
|
-
const res = await Taro.getStorageInfo({
|
|
154
|
-
success,
|
|
155
|
-
fail,
|
|
156
|
-
complete
|
|
157
|
-
})
|
|
158
|
-
const expectMsg = 'getStorageInfo:ok'
|
|
159
|
-
|
|
160
|
-
expect.assertions(9)
|
|
161
|
-
|
|
162
|
-
expect(success.mock.calls.length).toBe(1)
|
|
163
|
-
expect(success.mock.calls[0][0]).toEqual(res)
|
|
164
|
-
expect(fail.mock.calls.length).toBe(0)
|
|
165
|
-
expect(complete.mock.calls.length).toBe(1)
|
|
166
|
-
expect(complete.mock.calls[0][0]).toEqual(res)
|
|
167
|
-
expect(res.errMsg).toMatch(expectMsg)
|
|
168
|
-
// @ts-ignore
|
|
169
|
-
expect(res.keys).toEqual([key1, key2])
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
expect(res.currentSize).toBe(+(12 / 1024).toFixed(2))
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
expect(res.limitSize).toBe(Infinity)
|
|
174
|
-
})
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
describe('clearStorage', () => {
|
|
178
|
-
test('clearStorage能清楚所有的Storage', async () => {
|
|
179
|
-
await Taro.clearStorage({})
|
|
180
|
-
const key1 = 'bar'
|
|
181
|
-
const key2 = 'foo'
|
|
182
|
-
const data = 'data'
|
|
183
|
-
|
|
184
|
-
await AsyncStorage.setItem(key1, JSON.stringify(data))
|
|
185
|
-
await AsyncStorage.setItem(key2, JSON.stringify(data))
|
|
186
|
-
|
|
187
|
-
const getData1 = await AsyncStorage.getItem(key1) || ''
|
|
188
|
-
const getData2 = await AsyncStorage.getItem(key2) || ''
|
|
189
|
-
|
|
190
|
-
expect(JSON.parse(getData1)).toBe(data)
|
|
191
|
-
expect(JSON.parse(getData2)).toBe(data)
|
|
192
|
-
|
|
193
|
-
await Taro.clearStorage({})
|
|
194
|
-
|
|
195
|
-
const res = await AsyncStorage.getAllKeys()
|
|
196
|
-
|
|
197
|
-
expect.assertions(3)
|
|
198
|
-
|
|
199
|
-
expect(res).toEqual([])
|
|
200
|
-
})
|
|
201
|
-
})
|
|
202
|
-
})
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { getSystemInfo } from '../lib/getSystemInfo'
|
|
2
|
-
import { getSystemInfoSync } from '../lib/getSystemInfoSync'
|
|
3
|
-
|
|
4
|
-
const Taro = { getSystemInfo, getSystemInfoSync }
|
|
5
|
-
|
|
6
|
-
describe('system', () => {
|
|
7
|
-
describe('getSystemInfoSync', () => {
|
|
8
|
-
test('能同步返回正确的系统信息', () => {
|
|
9
|
-
const expectRes = {
|
|
10
|
-
brand: expect.any(String),
|
|
11
|
-
model: expect.any(String),
|
|
12
|
-
pixelRatio: expect.any(Number),
|
|
13
|
-
safeArea: expect.any(Object),
|
|
14
|
-
screenWidth: expect.any(Number),
|
|
15
|
-
screenHeight: expect.any(Number),
|
|
16
|
-
windowWidth: expect.any(Number),
|
|
17
|
-
windowHeight: expect.any(Number),
|
|
18
|
-
statusBarHeight: expect.any(Number),
|
|
19
|
-
language: null,
|
|
20
|
-
version: expect.any(String),
|
|
21
|
-
system: expect.any(String),
|
|
22
|
-
platform: expect.any(String),
|
|
23
|
-
fontSizeSetting: expect.any(Number),
|
|
24
|
-
SDKVersion: null
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const res = Taro.getSystemInfoSync()
|
|
28
|
-
expect(res).toEqual(expect.objectContaining(expectRes))
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
describe('getSystemInfo', () => {
|
|
33
|
-
test('能异步返回正确的系统信息', () => {
|
|
34
|
-
const success = jest.fn()
|
|
35
|
-
const fail = jest.fn()
|
|
36
|
-
const complete = jest.fn()
|
|
37
|
-
const expectRes = {
|
|
38
|
-
brand: expect.any(String),
|
|
39
|
-
model: expect.any(String),
|
|
40
|
-
pixelRatio: expect.any(Number),
|
|
41
|
-
safeArea: expect.any(Object),
|
|
42
|
-
screenWidth: expect.any(Number),
|
|
43
|
-
screenHeight: expect.any(Number),
|
|
44
|
-
windowWidth: expect.any(Number),
|
|
45
|
-
windowHeight: expect.any(Number),
|
|
46
|
-
statusBarHeight: expect.any(Number),
|
|
47
|
-
language: null,
|
|
48
|
-
version: expect.any(String),
|
|
49
|
-
system: expect.any(String),
|
|
50
|
-
platform: expect.any(String),
|
|
51
|
-
fontSizeSetting: expect.any(Number),
|
|
52
|
-
SDKVersion: null
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
expect.assertions(4)
|
|
56
|
-
|
|
57
|
-
return Taro.getSystemInfo({
|
|
58
|
-
success,
|
|
59
|
-
fail,
|
|
60
|
-
complete
|
|
61
|
-
}).then((res) => {
|
|
62
|
-
expect(success.mock.calls.length).toBe(1)
|
|
63
|
-
expect(fail.mock.calls.length).toBe(0)
|
|
64
|
-
expect(complete.mock.calls.length).toBe(1)
|
|
65
|
-
expect(res).toEqual(expect.objectContaining(expectRes))
|
|
66
|
-
})
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
})
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as vibrate from '../lib/vibrate'
|
|
2
|
-
|
|
3
|
-
const Taro = Object.assign({}, vibrate)
|
|
4
|
-
|
|
5
|
-
describe('vibrate', () => {
|
|
6
|
-
describe('vibrateShort', () => {
|
|
7
|
-
test('能正常震动', () => {
|
|
8
|
-
const expectMsg = 'vibrateShort:ok'
|
|
9
|
-
|
|
10
|
-
expect.assertions(1)
|
|
11
|
-
return Taro.vibrateShort().then((res) => {
|
|
12
|
-
expect(res.errMsg).toMatch(expectMsg)
|
|
13
|
-
})
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
describe('vibrateLong', () => {
|
|
18
|
-
test('能正常震动', () => {
|
|
19
|
-
const expectMsg = 'vibrateLong:ok'
|
|
20
|
-
|
|
21
|
-
expect.assertions(1)
|
|
22
|
-
return Taro.vibrateLong().then((res) => {
|
|
23
|
-
expect(res.errMsg).toMatch(expectMsg)
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
})
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { WebSocket, Server } from 'mock-socket'
|
|
2
|
-
import * as connectSocket from '../lib/connectSocket'
|
|
3
|
-
|
|
4
|
-
const Taro = Object.assign({}, connectSocket)
|
|
5
|
-
|
|
6
|
-
describe('websocket', () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
global.WebSocket = WebSocket
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
test('url should be string', () => {
|
|
13
|
-
const success = jest.fn()
|
|
14
|
-
const fail = jest.fn()
|
|
15
|
-
const complete = jest.fn()
|
|
16
|
-
|
|
17
|
-
expect.assertions(6)
|
|
18
|
-
|
|
19
|
-
return Taro.connectSocket({
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
url: {},
|
|
22
|
-
success,
|
|
23
|
-
fail,
|
|
24
|
-
complete
|
|
25
|
-
}).catch(err => {
|
|
26
|
-
const expectErrMsg = 'connectSocket:fail parameter error: parameter.url should be String'
|
|
27
|
-
expect(success.mock.calls.length).toBe(0)
|
|
28
|
-
expect(fail.mock.calls.length).toBe(1)
|
|
29
|
-
expect(fail.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
|
|
30
|
-
expect(complete.mock.calls.length).toBe(1)
|
|
31
|
-
expect(complete.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
|
|
32
|
-
expect(err.errMsg).toMatch(expectErrMsg)
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test('should not keep more than 2 connection', async () => {
|
|
37
|
-
const success = jest.fn()
|
|
38
|
-
const fail = jest.fn()
|
|
39
|
-
const complete = jest.fn()
|
|
40
|
-
|
|
41
|
-
expect.assertions(8)
|
|
42
|
-
|
|
43
|
-
const socketTaskOne = await Taro.connectSocket({ url: 'wss://localhost:8080', success })
|
|
44
|
-
expect(success.mock.calls[0][0])
|
|
45
|
-
.toEqual({ socketTaskId: 1, socketTask: socketTaskOne, errMsg: 'connectSocket:ok' })
|
|
46
|
-
|
|
47
|
-
const socketTaskTwo = await Taro.connectSocket({ url: 'wss://localhost:8090', success })
|
|
48
|
-
expect(success.mock.calls[1][0])
|
|
49
|
-
.toEqual({ socketTaskId: 2, socketTask: socketTaskTwo, errMsg: 'connectSocket:ok' })
|
|
50
|
-
|
|
51
|
-
await Taro.connectSocket({
|
|
52
|
-
url: 'wss://localhost:9080',
|
|
53
|
-
success,
|
|
54
|
-
complete,
|
|
55
|
-
fail
|
|
56
|
-
}).catch(err => {
|
|
57
|
-
const expectErrMsg = '同时最多发起 2 个 socket 请求,更多请参考文档。'
|
|
58
|
-
expect(success.mock.calls.length).toBe(2)
|
|
59
|
-
expect(fail.mock.calls.length).toBe(1)
|
|
60
|
-
expect(fail.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
|
|
61
|
-
expect(complete.mock.calls.length).toBe(1)
|
|
62
|
-
expect(complete.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
|
|
63
|
-
expect(err.errMsg).toMatch(expectErrMsg)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
socketTaskOne.close({})
|
|
67
|
-
socketTaskTwo.close({})
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
test('connection关闭的时候会重置总的socketTask数量', async () => {
|
|
71
|
-
const success = jest.fn()
|
|
72
|
-
const fail = jest.fn()
|
|
73
|
-
const complete = jest.fn()
|
|
74
|
-
|
|
75
|
-
expect.assertions(7)
|
|
76
|
-
|
|
77
|
-
const socketTaskOne = await Taro.connectSocket({ url: 'wss://localhost:8080', success })
|
|
78
|
-
expect(success.mock.calls.length).toBe(1)
|
|
79
|
-
socketTaskOne.close({})
|
|
80
|
-
|
|
81
|
-
const socketTaskTwo = await Taro.connectSocket({ url: 'wss://localhost:8090', success })
|
|
82
|
-
expect(success.mock.calls.length).toBe(2)
|
|
83
|
-
|
|
84
|
-
const socketTaskThree = await Taro.connectSocket({
|
|
85
|
-
url: 'wss://localhost:9080',
|
|
86
|
-
success,
|
|
87
|
-
complete,
|
|
88
|
-
fail
|
|
89
|
-
})
|
|
90
|
-
expect(success.mock.calls.length).toBe(3)
|
|
91
|
-
expect(fail.mock.calls.length).toBe(0)
|
|
92
|
-
expect(complete.mock.calls.length).toBe(1)
|
|
93
|
-
expect(success.mock.calls[2][0])
|
|
94
|
-
.toEqual(expect.objectContaining({
|
|
95
|
-
socketTask: socketTaskThree,
|
|
96
|
-
errMsg: 'connectSocket:ok'
|
|
97
|
-
}))
|
|
98
|
-
expect(complete.mock.calls[0][0])
|
|
99
|
-
.toEqual(expect.objectContaining({
|
|
100
|
-
socketTask: socketTaskThree,
|
|
101
|
-
errMsg: 'connectSocket:ok'
|
|
102
|
-
}))
|
|
103
|
-
|
|
104
|
-
socketTaskTwo.close({})
|
|
105
|
-
socketTaskThree.close({})
|
|
106
|
-
})
|
|
107
|
-
// @ts-ignore
|
|
108
|
-
test('should work basically', async (done) => {
|
|
109
|
-
const fakeURL = 'wss://localhost:8080'
|
|
110
|
-
const mockServer = new Server(fakeURL)
|
|
111
|
-
const connected = jest.fn()
|
|
112
|
-
const success = jest.fn()
|
|
113
|
-
const complete = jest.fn()
|
|
114
|
-
const msg = 'hey gay!'
|
|
115
|
-
const msg2 = 'hey gay!gay!'
|
|
116
|
-
|
|
117
|
-
expect.assertions(11)
|
|
118
|
-
|
|
119
|
-
mockServer.on('connection', connected)
|
|
120
|
-
|
|
121
|
-
mockServer.on('message', message => {
|
|
122
|
-
expect(message).toMatch(msg)
|
|
123
|
-
mockServer.send(msg2)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const socketTask = await Taro.connectSocket({
|
|
127
|
-
url: fakeURL,
|
|
128
|
-
success,
|
|
129
|
-
complete
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
const socketTaskSend = jest.spyOn(socketTask.ws, 'send')
|
|
133
|
-
const socketTaskClose = jest.spyOn(socketTask.ws, 'close')
|
|
134
|
-
const closeCode = 100
|
|
135
|
-
const closeReason = 'hey'
|
|
136
|
-
|
|
137
|
-
socketTask.onOpen(() => {
|
|
138
|
-
socketTask.send({
|
|
139
|
-
data: msg,
|
|
140
|
-
success: (res) => {
|
|
141
|
-
expect(socketTaskSend).toHaveBeenCalled()
|
|
142
|
-
expect(res.errMsg).toMatch('sendSocketMessage:ok')
|
|
143
|
-
},
|
|
144
|
-
})
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
socketTask.onMessage(res => {
|
|
148
|
-
expect(res.data).toMatch(msg2)
|
|
149
|
-
socketTask.close({
|
|
150
|
-
code: closeCode,
|
|
151
|
-
reason: closeReason,
|
|
152
|
-
success: (res) => {
|
|
153
|
-
expect(socketTaskClose).toHaveBeenCalled()
|
|
154
|
-
expect(res.errMsg).toMatch('sendSocketMessage:ok')
|
|
155
|
-
},
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
socketTask.onClose(({ code, reason }) => {
|
|
160
|
-
const expectMsg = 'connectSocket:ok'
|
|
161
|
-
expect(connected.mock.calls.length).toBe(1)
|
|
162
|
-
expect(success.mock.calls[0][0].errMsg).toMatch(expectMsg)
|
|
163
|
-
expect(complete.mock.calls[0][0].errMsg).toMatch(expectMsg)
|
|
164
|
-
expect(code).toBe(closeCode)
|
|
165
|
-
expect(reason).toBe(closeReason)
|
|
166
|
-
done()
|
|
167
|
-
})
|
|
168
|
-
})
|
|
169
|
-
})
|