Skip to content

Commit

Permalink
Explicitly separate mocked native modules from mocked JS modules (fac…
Browse files Browse the repository at this point in the history
…ebook#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 facebook#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: facebook#24809

Differential Revision: D15316882

Pulled By: cpojer

fbshipit-source-id: 039e4e320121bea9580196fe0a091b8b1e8b41bf
  • Loading branch information
ide authored and facebook-github-bot committed May 31, 2019
1 parent 9d0d7b6 commit 1ed3525
Show file tree
Hide file tree
Showing 2 changed files with 233 additions and 276 deletions.
29 changes: 18 additions & 11 deletions Libraries/Image/__tests__/resolveAssetSource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

'use strict';

const AssetRegistry = require('../AssetRegistry');
const Platform = require('../../Utilities/Platform');
const resolveAssetSource = require('../resolveAssetSource');

import NativeSourceCode from '../../NativeModules/specs/NativeSourceCode';

function expectResolvesAsset(input, expectedSource) {
const assetId = AssetRegistry.registerAsset(input);
expect(resolveAssetSource(assetId)).toEqual(expectedSource);
}

describe('resolveAssetSource', () => {
let AssetRegistry;
let resolveAssetSource;
let NativeSourceCode;
let Platform;

beforeEach(() => {
jest.resetModules();

AssetRegistry = require('../AssetRegistry');
resolveAssetSource = require('../resolveAssetSource');
NativeSourceCode = require('../../NativeModules/specs/NativeSourceCode')
.default;
Platform = require('../../Utilities/Platform');
});

it('returns same source for simple static and network images', () => {
Expand Down Expand Up @@ -303,9 +303,16 @@ describe('resolveAssetSource', () => {
);
});
});

function expectResolvesAsset(input, expectedSource) {
const assetId = AssetRegistry.registerAsset(input);
expect(resolveAssetSource(assetId)).toEqual(expectedSource);
}
});

describe('resolveAssetSource.pickScale', () => {
const resolveAssetSource = require('../resolveAssetSource');

it('picks matching scale', () => {
expect(resolveAssetSource.pickScale([1], 2)).toBe(1);
expect(resolveAssetSource.pickScale([1, 2, 3], 2)).toBe(2);
Expand Down
Loading

0 comments on commit 1ed3525

Please sign in to comment.