|
| 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 | +}); |
0 commit comments