Skip to content

Commit 1ed3525

Browse files
idefacebook-github-bot
authored andcommitted
Explicitly separate mocked native modules from mocked JS modules (#24809)
Summary: This commit more clearly defines the mocks RN sets up and uses paths instead of Haste names to define the mocks. The Jest setup script defined mocks for native modules (Obj-C, Java) and mocks for JS modules in the same data structure. This meant that some non-native modules (that is, JS modules) were in the `mockNativeModules` map -- this commit splits them out and mocks them in typical `jest.mock` fashion. Additionally, the setup script used to mock the modules using the Haste names. As one of the steps toward migrating to standard path-based imports, the setup script now mocks JS modules using paths (native modules don't need a Haste name nor path since they are just entries in `NativeModules`). This gets us closer to being able to remove `hasteImpl`. (Tracking in #24772.) Also, this commit removes mocks that are not referenced anywhere in the RN and React repositories (grepped for the names and found no entries outside of the Jest setup scripts). ## Changelog [General] [Changed] - Explicitly separate mocked native modules from mocked JS modules Pull Request resolved: #24809 Differential Revision: D15316882 Pulled By: cpojer fbshipit-source-id: 039e4e320121bea9580196fe0a091b8b1e8b41bf
1 parent 9d0d7b6 commit 1ed3525

File tree

2 files changed

+233
-276
lines changed

2 files changed

+233
-276
lines changed

Libraries/Image/__tests__/resolveAssetSource-test.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010

1111
'use strict';
1212

13-
const AssetRegistry = require('../AssetRegistry');
14-
const Platform = require('../../Utilities/Platform');
15-
const resolveAssetSource = require('../resolveAssetSource');
16-
17-
import NativeSourceCode from '../../NativeModules/specs/NativeSourceCode';
18-
19-
function expectResolvesAsset(input, expectedSource) {
20-
const assetId = AssetRegistry.registerAsset(input);
21-
expect(resolveAssetSource(assetId)).toEqual(expectedSource);
22-
}
23-
2413
describe('resolveAssetSource', () => {
14+
let AssetRegistry;
15+
let resolveAssetSource;
16+
let NativeSourceCode;
17+
let Platform;
18+
2519
beforeEach(() => {
2620
jest.resetModules();
21+
22+
AssetRegistry = require('../AssetRegistry');
23+
resolveAssetSource = require('../resolveAssetSource');
24+
NativeSourceCode = require('../../NativeModules/specs/NativeSourceCode')
25+
.default;
26+
Platform = require('../../Utilities/Platform');
2727
});
2828

2929
it('returns same source for simple static and network images', () => {
@@ -303,9 +303,16 @@ describe('resolveAssetSource', () => {
303303
);
304304
});
305305
});
306+
307+
function expectResolvesAsset(input, expectedSource) {
308+
const assetId = AssetRegistry.registerAsset(input);
309+
expect(resolveAssetSource(assetId)).toEqual(expectedSource);
310+
}
306311
});
307312

308313
describe('resolveAssetSource.pickScale', () => {
314+
const resolveAssetSource = require('../resolveAssetSource');
315+
309316
it('picks matching scale', () => {
310317
expect(resolveAssetSource.pickScale([1], 2)).toBe(1);
311318
expect(resolveAssetSource.pickScale([1, 2, 3], 2)).toBe(2);

0 commit comments

Comments
 (0)