@react-native/jest-preset 0.85.0-nightly-20260219-44901aaf9
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/README.md +39 -0
- package/jest/MockNativeMethods.js +27 -0
- package/jest/RefreshControlMock.js +32 -0
- package/jest/assetFileTransformer.js +38 -0
- package/jest/local-setup.js +29 -0
- package/jest/mock.js +39 -0
- package/jest/mockComponent.js +103 -0
- package/jest/mockNativeComponent.js +52 -0
- package/jest/mocks/AccessibilityInfo.js +62 -0
- package/jest/mocks/ActivityIndicator.js +23 -0
- package/jest/mocks/AppState.js +19 -0
- package/jest/mocks/Clipboard.js +16 -0
- package/jest/mocks/Image.js +23 -0
- package/jest/mocks/InitializeCore.js +9 -0
- package/jest/mocks/Linking.js +28 -0
- package/jest/mocks/Modal.js +33 -0
- package/jest/mocks/NativeComponentRegistry.js +30 -0
- package/jest/mocks/NativeModules.js +239 -0
- package/jest/mocks/RefreshControl.js +31 -0
- package/jest/mocks/RendererProxy.js +45 -0
- package/jest/mocks/ScrollView.js +58 -0
- package/jest/mocks/Text.js +27 -0
- package/jest/mocks/TextInput.js +32 -0
- package/jest/mocks/UIManager.js +60 -0
- package/jest/mocks/Vibration.js +16 -0
- package/jest/mocks/View.js +27 -0
- package/jest/mocks/ViewNativeComponent.js +23 -0
- package/jest/mocks/requireNativeComponent.js +22 -0
- package/jest/mocks/useColorScheme.js +18 -0
- package/jest/react-native-env.js +17 -0
- package/jest/renderer.js +40 -0
- package/jest/resolver.js +32 -0
- package/jest/setup.js +177 -0
- package/package.json +39 -0
package/jest/resolver.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @noflow
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
module.exports = (path, options) => {
|
|
14
|
+
const originalPackageFilter = options.packageFilter;
|
|
15
|
+
|
|
16
|
+
return options.defaultResolver(path, {
|
|
17
|
+
...options,
|
|
18
|
+
packageFilter: pkg => {
|
|
19
|
+
const filteredPkg = originalPackageFilter
|
|
20
|
+
? originalPackageFilter(pkg)
|
|
21
|
+
: pkg;
|
|
22
|
+
|
|
23
|
+
// Temporarily allow any react-native subpaths to be resolved and
|
|
24
|
+
// mocked by Jest (backwards compatibility around RFC0894)
|
|
25
|
+
if (filteredPkg.name === 'react-native') {
|
|
26
|
+
delete filteredPkg.exports;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return filteredPkg;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
};
|
package/jest/setup.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
12
|
+
// Suppress the `react-test-renderer` warnings until New Architecture and legacy
|
|
13
|
+
// mode are no longer supported by React Native.
|
|
14
|
+
global.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
|
|
15
|
+
|
|
16
|
+
import '@react-native/js-polyfills/error-guard';
|
|
17
|
+
|
|
18
|
+
import mock from './mock';
|
|
19
|
+
|
|
20
|
+
// $FlowFixMe[cannot-write]
|
|
21
|
+
Object.defineProperties(global, {
|
|
22
|
+
__DEV__: {
|
|
23
|
+
configurable: true,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
value: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
},
|
|
28
|
+
cancelAnimationFrame: {
|
|
29
|
+
configurable: true,
|
|
30
|
+
enumerable: true,
|
|
31
|
+
value(id: TimeoutID): void {
|
|
32
|
+
return clearTimeout(id);
|
|
33
|
+
},
|
|
34
|
+
writable: true,
|
|
35
|
+
},
|
|
36
|
+
nativeFabricUIManager: {
|
|
37
|
+
configurable: true,
|
|
38
|
+
enumerable: true,
|
|
39
|
+
value: {},
|
|
40
|
+
writable: true,
|
|
41
|
+
},
|
|
42
|
+
performance: {
|
|
43
|
+
configurable: true,
|
|
44
|
+
enumerable: true,
|
|
45
|
+
value: {
|
|
46
|
+
// $FlowFixMe[method-unbinding]
|
|
47
|
+
now: jest.fn(Date.now),
|
|
48
|
+
},
|
|
49
|
+
writable: true,
|
|
50
|
+
},
|
|
51
|
+
regeneratorRuntime: {
|
|
52
|
+
configurable: true,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
value: jest.requireActual<unknown>('regenerator-runtime/runtime'),
|
|
55
|
+
writable: true,
|
|
56
|
+
},
|
|
57
|
+
requestAnimationFrame: {
|
|
58
|
+
configurable: true,
|
|
59
|
+
enumerable: true,
|
|
60
|
+
value(callback: number => void): TimeoutID {
|
|
61
|
+
return setTimeout(() => callback(jest.now()), 0);
|
|
62
|
+
},
|
|
63
|
+
writable: true,
|
|
64
|
+
},
|
|
65
|
+
window: {
|
|
66
|
+
configurable: true,
|
|
67
|
+
enumerable: true,
|
|
68
|
+
value: global,
|
|
69
|
+
writable: true,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// This setup script will be published in the react-native package.
|
|
74
|
+
// Other people might not have prettier installed, so it will crash the mock below.
|
|
75
|
+
// Therefore, we wrap this mock in a try-catch.
|
|
76
|
+
try {
|
|
77
|
+
/**
|
|
78
|
+
* Prettier v3 uses import (cjs/mjs) file formats that jest-runtime does not
|
|
79
|
+
* support. To work around this we need to bypass the jest module system by
|
|
80
|
+
* using the orginal node `require` function.
|
|
81
|
+
*/
|
|
82
|
+
jest.mock('prettier', () => {
|
|
83
|
+
// $FlowExpectedError[underconstrained-implicit-instantiation]
|
|
84
|
+
const module = jest.requireActual('module');
|
|
85
|
+
return module.prototype.require(require.resolve('prettier'));
|
|
86
|
+
});
|
|
87
|
+
} catch {}
|
|
88
|
+
|
|
89
|
+
mock(
|
|
90
|
+
'm#react-native/Libraries/AppState/AppState',
|
|
91
|
+
// $FlowFixMe[incompatible-type] - `./mocks/AppState` is incomplete.
|
|
92
|
+
'm#./mocks/AppState',
|
|
93
|
+
);
|
|
94
|
+
mock(
|
|
95
|
+
'm#react-native/Libraries/BatchedBridge/NativeModules',
|
|
96
|
+
'm#./mocks/NativeModules',
|
|
97
|
+
);
|
|
98
|
+
mock(
|
|
99
|
+
'm#react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo',
|
|
100
|
+
'm#./mocks/AccessibilityInfo',
|
|
101
|
+
);
|
|
102
|
+
mock(
|
|
103
|
+
'm#react-native/Libraries/Components/ActivityIndicator/ActivityIndicator',
|
|
104
|
+
'm#./mocks/ActivityIndicator',
|
|
105
|
+
);
|
|
106
|
+
mock(
|
|
107
|
+
'm#react-native/Libraries/Components/Clipboard/Clipboard',
|
|
108
|
+
'm#./mocks/Clipboard',
|
|
109
|
+
);
|
|
110
|
+
mock(
|
|
111
|
+
'm#react-native/Libraries/Components/RefreshControl/RefreshControl',
|
|
112
|
+
// $FlowFixMe[incompatible-type] - `react-native/Libraries/Components/RefreshControl/RefreshControl` should export a component type.
|
|
113
|
+
'm#./mocks/RefreshControl',
|
|
114
|
+
);
|
|
115
|
+
mock(
|
|
116
|
+
'm#react-native/Libraries/Components/ScrollView/ScrollView',
|
|
117
|
+
// $FlowFixMe[incompatible-exact] - `react-native/Libraries/Components/ScrollView/ScrollView` is... I don't even.
|
|
118
|
+
// $FlowFixMe[incompatible-type]
|
|
119
|
+
'm#./mocks/ScrollView',
|
|
120
|
+
);
|
|
121
|
+
mock(
|
|
122
|
+
'm#react-native/Libraries/Components/TextInput/TextInput',
|
|
123
|
+
'm#./mocks/TextInput',
|
|
124
|
+
);
|
|
125
|
+
mock('m#react-native/Libraries/Components/View/View', 'm#./mocks/View');
|
|
126
|
+
mock(
|
|
127
|
+
'm#react-native/Libraries/Components/View/ViewNativeComponent',
|
|
128
|
+
// $FlowFixMe[incompatible-type] - `./mocks/ViewNativeComponent` is incomplete.
|
|
129
|
+
// $FlowFixMe[prop-missing]
|
|
130
|
+
'm#./mocks/ViewNativeComponent',
|
|
131
|
+
);
|
|
132
|
+
mock(
|
|
133
|
+
'm#react-native/Libraries/Core/InitializeCore',
|
|
134
|
+
'm#./mocks/InitializeCore',
|
|
135
|
+
);
|
|
136
|
+
mock('m#react-native/Libraries/Core/NativeExceptionsManager');
|
|
137
|
+
mock('m#react-native/Libraries/Image/Image', 'm#./mocks/Image');
|
|
138
|
+
mock(
|
|
139
|
+
'm#react-native/Libraries/Linking/Linking',
|
|
140
|
+
// $FlowFixMe[incompatible-type] - `./mocks/Linking` is incomplete.
|
|
141
|
+
'm#./mocks/Linking',
|
|
142
|
+
);
|
|
143
|
+
mock(
|
|
144
|
+
'm#react-native/Libraries/Modal/Modal',
|
|
145
|
+
// $FlowFixMe[incompatible-type] - `react-native/Libraries/Modal/Modal` should export a component type.
|
|
146
|
+
'm#./mocks/Modal',
|
|
147
|
+
);
|
|
148
|
+
mock(
|
|
149
|
+
'm#react-native/Libraries/NativeComponent/NativeComponentRegistry',
|
|
150
|
+
// $FlowFixMe[incompatible-type] - `./mocks/NativeComponentRegistry` should export named functions.
|
|
151
|
+
'm#./mocks/NativeComponentRegistry',
|
|
152
|
+
);
|
|
153
|
+
mock(
|
|
154
|
+
'm#react-native/Libraries/ReactNative/RendererProxy',
|
|
155
|
+
// $FlowFixMe[incompatible-type] - `./mocks/RendererProxy` is incomplete.
|
|
156
|
+
'm#./mocks/RendererProxy',
|
|
157
|
+
);
|
|
158
|
+
mock(
|
|
159
|
+
'm#react-native/Libraries/ReactNative/requireNativeComponent',
|
|
160
|
+
'm#./mocks/requireNativeComponent',
|
|
161
|
+
);
|
|
162
|
+
mock(
|
|
163
|
+
'm#react-native/Libraries/ReactNative/UIManager',
|
|
164
|
+
// $FlowFixMe[incompatible-type] - `./mocks/UIManager` is incomplete.
|
|
165
|
+
'm#./mocks/UIManager',
|
|
166
|
+
);
|
|
167
|
+
mock('m#react-native/Libraries/Text/Text', 'm#./mocks/Text');
|
|
168
|
+
mock(
|
|
169
|
+
'm#react-native/Libraries/Utilities/useColorScheme',
|
|
170
|
+
// $FlowFixMe[react-rule-hook-incompatible]
|
|
171
|
+
'm#./mocks/useColorScheme',
|
|
172
|
+
);
|
|
173
|
+
mock(
|
|
174
|
+
'm#react-native/Libraries/Vibration/Vibration',
|
|
175
|
+
// $FlowFixMe[incompatible-type]
|
|
176
|
+
'm#./mocks/Vibration',
|
|
177
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-native/jest-preset",
|
|
3
|
+
"version": "0.85.0-nightly-20260219-44901aaf9",
|
|
4
|
+
"description": "Jest preset for React Native apps",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"jest",
|
|
7
|
+
"preset",
|
|
8
|
+
"react-native"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/facebook/react-native.git",
|
|
13
|
+
"directory": "packages/jest-preset"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">= 20.19.4"
|
|
18
|
+
},
|
|
19
|
+
"main": "./jest-preset.js",
|
|
20
|
+
"files": [
|
|
21
|
+
"jest",
|
|
22
|
+
"index.js",
|
|
23
|
+
"README.md",
|
|
24
|
+
"!**/__docs__/**",
|
|
25
|
+
"!**/__fixtures__/**",
|
|
26
|
+
"!**/__mocks__/**",
|
|
27
|
+
"!**/__tests__/**"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@jest/create-cache-key-function": "^29.7.0",
|
|
31
|
+
"@react-native/js-polyfills": "0.85.0-nightly-20260219-44901aaf9",
|
|
32
|
+
"babel-jest": "^29.7.0",
|
|
33
|
+
"jest-environment-node": "^29.7.0",
|
|
34
|
+
"regenerator-runtime": "^0.13.2"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"react": "^19.2.3"
|
|
38
|
+
}
|
|
39
|
+
}
|