jest-expo 54.0.0-canary-20250713-8f814f8 → 54.0.0-canary-20250722-599a28f
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/package.json +4 -4
- package/src/preset/setup.js +63 -75
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-expo",
|
|
3
|
-
"version": "54.0.0-canary-
|
|
3
|
+
"version": "54.0.0-canary-20250722-599a28f",
|
|
4
4
|
"description": "A Jest preset to painlessly test your Expo / React Native apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"preset": "jest-expo/universal"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@expo/config": "11.0.14-canary-
|
|
41
|
-
"@expo/json-file": "9.1.6-canary-
|
|
40
|
+
"@expo/config": "11.0.14-canary-20250722-599a28f",
|
|
41
|
+
"@expo/json-file": "9.1.6-canary-20250722-599a28f",
|
|
42
42
|
"@jest/create-cache-key-function": "^29.2.1",
|
|
43
43
|
"@jest/globals": "^29.2.1",
|
|
44
44
|
"babel-jest": "^29.2.1",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"stacktrace-js": "^2.0.2"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"expo": "54.0.0-canary-
|
|
58
|
+
"expo": "54.0.0-canary-20250722-599a28f",
|
|
59
59
|
"react-native": "*"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/src/preset/setup.js
CHANGED
|
@@ -219,88 +219,76 @@ function attemptLookup(moduleName) {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
|
|
223
|
-
jest.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
for (const moduleName of Object.keys(NativeModulesProxy)) {
|
|
245
|
-
const nativeModule = NativeModulesProxy[moduleName];
|
|
246
|
-
for (const propertyName of Object.keys(nativeModule)) {
|
|
247
|
-
if (typeof nativeModule[propertyName] === 'function') {
|
|
248
|
-
nativeModule[propertyName] = jest.fn(async () => {});
|
|
249
|
-
}
|
|
222
|
+
jest.doMock('expo-modules-core', () => {
|
|
223
|
+
const ExpoModulesCore = jest.requireActual('expo-modules-core');
|
|
224
|
+
|
|
225
|
+
const { EventEmitter, NativeModule, SharedObject } = globalThis.expo;
|
|
226
|
+
|
|
227
|
+
// support old hard-coded mocks TODO: remove this
|
|
228
|
+
const { NativeModulesProxy } = ExpoModulesCore;
|
|
229
|
+
|
|
230
|
+
// After the NativeModules mock is set up, we can mock NativeModuleProxy's functions that call
|
|
231
|
+
// into the native proxy module. We're not really interested in checking whether the underlying
|
|
232
|
+
// method is called, just that the proxy method is called, since we have unit tests for the
|
|
233
|
+
// adapter and believe it works correctly.
|
|
234
|
+
//
|
|
235
|
+
// NOTE: The adapter validates the number of arguments, which we don't do in the mocked functions.
|
|
236
|
+
// This means the mock functions will not throw validation errors the way they would in an app.
|
|
237
|
+
|
|
238
|
+
for (const moduleName of Object.keys(NativeModulesProxy)) {
|
|
239
|
+
const nativeModule = NativeModulesProxy[moduleName];
|
|
240
|
+
for (const propertyName of Object.keys(nativeModule)) {
|
|
241
|
+
if (typeof nativeModule[propertyName] === 'function') {
|
|
242
|
+
nativeModule[propertyName] = jest.fn(async () => {});
|
|
250
243
|
}
|
|
251
244
|
}
|
|
245
|
+
}
|
|
252
246
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const nativeModule = new NativeModule();
|
|
264
|
-
for (const [key, value] of Object.entries(nativeModuleMock)) {
|
|
265
|
-
nativeModule[key] = typeof value === 'function' ? jest.fn(value) : value;
|
|
266
|
-
}
|
|
267
|
-
return nativeModule;
|
|
247
|
+
function requireMockModule(name) {
|
|
248
|
+
// Support auto-mocking of expo-modules that:
|
|
249
|
+
// 1. have a mock in the `mocks` directory
|
|
250
|
+
// 2. the native module (e.g. ExpoCrypto) name matches the package name (expo-crypto)
|
|
251
|
+
const nativeModuleMock =
|
|
252
|
+
attemptLookup(name) ?? ExpoModulesCore.requireOptionalNativeModule(name);
|
|
253
|
+
if (!nativeModuleMock) {
|
|
254
|
+
return null;
|
|
268
255
|
}
|
|
269
256
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
NativeModule,
|
|
276
|
-
SharedObject,
|
|
277
|
-
|
|
278
|
-
requireOptionalNativeModule: requireMockModule,
|
|
279
|
-
requireNativeModule(moduleName) {
|
|
280
|
-
const module = requireMockModule(moduleName);
|
|
281
|
-
if (!module) {
|
|
282
|
-
throw new Error(`Cannot find native module '${moduleName}'`);
|
|
283
|
-
}
|
|
284
|
-
return module;
|
|
285
|
-
},
|
|
286
|
-
requireNativeViewManager: (name) => {
|
|
287
|
-
const nativeModuleMock = attemptLookup(name);
|
|
288
|
-
if (!nativeModuleMock || !nativeModuleMock.View) {
|
|
289
|
-
return ExpoModulesCore.requireNativeViewManager(name);
|
|
290
|
-
}
|
|
291
|
-
return nativeModuleMock.View;
|
|
292
|
-
},
|
|
293
|
-
};
|
|
294
|
-
});
|
|
295
|
-
} catch (error) {
|
|
296
|
-
// Allow this module to be optional for bare-workflow
|
|
297
|
-
if (error.code !== 'MODULE_NOT_FOUND') {
|
|
298
|
-
throw error;
|
|
257
|
+
const nativeModule = new NativeModule();
|
|
258
|
+
for (const [key, value] of Object.entries(nativeModuleMock)) {
|
|
259
|
+
nativeModule[key] = typeof value === 'function' ? jest.fn(value) : value;
|
|
260
|
+
}
|
|
261
|
+
return nativeModule;
|
|
299
262
|
}
|
|
300
|
-
}
|
|
301
263
|
|
|
302
|
-
|
|
303
|
-
|
|
264
|
+
return {
|
|
265
|
+
...ExpoModulesCore,
|
|
266
|
+
|
|
267
|
+
// Use web implementations for the common classes written natively
|
|
268
|
+
EventEmitter,
|
|
269
|
+
NativeModule,
|
|
270
|
+
SharedObject,
|
|
271
|
+
|
|
272
|
+
requireOptionalNativeModule: requireMockModule,
|
|
273
|
+
requireNativeModule(moduleName) {
|
|
274
|
+
const module = requireMockModule(moduleName);
|
|
275
|
+
if (!module) {
|
|
276
|
+
throw new Error(`Cannot find native module '${moduleName}'`);
|
|
277
|
+
}
|
|
278
|
+
return module;
|
|
279
|
+
},
|
|
280
|
+
requireNativeViewManager: (name) => {
|
|
281
|
+
const nativeModuleMock = attemptLookup(name);
|
|
282
|
+
if (!nativeModuleMock || !nativeModuleMock.View) {
|
|
283
|
+
return ExpoModulesCore.requireNativeViewManager(name);
|
|
284
|
+
}
|
|
285
|
+
return nativeModuleMock.View;
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Installs web implementations of the global.expo object for all platforms to polyfill APIs that are normally installed through JSI.
|
|
291
|
+
require('expo-modules-core/src/polyfill/dangerous-internal').installExpoGlobalPolyfill();
|
|
304
292
|
|
|
305
293
|
jest.doMock('expo/src/winter/FormData', () => ({
|
|
306
294
|
// The `installFormDataPatch` function is for native runtime only,
|