Delete hasteImpl, providesModuleNodeModules, and modulePathNameMapper (#24811)

Summary:
**Depends on https://github.com/facebook/react-native/pull/25100**

This commit depends on having migrated all of RN away from Haste. With 100% standard path-based requires, the key foundation is set and we no longer need `hasteImpl` and related settings in the Jest configuration.

This commit deletes the `hasteImpl` file and setting as well as `providesModuleNodeModules` and `modulePathNameMapper`, removing most of the dependency graph overriding performed by Jest.

## Changelog

[General] [Changed] - Delete hasteImpl, providesModuleNodeModules, and modulePathNameMapper from Jest config
Pull Request resolved: https://github.com/facebook/react-native/pull/24811

Differential Revision: D15659274

Pulled By: cpojer

fbshipit-source-id: 8a4a3b97ddf7e38fbe62c6d3cc9c98248bfca343
This commit is contained in:
James Ide
2019-06-05 10:55:08 -07:00
committed by Facebook Github Bot
parent 995b4d3049
commit 7a2463e1f3
4 changed files with 2 additions and 222 deletions
-8
View File
@@ -9,19 +9,11 @@
'use strict';
const dir = __dirname;
module.exports = {
haste: {
defaultPlatform: 'ios',
platforms: ['android', 'ios', 'native'],
hasteImplModulePath: require.resolve('./jest/hasteImpl.js'),
providesModuleNodeModules: ['react-native'],
},
moduleNameMapper: {
'^React$': require.resolve('react'),
},
modulePathIgnorePatterns: [`${dir}/Libraries/react-native/`],
transform: {
'^.+\\.(js|ts|tsx)$': 'babel-jest',
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
-38
View File
@@ -17,9 +17,6 @@ module.exports = {
'./jest/setup.js',
],
'timers': 'fake',
'moduleNameMapper': {
'^React$': '<rootDir>/Libraries/react-native/React.js',
},
'testRegex': '/__tests__/.*-test\\.js$',
'testPathIgnorePatterns': [
'/node_modules/',
@@ -29,46 +26,11 @@ module.exports = {
],
'haste': {
'defaultPlatform': 'ios',
'hasteImplModulePath': '<rootDir>/jest/hasteImpl.js',
'providesModuleNodeModules': [
'react-native',
],
'platforms': [
'ios',
'android',
],
},
'modulePathIgnorePatterns': [
'/node_modules/(?!react|fbjs|react-native|react-transform-hmr|core-js|promise)/',
'node_modules/react/node_modules/fbjs/',
'node_modules/react/lib/ReactDOM.js',
'node_modules/fbjs/lib/Map.js',
'node_modules/fbjs/lib/Promise.js',
'node_modules/fbjs/lib/fetch.js',
'node_modules/fbjs/lib/ErrorUtils.js',
'node_modules/fbjs/lib/URI.js',
'node_modules/fbjs/lib/Deferred.js',
'node_modules/fbjs/lib/PromiseMap.js',
'node_modules/fbjs/lib/UserAgent.js',
'node_modules/fbjs/lib/areEqual.js',
'node_modules/fbjs/lib/base62.js',
'node_modules/fbjs/lib/crc32.js',
'node_modules/fbjs/lib/everyObject.js',
'node_modules/fbjs/lib/fetchWithRetries.js',
'node_modules/fbjs/lib/filterObject.js',
'node_modules/fbjs/lib/flattenArray.js',
'node_modules/fbjs/lib/forEachObject.js',
'node_modules/fbjs/lib/isEmpty.js',
'node_modules/fbjs/lib/removeFromArray.js',
'node_modules/fbjs/lib/resolveImmediate.js',
'node_modules/fbjs/lib/someObject.js',
'node_modules/fbjs/lib/sprintf.js',
'node_modules/fbjs/lib/xhrSimpleDataSerializer.js',
'node_modules/jest-cli',
'node_modules/react/dist',
'node_modules/fbjs/.*/__mocks__/',
'node_modules/fbjs/node_modules/',
],
'unmockedModulePathPatterns': [
'node_modules/react/',
'Libraries/Renderer',
-93
View File
@@ -1,93 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+js_foundation
*/
'use strict';
const path = require('path');
const {getHasteName} = require('../hasteImpl');
function getPath(...parts) {
return path.join(__dirname, '..', '..', ...parts);
}
it('returns the correct haste name for a RN library file', () => {
expect(
getHasteName(
getPath(
'Libraries',
'Components',
'AccessibilityInfo',
'AccessibilityInfo.js',
),
),
).toEqual('AccessibilityInfo');
});
it('returns the correct haste name for a file with a platform suffix', () => {
for (const platform of ['android', 'ios', 'native']) {
expect(
getHasteName(
getPath(
'Libraries',
'Components',
'AccessibilityInfo',
`AccessibilityInfo.${platform}.js`,
),
),
).toEqual('AccessibilityInfo');
}
});
it('returns the correct haste name for a file with a flow suffix', () => {
expect(
getHasteName(
getPath(
'Libraries',
'Components',
'AccessibilityInfo',
'AccessibilityInfo.ios.js.flow',
),
),
).toEqual('AccessibilityInfo');
});
it('does not calculate the haste name for a file that is not JS', () => {
expect(
getHasteName(
getPath(
'Libraries',
'Components',
'AccessibilityInfo',
'AccessibilityInfo.txt',
),
),
).toBe(undefined);
});
it('does not calculate the haste name for a file outside of RN', () => {
expect(
getHasteName(getPath('..', 'Libraries', 'AccessibilityInfo.txt')),
).toBe(undefined);
});
it('does not calculate the haste name for a blacklisted file', () => {
expect(
getHasteName(
getPath(
'Libraries',
'Components',
'__mocks__',
'AccessibilityInfo',
'AccessibilityInfo.js',
),
),
).toBe(undefined);
});
+2 -83
View File
@@ -5,93 +5,12 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const path = require('path');
const cli = require('@react-native-community/cli');
// Use duck-typing because of Facebook-internal infra that doesn't have the cli package.
const {haste} = (cli.loadConfig && cli.loadConfig()) || {
haste: {
providesModuleNodeModules: [],
platforms: ['ios', 'android'],
},
};
// Detect out-of-tree platforms and add them to the whitelists
const pluginRoots /*: Array<string> */ = haste.providesModuleNodeModules.map(
name => path.resolve(__dirname, '../../', name) + path.sep,
);
const pluginNameReducers /*: Array<[RegExp, string]> */ = haste.platforms.map(
name => [new RegExp(`^(.*)\\.(${name})$`), '$1'],
);
const ROOTS = [path.resolve(__dirname, '..') + path.sep, ...pluginRoots];
const BLACKLISTED_PATTERNS /*: Array<RegExp> */ = [
/.*[\\\/]__(mocks|tests)__[\\\/].*/,
/^Libraries[\\\/]Animated[\\\/]src[\\\/]polyfills[\\\/].*/,
/^Libraries[\\\/]Renderer[\\\/]fb[\\\/].*/,
/DerivedData[\\\/].*/,
];
const WHITELISTED_PREFIXES /*: Array<string> */ = [
'IntegrationTests',
'Libraries',
'ReactAndroid',
'RNTester',
];
const NAME_REDUCERS /*: Array<[RegExp, string]> */ = [
// extract basename
[/^(?:.*[\\\/])?([a-zA-Z0-9$_.-]+)$/, '$1'],
// strip .js/.js.flow suffix
[/^(.*)\.js(\.flow)?$/, '$1'],
// strip native suffix
[/^(.*)\.(native)$/, '$1'],
// strip plugin platform suffixes
...pluginNameReducers,
];
function isHastePath(filePath /*: string */) /*: boolean */ {
if (!filePath.endsWith('.js') && !filePath.endsWith('.js.flow')) {
return false;
}
const root = ROOTS.find(r => filePath.startsWith(r));
if (!root) {
return false;
}
filePath = filePath.substr(root.length);
if (BLACKLISTED_PATTERNS.some(pattern => pattern.test(filePath))) {
return false;
}
return WHITELISTED_PREFIXES.some(prefix => filePath.startsWith(prefix));
}
module.exports = {
/*
* @return {string|void} hasteName for module at filePath; or undefined if
* filePath is not a haste module
*/
getHasteName(
filePath /*: string */,
sourceCode /*: ?string */,
) /*: string | void */ {
if (!isHastePath(filePath)) {
return undefined;
}
const hasteName = NAME_REDUCERS.reduce(
(name, [pattern, replacement]) => name.replace(pattern, replacement),
filePath,
);
return hasteName;
getHasteName() {
return undefined;
},
};