Skip to content

Commit 3ac86c3

Browse files
rafecafacebook-github-bot
authored andcommittedJul 17, 2018
Fix hasteImpl path checks on Windows machines
Summary: @public This fixes facebook/metro#181 Reviewed By: mjesun Differential Revision: D8880071 fbshipit-source-id: 27e232baa7f39a938af86de810ff5357f777e858
1 parent 679bff2 commit 3ac86c3

File tree

2 files changed

+97
-4
lines changed

2 files changed

+97
-4
lines changed
 

‎jest/__tests__/hasteImpl-test.js

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @emails oncall+js_foundation
9+
*/
10+
11+
'use strict';
12+
13+
const path = require('path');
14+
15+
const {getHasteName} = require('../hasteImpl');
16+
17+
function getPath(...parts) {
18+
return path.join(__dirname, '..', '..', ...parts);
19+
}
20+
21+
it('returns the correct haste name for a RN library file', () => {
22+
expect(
23+
getHasteName(
24+
getPath(
25+
'Libraries',
26+
'Components',
27+
'AccessibilityInfo',
28+
'AccessibilityInfo.js',
29+
),
30+
),
31+
).toEqual('AccessibilityInfo');
32+
});
33+
34+
it('returns the correct haste name for a file with a platform suffix', () => {
35+
for (const platform of ['android', 'ios', 'native', 'web', 'windows']) {
36+
expect(
37+
getHasteName(
38+
getPath(
39+
'Libraries',
40+
'Components',
41+
'AccessibilityInfo',
42+
`AccessibilityInfo.${platform}.js`,
43+
),
44+
),
45+
).toEqual('AccessibilityInfo');
46+
}
47+
});
48+
49+
it('returns the correct haste name for a file with a flow suffix', () => {
50+
expect(
51+
getHasteName(
52+
getPath(
53+
'Libraries',
54+
'Components',
55+
'AccessibilityInfo',
56+
'AccessibilityInfo.ios.js.flow',
57+
),
58+
),
59+
).toEqual('AccessibilityInfo');
60+
});
61+
62+
it('does not calculate the haste name for a file that is not JS', () => {
63+
expect(
64+
getHasteName(
65+
getPath(
66+
'Libraries',
67+
'Components',
68+
'AccessibilityInfo',
69+
'AccessibilityInfo.txt',
70+
),
71+
),
72+
).toBe(undefined);
73+
});
74+
75+
it('does not calculate the haste name for a file outside of RN', () => {
76+
expect(
77+
getHasteName(getPath('..', 'Libraries', 'AccessibilityInfo.txt')),
78+
).toBe(undefined);
79+
});
80+
81+
it('does not calculate the haste name for a blacklisted file', () => {
82+
expect(
83+
getHasteName(
84+
getPath(
85+
'Libraries',
86+
'Components',
87+
'__mocks__',
88+
'AccessibilityInfo',
89+
'AccessibilityInfo.js',
90+
),
91+
),
92+
).toBe(undefined);
93+
});

‎jest/hasteImpl.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const ROOTS = [
1818
];
1919

2020
const BLACKLISTED_PATTERNS /*: Array<RegExp> */ = [
21-
/.*\/__(mocks|tests)__\/.*/,
22-
/^Libraries\/Animated\/src\/polyfills\/.*/,
23-
/^Libraries\/Renderer\/fb\/.*/,
21+
/.*[\\\/]__(mocks|tests)__[\\\/].*/,
22+
/^Libraries[\\\/]Animated[\\\/]src[\\\/]polyfills[\\\/].*/,
23+
/^Libraries[\\\/]Renderer[\\\/]fb[\\\/].*/,
2424
];
2525

2626
const WHITELISTED_PREFIXES /*: Array<string> */ = [
@@ -32,7 +32,7 @@ const WHITELISTED_PREFIXES /*: Array<string> */ = [
3232

3333
const NAME_REDUCERS /*: Array<[RegExp, string]> */ = [
3434
// extract basename
35-
[/^(?:.*\/)?([a-zA-Z0-9$_.-]+)$/, '$1'],
35+
[/^(?:.*[\\\/])?([a-zA-Z0-9$_.-]+)$/, '$1'],
3636
// strip .js/.js.flow suffix
3737
[/^(.*)\.js(\.flow)?$/, '$1'],
3838
// strip .android/.ios/.native/.web suffix

0 commit comments

Comments
 (0)
Please sign in to comment.