@tarojs/taro-rn 4.0.0-beta.75 → 4.0.0-beta.76
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 +1 -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 +3 -3
- 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/chooseMedia/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 +2 -2
- package/dist/lib/getLocation/index.js.map +1 -1
- package/dist/lib/getRecorderManager/index.js +5 -5
- 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/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 +15 -13
- 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 +22 -22
- 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 +3 -3
- package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/lib/showModal/Dialog.js +3 -3
- 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/package.json +65 -60
- 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 +8 -6
- 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/chooseMedia/index.ts +1 -1
- 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 +4 -3
- package/src/lib/getRecorderManager/index.ts +1 -1
- 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/keyboard.ts +5 -4
- package/src/lib/location.ts +6 -5
- package/src/lib/makePhoneCall/index.ts +2 -1
- package/src/lib/media.ts +21 -18
- 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 +17 -15
- 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 +7 -6
- package/src/lib/showActionSheet/index.tsx +1 -0
- package/src/lib/showModal/Dialog.tsx +7 -6
- package/src/lib/showModal/index.tsx +1 -0
- package/src/lib/showModal/toast.tsx +12 -11
- 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 -58
- package/dist/setup.js.map +0 -1
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +0 -7
- package/src/__tests__/__mock__/mockRNCGeolocation.js +0 -13
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +0 -154
- 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 -170
- package/src/setup.ts +0 -64
- /package/{src/types → types}/definition.d.ts +0 -0
|
@@ -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,170 +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', (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
|
-
Taro.connectSocket({
|
|
127
|
-
url: fakeURL,
|
|
128
|
-
success,
|
|
129
|
-
complete
|
|
130
|
-
}).then(socketTask => {
|
|
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
|
-
})
|
|
170
|
-
})
|
package/src/setup.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-native/extend-expect'
|
|
2
|
-
import { NetInfoStateType } from '@react-native-community/netinfo'
|
|
3
|
-
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock'
|
|
4
|
-
import mockRNCAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock'
|
|
5
|
-
import mockRNCDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock'
|
|
6
|
-
import mockRNCClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock'
|
|
7
|
-
import mockRNCGeolocation from './__tests__/__mock__/mockRNCGeolocation'
|
|
8
|
-
import mockRNCameraRoll from './__tests__/__mock__/mockRNCCameraRoll'
|
|
9
|
-
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter')
|
|
10
|
-
jest.doMock('@react-native-community/netinfo', () => ({ ...mockRNCNetInfo, NetInfoStateType }))
|
|
11
|
-
jest.doMock('@react-native-async-storage/async-storage', () => mockRNCAsyncStorage)
|
|
12
|
-
jest.doMock('@react-native-community/geolocation', () => mockRNCGeolocation)
|
|
13
|
-
jest.doMock('@react-native-clipboard/clipboard', () => mockRNCClipboard)
|
|
14
|
-
jest.doMock('react-native-device-info', () => mockRNCDeviceInfo)
|
|
15
|
-
jest.mock('@react-native-camera-roll/camera-roll', () => mockRNCameraRoll)
|
|
16
|
-
|
|
17
|
-
jest.mock('react-native', () => {
|
|
18
|
-
const ReactNative = jest.requireActual('react-native') as any
|
|
19
|
-
ReactNative.Image.getSize = jest.fn((_uri, success: any) => {
|
|
20
|
-
setTimeout(() => success && success(320, 240))
|
|
21
|
-
return Promise.resolve([320, 240])
|
|
22
|
-
})
|
|
23
|
-
return ReactNative
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
jest.doMock('expo-modules-core', () => {
|
|
27
|
-
const unimodules = jest.requireActual('expo-modules-core') as any
|
|
28
|
-
const { NativeModulesProxy } = unimodules
|
|
29
|
-
|
|
30
|
-
NativeModulesProxy.ExpoLocation = {
|
|
31
|
-
getCurrentPositionAsync: jest.fn(() => Promise.resolve({
|
|
32
|
-
coords: {
|
|
33
|
-
latitude: 0,
|
|
34
|
-
longitude: 0,
|
|
35
|
-
speed: 0,
|
|
36
|
-
accuracy: 0,
|
|
37
|
-
altitude: 0
|
|
38
|
-
}
|
|
39
|
-
}))
|
|
40
|
-
}
|
|
41
|
-
return unimodules
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const grantedPromise = jest.fn(() => Promise.resolve({
|
|
45
|
-
granted: true
|
|
46
|
-
}))
|
|
47
|
-
|
|
48
|
-
jest.doMock('expo-image-picker', () => {
|
|
49
|
-
const expoImagePicker = jest.requireActual('expo-image-picker') as any
|
|
50
|
-
expoImagePicker.requestMediaLibraryPermissionsAsync = grantedPromise
|
|
51
|
-
return expoImagePicker
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
jest.doMock('expo-location', () => {
|
|
55
|
-
const expoLocation = jest.requireActual('expo-location') as any
|
|
56
|
-
expoLocation.requestForegroundPermissionsAsync = grantedPromise
|
|
57
|
-
return expoLocation
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
jest.doMock('expo-barcode-scanner', () => {
|
|
61
|
-
const expoBarcodeSacnner = jest.requireActual('expo-barcode-scanner') as any
|
|
62
|
-
expoBarcodeSacnner.requestPermissionsAsync = grantedPromise
|
|
63
|
-
return expoBarcodeSacnner
|
|
64
|
-
})
|
|
File without changes
|