@tarojs/taro-rn 4.0.1-alpha.0 → 4.0.1
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 +13 -20
- 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 +151 -3
- package/dist/lib/chooseImage/index.js.map +1 -1
- package/dist/lib/chooseVideo/index.js +55 -1
- 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 +4 -8
- package/dist/lib/getLocation/index.js.map +1 -1
- package/dist/lib/getRecorderManager/index.js +6 -11
- 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 +0 -1
- 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 +30 -61
- 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 +5 -6
- 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 +23 -11
- package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
- package/dist/lib/showActionSheet/index.js +24 -10
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/lib/showModal/Dialog.js +36 -22
- 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 +4 -2
- 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/setup.js +75 -0
- package/dist/setup.js.map +1 -0
- package/dist/utils/callbackManager.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/libList.js +0 -1
- package/package.json +69 -70
- package/src/__tests__/__mock__/mockAsyncStorage.js +47 -0
- package/src/__tests__/__mock__/mockClipboard.js +15 -0
- package/src/__tests__/__mock__/mockNavigator.js +20 -0
- package/src/__tests__/__mock__/mockNetwork.js +59 -0
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +16 -0
- package/src/__tests__/__mock__/mockRNCGeolocation.js +13 -0
- package/src/__tests__/__mock__/mockVibrate.js +6 -0
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +125 -0
- package/src/__tests__/clipboard.test.ts +88 -0
- package/src/__tests__/deviceMotion.test.ts +37 -0
- package/src/__tests__/geolocation.test.ts +60 -0
- package/src/__tests__/interactive.test.tsx +101 -0
- package/src/__tests__/keyboard.test.ts +46 -0
- package/src/__tests__/media.test.ts +104 -0
- package/src/__tests__/network.test.ts +57 -0
- package/src/__tests__/others.test.ts +25 -0
- package/src/__tests__/phone.test.ts +31 -0
- package/src/__tests__/request.test.ts +146 -0
- package/src/__tests__/scanCode.test.tsx +14 -0
- package/src/__tests__/storage.test.ts +202 -0
- package/src/__tests__/system.test.ts +69 -0
- package/src/__tests__/vibrate.test.ts +27 -0
- package/src/__tests__/websocket.test.ts +169 -0
- 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 +19 -26
- package/src/lib/StyleSheet.ts +1 -1
- package/src/lib/accelerometer.ts +1 -2
- package/src/lib/arrayBufferToBase64/index.ts +1 -1
- package/src/lib/base64ToArrayBuffer/index.ts +1 -1
- package/src/lib/chooseImage/index.ts +155 -3
- package/src/lib/chooseVideo/index.ts +56 -1
- package/src/lib/clearStorage/index.ts +0 -1
- package/src/lib/clearStorageSync/index.ts +1 -1
- package/src/lib/compressImage/index.ts +0 -1
- package/src/lib/connectSocket/socketTask.ts +9 -7
- package/src/lib/createCameraContext/index.ts +4 -6
- package/src/lib/createInnerAudioContext/index.ts +0 -1
- package/src/lib/createSelectorQuery/index.ts +1 -1
- package/src/lib/deviceMotion.ts +3 -4
- package/src/lib/file.ts +8 -9
- package/src/lib/getClipboardData/index.ts +0 -1
- package/src/lib/getEnv/index.ts +1 -1
- package/src/lib/getFileSystemManager/index.ts +1 -1
- package/src/lib/getLocation/index.ts +2 -7
- package/src/lib/getRecorderManager/index.ts +2 -7
- package/src/lib/getStorage/index.ts +0 -1
- package/src/lib/getStorageInfo/index.ts +0 -1
- 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 +46 -47
- package/src/lib/index.ts +0 -1
- package/src/lib/keyboard.ts +4 -5
- package/src/lib/location.ts +5 -6
- package/src/lib/makePhoneCall/index.ts +1 -2
- package/src/lib/media.ts +31 -83
- 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 +22 -23
- package/src/lib/openUrl/index.ts +1 -2
- package/src/lib/permission.ts +25 -33
- package/src/lib/previewImage/index.tsx +3 -4
- package/src/lib/removeStorageSync/index.ts +1 -1
- package/src/lib/request/index.ts +2 -2
- package/src/lib/scanCode/index.tsx +16 -18
- package/src/lib/screen.ts +0 -1
- package/src/lib/setClipboardData/index.ts +2 -3
- package/src/lib/setKeepScreenOn/index.ts +1 -2
- package/src/lib/setStorage/index.ts +0 -1
- package/src/lib/setStorageSync/index.ts +1 -1
- package/src/lib/showActionSheet/ActionSheet.tsx +43 -34
- package/src/lib/showActionSheet/index.tsx +36 -11
- package/src/lib/showModal/Dialog.tsx +39 -34
- package/src/lib/showModal/index.tsx +0 -1
- package/src/lib/showModal/toast.tsx +13 -14
- package/src/lib/startGyroscope/index.ts +1 -1
- package/src/lib/startLocationUpdate/index.ts +1 -1
- package/src/lib/unsupportedApi.ts +5 -3
- package/src/lib/vibrate.ts +10 -11
- package/src/lib/window.ts +2 -3
- package/src/setup.ts +84 -0
- package/{types → src/types}/vue/index.d.ts +3 -2
- package/src/utils/callbackManager.ts +5 -5
- package/src/utils/index.ts +4 -4
- package/dist/lib/chooseMedia/index.js +0 -19
- package/dist/lib/chooseMedia/index.js.map +0 -1
- package/src/lib/chooseMedia/index.ts +0 -15
- /package/{types → src/types}/definition.d.ts +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,169 @@
|
|
|
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
|
+
})
|
package/src/api/index.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
export {
|
|
2
2
|
Current,
|
|
3
|
+
getCurrentInstance,
|
|
4
|
+
useDidShow,
|
|
5
|
+
useDidHide,
|
|
6
|
+
useLoad,
|
|
7
|
+
useReady,
|
|
8
|
+
useUnload,
|
|
9
|
+
useLaunch,
|
|
10
|
+
usePageNotFound,
|
|
11
|
+
useRouter,
|
|
12
|
+
usePullDownRefresh,
|
|
13
|
+
useReachBottom,
|
|
14
|
+
usePageScroll,
|
|
15
|
+
useTabItemTap,
|
|
16
|
+
useResize,
|
|
3
17
|
eventCenter,
|
|
4
18
|
Events,
|
|
5
|
-
getApp,
|
|
6
|
-
getCurrentInstance,
|
|
7
|
-
getCurrentPages,
|
|
8
|
-
hideNavigationBarLoading,
|
|
9
|
-
hideTabBar,
|
|
10
|
-
hideTabBarRedDot,
|
|
11
|
-
navigateBack,
|
|
12
19
|
navigateTo,
|
|
13
|
-
pageScrollTo,
|
|
14
|
-
pxTransform,
|
|
15
20
|
redirectTo,
|
|
21
|
+
navigateBack,
|
|
22
|
+
switchTab,
|
|
16
23
|
reLaunch,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
setNavigationBarTitle,
|
|
24
|
+
showTabBar,
|
|
25
|
+
hideTabBar,
|
|
26
|
+
showTabBarRedDot,
|
|
27
|
+
hideTabBarRedDot,
|
|
22
28
|
setTabBarBadge,
|
|
29
|
+
removeTabBarBadge,
|
|
23
30
|
setTabBarItem,
|
|
24
|
-
|
|
31
|
+
setNavigationBarTitle,
|
|
32
|
+
setNavigationBarColor,
|
|
25
33
|
showNavigationBarLoading,
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
hideNavigationBarLoading,
|
|
35
|
+
setTabBarStyle,
|
|
36
|
+
getApp,
|
|
37
|
+
pxTransform,
|
|
28
38
|
startPullDownRefresh,
|
|
29
39
|
stopPullDownRefresh,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
useLoad,
|
|
35
|
-
usePageNotFound,
|
|
36
|
-
usePageScroll,
|
|
37
|
-
usePullDownRefresh,
|
|
38
|
-
useReachBottom,
|
|
39
|
-
useReady,
|
|
40
|
-
useResize,
|
|
41
|
-
useRouter,
|
|
42
|
-
useTabItemTap,
|
|
43
|
-
useUnload
|
|
40
|
+
pageScrollTo,
|
|
41
|
+
setBackgroundColor,
|
|
42
|
+
setBackgroundTextStyle,
|
|
43
|
+
getCurrentPages
|
|
44
44
|
} from '@tarojs/runtime-rn'
|
package/src/lib/Mask.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ViewPropTypes } from 'deprecated-react-native-prop-types'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
1
|
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
4
3
|
import { StyleSheet, TouchableWithoutFeedback, View } from 'react-native'
|
|
4
|
+
import { ViewPropTypes } from 'deprecated-react-native-prop-types'
|
|
5
5
|
|
|
6
6
|
const styles = StyleSheet.create({
|
|
7
7
|
mask: {
|
package/src/lib/Popup.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ViewPropTypes } from 'deprecated-react-native-prop-types'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
1
|
import React, { Component } from 'react'
|
|
4
|
-
import { Animated, Dimensions, Easing, Modal, StyleSheet, View } from 'react-native'
|
|
5
2
|
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import { Modal, View, StyleSheet, Dimensions, Animated, Easing } from 'react-native'
|
|
5
|
+
import { ViewPropTypes } from 'deprecated-react-native-prop-types'
|
|
6
6
|
import { Mask } from './Mask'
|
|
7
7
|
|
|
8
8
|
const { width, height } = Dimensions.get('window')
|
|
@@ -17,7 +17,7 @@ const styles = StyleSheet.create({
|
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
interface Props {
|
|
20
|
-
visible?: boolean
|
|
20
|
+
visible?: boolean;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
class Popup extends Component<any, any> {
|
|
@@ -32,14 +32,14 @@ class Popup extends Component<any, any> {
|
|
|
32
32
|
|
|
33
33
|
height
|
|
34
34
|
popup
|
|
35
|
-
|
|
36
|
-
constructor(props:
|
|
35
|
+
|
|
36
|
+
constructor (props:Props) {
|
|
37
37
|
super(props)
|
|
38
38
|
this.state = { visible: props.visible ?? false, translateY: new Animated.Value(height) }
|
|
39
39
|
this.handleLayout = this.handleLayout.bind(this)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
UNSAFE_componentWillReceiveProps (nextProp:
|
|
42
|
+
UNSAFE_componentWillReceiveProps (nextProp:Props):void {
|
|
43
43
|
if (this.props.visible !== nextProp.visible) {
|
|
44
44
|
if (nextProp.visible) {
|
|
45
45
|
this.setState({ visible: true })
|
|
@@ -54,27 +54,20 @@ class Popup extends Component<any, any> {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
duration: 300,
|
|
69
|
-
easing: (Easing as any).easeInOut,
|
|
70
|
-
useNativeDriver: true
|
|
71
|
-
}).start()
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
},) // 处理鸿蒙系统handleLayout 回调 this.popup为空的情况
|
|
57
|
+
handleLayout ():void {
|
|
58
|
+
this.popup.measure((_x, _y, _w, h) => {
|
|
59
|
+
this.height = h
|
|
60
|
+
this.setState({ translateY: new Animated.Value(h) })
|
|
61
|
+
Animated.timing(this.state.translateY, {
|
|
62
|
+
toValue: 0,
|
|
63
|
+
duration: 300,
|
|
64
|
+
easing: (Easing as any).easeInOut,
|
|
65
|
+
useNativeDriver: true
|
|
66
|
+
}).start()
|
|
67
|
+
})
|
|
75
68
|
}
|
|
76
69
|
|
|
77
|
-
render ():
|
|
70
|
+
render ():JSX.Element {
|
|
78
71
|
const {
|
|
79
72
|
style,
|
|
80
73
|
maskStyle,
|
package/src/lib/StyleSheet.ts
CHANGED
package/src/lib/accelerometer.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Accelerometer } from 'expo-sensors'
|
|
2
|
-
|
|
3
2
|
import { createCallbackManager, errorHandler, successHandler } from '../utils'
|
|
4
3
|
|
|
5
4
|
const _cbManager = createCallbackManager()
|
|
@@ -69,8 +68,8 @@ function stopAccelerometer(opts: Taro.stopAccelerometer.Option = {}): Promise<Ta
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
export {
|
|
72
|
-
offAccelerometerChange,
|
|
73
71
|
onAccelerometerChange,
|
|
72
|
+
offAccelerometerChange,
|
|
74
73
|
startAccelerometer,
|
|
75
74
|
stopAccelerometer
|
|
76
75
|
}
|