@tarojs/taro-rn 4.0.0-beta.0 → 4.0.0-beta.2
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 +14 -0
- package/dist/lib/chooseImage/index.js +36 -146
- package/dist/lib/chooseImage/index.js.map +1 -1
- package/dist/lib/chooseVideo/index.js +32 -47
- package/dist/lib/chooseVideo/index.js.map +1 -1
- package/dist/lib/media.js +9 -12
- package/dist/lib/media.js.map +1 -1
- package/dist/lib/showActionSheet/index.js +10 -24
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/setup.js +13 -30
- package/dist/setup.js.map +1 -1
- package/package.json +45 -48
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +3 -12
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +11 -16
- package/src/__tests__/clipboard.test.ts +2 -2
- package/src/lib/chooseImage/index.ts +24 -148
- package/src/lib/chooseVideo/index.ts +23 -48
- package/src/lib/file.ts +1 -1
- package/src/lib/media.ts +17 -13
- package/src/lib/showActionSheet/index.tsx +10 -36
- package/src/setup.ts +13 -33
- 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__/mockVibrate.js +0 -6
package/src/setup.ts
CHANGED
|
@@ -1,44 +1,24 @@
|
|
|
1
|
-
import { jest } from '@jest/globals'
|
|
2
1
|
import '@testing-library/jest-native/extend-expect'
|
|
3
|
-
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock.js'
|
|
4
2
|
import { NetInfoStateType } from '@react-native-community/netinfo'
|
|
5
|
-
import
|
|
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'
|
|
6
5
|
import mockRNCDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock'
|
|
7
|
-
|
|
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')
|
|
8
10
|
jest.doMock('@react-native-community/netinfo', () => ({ ...mockRNCNetInfo, NetInfoStateType }))
|
|
9
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)
|
|
10
14
|
jest.doMock('react-native-device-info', () => mockRNCDeviceInfo)
|
|
15
|
+
jest.mock('@react-native-camera-roll/camera-roll', () => mockRNCameraRoll)
|
|
11
16
|
|
|
12
|
-
jest.
|
|
17
|
+
jest.mock('react-native', () => {
|
|
13
18
|
const ReactNative = jest.requireActual('react-native') as any
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Object.defineProperty(ReactNative, 'Vibration', {
|
|
18
|
-
enumerable: false,
|
|
19
|
-
configurable: false,
|
|
20
|
-
writable: false,
|
|
21
|
-
value: Vibration
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
// mockNativeModules: react-native/Libraries/BatchedBridge/NativeModules
|
|
25
|
-
const RNCCameraRoll = (jest.requireActual('./__tests__/__mock__/mockRNCCameraRoll') as any).default
|
|
26
|
-
const MockClipboard = (jest.requireActual('./__tests__/__mock__/mockClipboard') as any).default
|
|
27
|
-
const RNCGeolocation = (jest.requireActual('./__tests__/__mock__/mockRNCGeolocation') as any).default
|
|
28
|
-
ReactNative.NativeModules.RNCCameraRoll = RNCCameraRoll.RNCCameraRoll
|
|
29
|
-
ReactNative.NativeModules.RNCCameraRollPermissionModule = RNCCameraRoll.RNCCameraRollPermissionModule
|
|
30
|
-
ReactNative.NativeModules.RNCClipboard = new MockClipboard()
|
|
31
|
-
ReactNative.NativeModules.RNCGeolocation = RNCGeolocation
|
|
32
|
-
Object.defineProperty(ReactNative.NativeModules, 'ImageLoader', {
|
|
33
|
-
configurable: true,
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: () => ({
|
|
36
|
-
prefetchImage: jest.fn(),
|
|
37
|
-
getSize: jest.fn((_uri, success: any) => {
|
|
38
|
-
process.nextTick(() => success && success(320, 240))
|
|
39
|
-
return Promise.resolve([320, 240])
|
|
40
|
-
}),
|
|
41
|
-
}),
|
|
19
|
+
ReactNative.Image.getSize = jest.fn((_uri, success: any) => {
|
|
20
|
+
setTimeout(() => success && success(320, 240))
|
|
21
|
+
return Promise.resolve([320, 240])
|
|
42
22
|
})
|
|
43
23
|
return ReactNative
|
|
44
24
|
})
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
}
|