@tarojs/taro-rn 4.0.1-alpha.1 → 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
package/package.json
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/taro-rn",
|
|
3
|
-
"version": "4.0.1
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Taro RN framework",
|
|
5
|
-
"author": "O2Team",
|
|
6
|
-
"license": "MIT",
|
|
7
5
|
"main": "dist/index.js",
|
|
8
|
-
"
|
|
6
|
+
"typings": "types/index.d.ts",
|
|
9
7
|
"files": [
|
|
10
8
|
"dist",
|
|
11
9
|
"src",
|
|
@@ -20,83 +18,84 @@
|
|
|
20
18
|
"keywords": [
|
|
21
19
|
"taro"
|
|
22
20
|
],
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
},
|
|
21
|
+
"author": "O2Team",
|
|
22
|
+
"license": "MIT",
|
|
26
23
|
"dependencies": {
|
|
27
|
-
"@bam.tech/react-native-image-resizer": "3.0.
|
|
28
|
-
"@react-native-async-storage/async-storage": "1.
|
|
29
|
-
"@react-native-camera-roll/camera-roll": "
|
|
30
|
-
"@react-native-clipboard/clipboard": "1.
|
|
31
|
-
"@react-native-community/geolocation": "3.2
|
|
32
|
-
"@react-native-community/netinfo": "
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"expo-
|
|
37
|
-
"expo-
|
|
38
|
-
"expo-
|
|
39
|
-
"expo-
|
|
40
|
-
"expo-
|
|
41
|
-
"expo-
|
|
42
|
-
"expo-
|
|
43
|
-
"expo-
|
|
24
|
+
"@bam.tech/react-native-image-resizer": "~3.0.4",
|
|
25
|
+
"@react-native-async-storage/async-storage": "~1.17.7",
|
|
26
|
+
"@react-native-camera-roll/camera-roll": "~5.0.4",
|
|
27
|
+
"@react-native-clipboard/clipboard": "~1.11.1",
|
|
28
|
+
"@react-native-community/geolocation": "~3.0.2",
|
|
29
|
+
"@react-native-community/netinfo": "~9.3.0",
|
|
30
|
+
"babel-preset-expo": "~9.2.1",
|
|
31
|
+
"base64-js": "^1.3.0",
|
|
32
|
+
"deprecated-react-native-prop-types": "^2.3.0",
|
|
33
|
+
"expo-av": "~13.0.0",
|
|
34
|
+
"expo-barcode-scanner": "~12.0.0",
|
|
35
|
+
"expo-brightness": "~11.0.0",
|
|
36
|
+
"expo-camera": "~13.0.0",
|
|
37
|
+
"expo-file-system": "~15.1.1",
|
|
38
|
+
"expo-image-picker": "~14.0.0",
|
|
39
|
+
"expo-keep-awake": "~11.0.1",
|
|
40
|
+
"expo-location": "~15.0.1",
|
|
41
|
+
"expo-sensors": "~12.0.1",
|
|
42
|
+
"nullthrows": "^1.1.1",
|
|
44
43
|
"prop-types": "^15.8.1",
|
|
45
|
-
"react-native-device-info": "
|
|
46
|
-
"react-native-image-zoom-viewer": "3.0.1",
|
|
47
|
-
"react-native-root-siblings": "
|
|
48
|
-
"react-native-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
44
|
+
"react-native-device-info": "~10.3.0",
|
|
45
|
+
"react-native-image-zoom-viewer": "^3.0.1",
|
|
46
|
+
"react-native-root-siblings": "^4.1.1",
|
|
47
|
+
"react-native-root-toast": "^3.0.1",
|
|
48
|
+
"react-native-safe-area-context": "~4.4.1",
|
|
49
|
+
"react-native-stylekit": "^1.0.0",
|
|
50
|
+
"react-native-syan-image-picker": "0.5.3",
|
|
51
|
+
"@tarojs/runtime-rn": "4.0.1"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@babel/core": "^7.
|
|
54
|
-
"@babel/
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@react-native
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"jest
|
|
54
|
+
"@babel/core": "^7.14.5",
|
|
55
|
+
"@babel/preset-env": "^7.14.5",
|
|
56
|
+
"@jest/globals": "^26.6.2",
|
|
57
|
+
"@testing-library/jest-native": "^4.0.4",
|
|
58
|
+
"@testing-library/react-native": "^11.5.0",
|
|
59
|
+
"@types/jest": "^27.4.1",
|
|
60
|
+
"@types/react-native": "^0.69.8",
|
|
61
|
+
"expo": "~47.0.3",
|
|
62
|
+
"expo-modules-core": "~1.0.2",
|
|
63
|
+
"fbjs-scripts": "^3.0.1",
|
|
64
|
+
"jest": "^26.4.2",
|
|
65
|
+
"jest-cli": "^26.4.2",
|
|
66
|
+
"jest-environment-node": "^26.0.0",
|
|
67
|
+
"jest-expo": "^47.0.0",
|
|
68
|
+
"metro-react-native-babel-preset": "^0.72.1",
|
|
64
69
|
"mock-socket": "^7.1.0",
|
|
65
|
-
"react": "
|
|
66
|
-
"react-native": "^0.
|
|
70
|
+
"react": "18.1.0",
|
|
71
|
+
"react-native": "^0.70.5",
|
|
72
|
+
"react-test-renderer": "18.1.0"
|
|
67
73
|
},
|
|
68
74
|
"peerDependencies": {
|
|
69
|
-
"@bam.tech/react-native-image-resizer": "
|
|
70
|
-
"@react-native-async-storage/async-storage": "
|
|
71
|
-
"@react-native-camera-roll/camera-roll": "
|
|
72
|
-
"@react-native-clipboard/clipboard": "
|
|
73
|
-
"@react-native-community/geolocation": "
|
|
74
|
-
"@react-native-community/netinfo": "
|
|
75
|
-
"expo": "
|
|
76
|
-
"expo-
|
|
77
|
-
"expo-
|
|
78
|
-
"expo-
|
|
79
|
-
"expo-
|
|
80
|
-
"expo-
|
|
81
|
-
"expo-
|
|
82
|
-
"expo-
|
|
83
|
-
"expo-
|
|
84
|
-
"
|
|
85
|
-
"react": "
|
|
86
|
-
"react-native": "
|
|
87
|
-
"react-native-device-info": ">= 11",
|
|
88
|
-
"react-native-image-zoom-viewer": ">= 3",
|
|
89
|
-
"react-native-root-siblings": ">= 5",
|
|
90
|
-
"react-native-safe-area-context": ">= 4.8.0"
|
|
75
|
+
"@bam.tech/react-native-image-resizer": "~3.0.4",
|
|
76
|
+
"@react-native-async-storage/async-storage": "~1.17.7",
|
|
77
|
+
"@react-native-camera-roll/camera-roll": "~5.0.4",
|
|
78
|
+
"@react-native-clipboard/clipboard": "~1.11.1",
|
|
79
|
+
"@react-native-community/geolocation": "~3.0.2",
|
|
80
|
+
"@react-native-community/netinfo": "~9.3.0",
|
|
81
|
+
"expo-av": "~13.0.0",
|
|
82
|
+
"expo-barcode-scanner": "~12.0.0",
|
|
83
|
+
"expo-brightness": "~11.0.0",
|
|
84
|
+
"expo-camera": "~13.0.0",
|
|
85
|
+
"expo-file-system": "~15.1.1",
|
|
86
|
+
"expo-image-picker": "~14.0.0",
|
|
87
|
+
"expo-keep-awake": "~11.0.1",
|
|
88
|
+
"expo-location": "~15.0.1",
|
|
89
|
+
"expo-sensors": "~12.0.1",
|
|
90
|
+
"react-native-device-info": "~10.3.0",
|
|
91
|
+
"react-native-safe-area-context": "~4.4.1",
|
|
92
|
+
"react-native-syan-image-picker": "0.5.3"
|
|
91
93
|
},
|
|
92
94
|
"scripts": {
|
|
93
|
-
"prod": "pnpm run build",
|
|
94
95
|
"assets": "cpy 'src/**/*.png' '!src/__tests__/*' dist",
|
|
95
|
-
"
|
|
96
|
-
"clean": "rimraf --impl=move-remove ./dist apiList.js libList.js",
|
|
97
|
-
"build": "tsc && pnpm run assets && pnpm run script",
|
|
96
|
+
"build": "rimraf ./dist && tsc && pnpm run assets && pnpm run script",
|
|
98
97
|
"dev": "pnpm run assets && tsc --watch",
|
|
99
|
-
"lint": "eslint
|
|
98
|
+
"lint": "eslint .",
|
|
100
99
|
"test": "jest --silent",
|
|
101
100
|
"test:ci": "jest --ci -i --coverage --silent",
|
|
102
101
|
"test:coverage": "jest --coverage",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export default class MockStorage {
|
|
2
|
+
constructor (cache = {}) {
|
|
3
|
+
this.storageCache = cache
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
setItem = jest.fn((key, value) => {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
return (typeof key !== 'string' || typeof value !== 'string')
|
|
9
|
+
? reject(new Error('key and value must be string'))
|
|
10
|
+
: resolve(this.storageCache[key] = value)
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
getItem = jest.fn((key) => {
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
// eslint-disable-next-line
|
|
17
|
+
return this.storageCache.hasOwnProperty(key)
|
|
18
|
+
? resolve(this.storageCache[key])
|
|
19
|
+
: resolve(null)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
removeItem = jest.fn((key) => {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
return this.storageCache.hasOwnProperty(key)
|
|
26
|
+
? resolve(delete this.storageCache[key])
|
|
27
|
+
: reject(new Error('No such key!'))
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
clear = jest.fn(() => {
|
|
32
|
+
return new Promise((resolve) => resolve(this.storageCache = {}))
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
getAllKeys = jest.fn(() => {
|
|
36
|
+
return new Promise((resolve) => resolve(Object.keys(this.storageCache)))
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
multiRemove = jest.fn((keys) => {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
keys.forEach(key => {
|
|
42
|
+
this.removeItem(key)
|
|
43
|
+
})
|
|
44
|
+
resolve()
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const geolocation = {
|
|
2
|
+
getCurrentPosition (callback) {
|
|
3
|
+
const res = {}
|
|
4
|
+
const coords = {
|
|
5
|
+
latitude: 0,
|
|
6
|
+
longitude: 0,
|
|
7
|
+
speed: 0,
|
|
8
|
+
accuracy: 0,
|
|
9
|
+
altitude: 0
|
|
10
|
+
}
|
|
11
|
+
res.coords = coords
|
|
12
|
+
res.timestamp = Date.now()
|
|
13
|
+
callback && callback(res)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const navigator = {}
|
|
18
|
+
navigator.geolocation = geolocation
|
|
19
|
+
|
|
20
|
+
export default navigator
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// eslint-disable-next-line
|
|
2
|
+
const noop = () => {}
|
|
3
|
+
|
|
4
|
+
export default class NetInfo {
|
|
5
|
+
constructor (connectionType = 'wifi', effectiveConnectionType = '4g') {
|
|
6
|
+
this.connectionType = connectionType
|
|
7
|
+
this.effectiveConnectionType = effectiveConnectionType
|
|
8
|
+
this.eventMaps = {}
|
|
9
|
+
this.connectedStatus = connectionType === 'wifi' || connectionType === 'cellular'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
isConnected = {
|
|
13
|
+
fetch: this.fetch.bind(this)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
fetch () {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
resolve({
|
|
19
|
+
type: this.connectionType,
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getConnectionInfo () {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
const res = {}
|
|
27
|
+
res.type = this.connectionType
|
|
28
|
+
res.effectiveType = this.effectiveConnectionType
|
|
29
|
+
resolve(res)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
addEventListener (eventName, listener = noop) {
|
|
34
|
+
this.eventMaps[eventName] = listener
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
removeEventListener (eventName, listener = noop) {
|
|
38
|
+
if (this.eventMaps[eventName] === listener) {
|
|
39
|
+
delete this.eventMaps[eventName]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 纯粹为了模拟测试用,主动更改网络状态
|
|
44
|
+
changeNetworkType (connectionType, effectiveConnectionType = '4g') {
|
|
45
|
+
if (this.connectionType !== connectionType) {
|
|
46
|
+
this.connectionType = connectionType
|
|
47
|
+
if (connectionType === 'cellular') {
|
|
48
|
+
this.effectiveConnectionType = effectiveConnectionType
|
|
49
|
+
}
|
|
50
|
+
this.connectedStatus = connectionType === 'wifi' || connectionType === 'cellular'
|
|
51
|
+
|
|
52
|
+
const res = {}
|
|
53
|
+
res.type = this.connectionType
|
|
54
|
+
res.effectiveType = this.effectiveConnectionType
|
|
55
|
+
const fn = this.eventMaps.connectionChange
|
|
56
|
+
fn && fn(res)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const RNCCameraRoll = {
|
|
2
|
+
deletePhotos: jest.fn(),
|
|
3
|
+
saveToCameraRoll: jest.fn((url, { type }) => Promise.resolve(`${type}://${url}`)),
|
|
4
|
+
getPhotos: jest.fn(() => Promise.resolve()),
|
|
5
|
+
}
|
|
6
|
+
const RNCCameraRollPermissionModule = {
|
|
7
|
+
checkPermission: jest.fn(),
|
|
8
|
+
requestReadWritePermission: jest.fn(),
|
|
9
|
+
requestAddOnlyPermission: jest.fn(),
|
|
10
|
+
refreshPhotoSelection: jest.fn(),
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
RNCCameraRoll,
|
|
15
|
+
RNCCameraRollPermissionModule,
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const mockGetCurrentPosition = jest.fn()
|
|
2
|
+
|
|
3
|
+
const RNCGeolocation = {
|
|
4
|
+
addListener: jest.fn(),
|
|
5
|
+
getCurrentPosition: mockGetCurrentPosition,
|
|
6
|
+
removeListeners: jest.fn(),
|
|
7
|
+
requestAuthorization: jest.fn(),
|
|
8
|
+
setConfiguration: jest.fn(),
|
|
9
|
+
startObserving: jest.fn(),
|
|
10
|
+
stopObserving: jest.fn(),
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default RNCGeolocation
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`scanCode should render scanCode success 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
style={
|
|
6
|
+
Array [
|
|
7
|
+
Object {
|
|
8
|
+
"alignItems": "center",
|
|
9
|
+
"backgroundColor": "#FFF",
|
|
10
|
+
"flex": 1,
|
|
11
|
+
"justifyContent": "center",
|
|
12
|
+
"position": "absolute",
|
|
13
|
+
"zIndex": 1000,
|
|
14
|
+
},
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
>
|
|
18
|
+
<ViewManagerAdapter_ExponentCamera
|
|
19
|
+
onBarCodeScanned={[Function]}
|
|
20
|
+
onCameraReady={[Function]}
|
|
21
|
+
onFacesDetected={[Function]}
|
|
22
|
+
onMountError={[Function]}
|
|
23
|
+
onPictureSaved={[Function]}
|
|
24
|
+
proxiedProperties={
|
|
25
|
+
Object {
|
|
26
|
+
"autoFocus": undefined,
|
|
27
|
+
"barCodeScannerEnabled": true,
|
|
28
|
+
"barCodeScannerSettings": Object {
|
|
29
|
+
"barCodeTypes": Array [],
|
|
30
|
+
},
|
|
31
|
+
"faceDetectorSettings": Object {},
|
|
32
|
+
"flashMode": undefined,
|
|
33
|
+
"focusDepth": 0,
|
|
34
|
+
"type": undefined,
|
|
35
|
+
"whiteBalance": undefined,
|
|
36
|
+
"zoom": 0,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
style={
|
|
40
|
+
Object {
|
|
41
|
+
"height": 1334,
|
|
42
|
+
"width": 750,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/>
|
|
46
|
+
<View
|
|
47
|
+
accessibilityLabel="Close"
|
|
48
|
+
accessible={true}
|
|
49
|
+
collapsable={false}
|
|
50
|
+
focusable={true}
|
|
51
|
+
onClick={[Function]}
|
|
52
|
+
onResponderGrant={[Function]}
|
|
53
|
+
onResponderMove={[Function]}
|
|
54
|
+
onResponderRelease={[Function]}
|
|
55
|
+
onResponderTerminate={[Function]}
|
|
56
|
+
onResponderTerminationRequest={[Function]}
|
|
57
|
+
onStartShouldSetResponder={[Function]}
|
|
58
|
+
style={
|
|
59
|
+
Object {
|
|
60
|
+
"left": 20,
|
|
61
|
+
"opacity": 1,
|
|
62
|
+
"position": "absolute",
|
|
63
|
+
"top": 10,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
>
|
|
67
|
+
<View
|
|
68
|
+
style={
|
|
69
|
+
Object {
|
|
70
|
+
"paddingTop": 20,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
>
|
|
74
|
+
<Image
|
|
75
|
+
source={1}
|
|
76
|
+
style={
|
|
77
|
+
Object {
|
|
78
|
+
"height": 25,
|
|
79
|
+
"marginTop": null,
|
|
80
|
+
"width": 25,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/>
|
|
84
|
+
</View>
|
|
85
|
+
</View>
|
|
86
|
+
<View
|
|
87
|
+
accessible={true}
|
|
88
|
+
collapsable={false}
|
|
89
|
+
focusable={true}
|
|
90
|
+
onClick={[Function]}
|
|
91
|
+
onResponderGrant={[Function]}
|
|
92
|
+
onResponderMove={[Function]}
|
|
93
|
+
onResponderRelease={[Function]}
|
|
94
|
+
onResponderTerminate={[Function]}
|
|
95
|
+
onResponderTerminationRequest={[Function]}
|
|
96
|
+
onStartShouldSetResponder={[Function]}
|
|
97
|
+
style={
|
|
98
|
+
Object {
|
|
99
|
+
"bottom": 40,
|
|
100
|
+
"opacity": 1,
|
|
101
|
+
"position": "absolute",
|
|
102
|
+
"right": 20,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
>
|
|
106
|
+
<View
|
|
107
|
+
style={
|
|
108
|
+
Object {
|
|
109
|
+
"paddingTop": 20,
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
>
|
|
113
|
+
<Image
|
|
114
|
+
source={1}
|
|
115
|
+
style={
|
|
116
|
+
Object {
|
|
117
|
+
"height": 20,
|
|
118
|
+
"width": 20,
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/>
|
|
122
|
+
</View>
|
|
123
|
+
</View>
|
|
124
|
+
</View>
|
|
125
|
+
`;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import Clipboard from '@react-native-clipboard/clipboard'
|
|
2
|
+
import { getClipboardData } from '../lib/getClipboardData'
|
|
3
|
+
import { setClipboardData } from '../lib/setClipboardData'
|
|
4
|
+
|
|
5
|
+
const Taro = {
|
|
6
|
+
setClipboardData,
|
|
7
|
+
getClipboardData
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 原生模块导出缺少 react_native_1.NativeModules.RNCClipboar setup mock
|
|
11
|
+
|
|
12
|
+
describe('clipboard', () => {
|
|
13
|
+
describe('setClipboardData', () => {
|
|
14
|
+
test('should set value into Clipboard', async () => {
|
|
15
|
+
const data = 'foo'
|
|
16
|
+
const success = jest.fn()
|
|
17
|
+
const fail = jest.fn()
|
|
18
|
+
const complete = jest.fn()
|
|
19
|
+
|
|
20
|
+
expect.assertions(7)
|
|
21
|
+
const res = await Taro.setClipboardData({
|
|
22
|
+
data,
|
|
23
|
+
success,
|
|
24
|
+
fail,
|
|
25
|
+
complete
|
|
26
|
+
})
|
|
27
|
+
const expectMsg = 'setClipboardData:ok'
|
|
28
|
+
expect(success.mock.calls.length).toBe(1)
|
|
29
|
+
expect(success.mock.calls[0][0]).toEqual({ data, errMsg: expectMsg })
|
|
30
|
+
expect(fail.mock.calls.length).toBe(0)
|
|
31
|
+
expect(complete.mock.calls.length).toBe(1)
|
|
32
|
+
expect(complete.mock.calls[0][0]).toEqual({ data, errMsg: expectMsg })
|
|
33
|
+
expect(res.errMsg).toMatch(expectMsg)
|
|
34
|
+
|
|
35
|
+
const clipData = await Clipboard.getString()
|
|
36
|
+
expect(clipData).toEqual(data)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('should fail when data is not string', () => {
|
|
40
|
+
const data = {}
|
|
41
|
+
const success = jest.fn()
|
|
42
|
+
const fail = jest.fn()
|
|
43
|
+
const complete = jest.fn()
|
|
44
|
+
|
|
45
|
+
// expect.assertions(6)
|
|
46
|
+
return Taro.setClipboardData({
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
data,
|
|
49
|
+
success,
|
|
50
|
+
fail,
|
|
51
|
+
complete
|
|
52
|
+
}).catch(err => {
|
|
53
|
+
const expectErrMsg = 'setClipboardData:fail parameter error: parameter.data should be String'
|
|
54
|
+
expect(success.mock.calls.length).toBe(0)
|
|
55
|
+
expect(fail.mock.calls.length).toBe(1)
|
|
56
|
+
expect(fail.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
|
|
57
|
+
expect(complete.mock.calls.length).toBe(1)
|
|
58
|
+
expect(complete.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
|
|
59
|
+
expect(err.errMsg).toMatch(expectErrMsg)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
describe('getClipboardData', () => {
|
|
65
|
+
test('可以获得正确的剪切板数据', async () => {
|
|
66
|
+
const data = 'hey!hey!hey!'
|
|
67
|
+
const success = jest.fn()
|
|
68
|
+
const fail = jest.fn()
|
|
69
|
+
const complete = jest.fn()
|
|
70
|
+
|
|
71
|
+
expect.assertions(6)
|
|
72
|
+
Clipboard.setString(data)
|
|
73
|
+
|
|
74
|
+
const res = await Taro.getClipboardData({
|
|
75
|
+
success,
|
|
76
|
+
fail,
|
|
77
|
+
complete
|
|
78
|
+
})
|
|
79
|
+
const expectErrMsg = 'getClipboardData:ok'
|
|
80
|
+
expect(success.mock.calls.length).toBe(1)
|
|
81
|
+
expect(fail.mock.calls.length).toBe(0)
|
|
82
|
+
expect(success.mock.calls[0][0]).toEqual({ data, errMsg: expectErrMsg })
|
|
83
|
+
expect(complete.mock.calls.length).toBe(1)
|
|
84
|
+
expect(complete.mock.calls[0][0]).toEqual({ data, errMsg: expectErrMsg })
|
|
85
|
+
expect(res.data).toEqual(data)
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// import { DeviceMotion } from 'expo-sensors'
|
|
2
|
+
import * as Taro from '../lib/deviceMotion'
|
|
3
|
+
|
|
4
|
+
describe('deviceMotion', () => {
|
|
5
|
+
it('should startDeviceMotionListening success', () => {
|
|
6
|
+
const success = jest.fn()
|
|
7
|
+
const fail = jest.fn()
|
|
8
|
+
const complete = jest.fn()
|
|
9
|
+
Taro.startDeviceMotionListening({
|
|
10
|
+
success,
|
|
11
|
+
fail,
|
|
12
|
+
complete,
|
|
13
|
+
})
|
|
14
|
+
expect(success.mock.calls.length).toBe(1)
|
|
15
|
+
expect(fail.mock.calls.length).toBe(0)
|
|
16
|
+
expect(success.mock.calls.length).toBe(1)
|
|
17
|
+
})
|
|
18
|
+
it('should stopDeviceMotionListening success', () => {
|
|
19
|
+
const success = jest.fn()
|
|
20
|
+
const fail = jest.fn()
|
|
21
|
+
const complete = jest.fn()
|
|
22
|
+
Taro.stopDeviceMotionListening({
|
|
23
|
+
success,
|
|
24
|
+
fail,
|
|
25
|
+
complete,
|
|
26
|
+
})
|
|
27
|
+
expect(success.mock.calls.length).toBe(1)
|
|
28
|
+
expect(fail.mock.calls.length).toBe(0)
|
|
29
|
+
expect(success.mock.calls.length).toBe(1)
|
|
30
|
+
})
|
|
31
|
+
// it('should onDeviceMotionChange success', () => {
|
|
32
|
+
// const change = jest.fn().mockImplementation((ret) => {
|
|
33
|
+
// expect(0).toBe(0)
|
|
34
|
+
// })
|
|
35
|
+
// Taro.onDeviceMotionChange(change)
|
|
36
|
+
// })
|
|
37
|
+
})
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as Taro from '../lib/getLocation'
|
|
2
|
+
import { mockGetCurrentPosition } from './__mock__/mockRNCGeolocation'
|
|
3
|
+
|
|
4
|
+
describe('location', () => {
|
|
5
|
+
describe('getLocation', () => {
|
|
6
|
+
// test('定位功能返回正常参数', () => {
|
|
7
|
+
// const success = jest.fn()
|
|
8
|
+
// const fail = jest.fn()
|
|
9
|
+
// const complete = jest.fn()
|
|
10
|
+
|
|
11
|
+
// const expectData = {
|
|
12
|
+
// latitude: expect.any(Number),
|
|
13
|
+
// longitude: expect.any(Number),
|
|
14
|
+
// speed: expect.any(Number),
|
|
15
|
+
// accuracy: expect.any(Number),
|
|
16
|
+
// altitude: expect.any(Number),
|
|
17
|
+
// verticalAccuracy: expect.any(Number),
|
|
18
|
+
// horizontalAccuracy: expect.any(Number),
|
|
19
|
+
// }
|
|
20
|
+
|
|
21
|
+
// expect.assertions(6)
|
|
22
|
+
|
|
23
|
+
// return Taro.getLocation({
|
|
24
|
+
// success,
|
|
25
|
+
// fail,
|
|
26
|
+
// complete
|
|
27
|
+
// }).then((res) => {
|
|
28
|
+
// expect(success.mock.calls.length).toBe(1)
|
|
29
|
+
// expect(fail.mock.calls.length).toBe(0)
|
|
30
|
+
// expect(complete.mock.calls.length).toBe(1)
|
|
31
|
+
// expect(complete.mock.calls[0][0]).toEqual(expect.objectContaining(expectData))
|
|
32
|
+
// expect(success.mock.calls[0][0]).toEqual(expect.objectContaining(expectData))
|
|
33
|
+
// expect(res).toEqual(expect.objectContaining(expectData))
|
|
34
|
+
// })
|
|
35
|
+
// })
|
|
36
|
+
test('定位方法正常调用', () => {
|
|
37
|
+
const success = jest.fn()
|
|
38
|
+
const fail = jest.fn()
|
|
39
|
+
const complete = jest.fn()
|
|
40
|
+
|
|
41
|
+
// const expectData = {
|
|
42
|
+
// latitude: expect.any(Number),
|
|
43
|
+
// longitude: expect.any(Number),
|
|
44
|
+
// speed: expect.any(Number),
|
|
45
|
+
// accuracy: expect.any(Number),
|
|
46
|
+
// altitude: expect.any(Number),
|
|
47
|
+
// verticalAccuracy: expect.any(Number),
|
|
48
|
+
// horizontalAccuracy: expect.any(Number),
|
|
49
|
+
// }
|
|
50
|
+
|
|
51
|
+
Taro.getLocation({
|
|
52
|
+
success,
|
|
53
|
+
fail,
|
|
54
|
+
complete
|
|
55
|
+
}).then(() => {
|
|
56
|
+
expect(mockGetCurrentPosition.mock.calls.length).toBe(1)
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
})
|