mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
Fix hasteImpl path checks on Windows machines
Summary: @public This fixes https://github.com/facebook/metro/issues/181 Reviewed By: mjesun Differential Revision: D8880071 fbshipit-source-id: 27e232baa7f39a938af86de810ff5357f777e858
This commit is contained in:
committed by
Facebook Github Bot
parent
679bff2658
commit
3ac86c366c
93
jest/__tests__/hasteImpl-test.js
Normal file
93
jest/__tests__/hasteImpl-test.js
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* 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', 'web', 'windows']) {
|
||||
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);
|
||||
});
|
||||
@@ -18,9 +18,9 @@ const ROOTS = [
|
||||
];
|
||||
|
||||
const BLACKLISTED_PATTERNS /*: Array<RegExp> */ = [
|
||||
/.*\/__(mocks|tests)__\/.*/,
|
||||
/^Libraries\/Animated\/src\/polyfills\/.*/,
|
||||
/^Libraries\/Renderer\/fb\/.*/,
|
||||
/.*[\\\/]__(mocks|tests)__[\\\/].*/,
|
||||
/^Libraries[\\\/]Animated[\\\/]src[\\\/]polyfills[\\\/].*/,
|
||||
/^Libraries[\\\/]Renderer[\\\/]fb[\\\/].*/,
|
||||
];
|
||||
|
||||
const WHITELISTED_PREFIXES /*: Array<string> */ = [
|
||||
@@ -32,7 +32,7 @@ const WHITELISTED_PREFIXES /*: Array<string> */ = [
|
||||
|
||||
const NAME_REDUCERS /*: Array<[RegExp, string]> */ = [
|
||||
// extract basename
|
||||
[/^(?:.*\/)?([a-zA-Z0-9$_.-]+)$/, '$1'],
|
||||
[/^(?:.*[\\\/])?([a-zA-Z0-9$_.-]+)$/, '$1'],
|
||||
// strip .js/.js.flow suffix
|
||||
[/^(.*)\.js(\.flow)?$/, '$1'],
|
||||
// strip .android/.ios/.native/.web suffix
|
||||
|
||||
Reference in New Issue
Block a user