mirror of
https://github.com/status-im/react-native.git
synced 2025-02-22 14:18:23 +00:00
Summary: This PR is a WIP for adding tests for out-of-tree platform support. [I originally had issues](https://github.com/facebook/react-native/pull/20825#issuecomment-416433611) with this, so I want to give it a try in a separate pull request. None of these issues appear on my machine while running these tests as of this rebase - if everything seems okay on CircleCI after this rebase against `master`, I will ditch the [WIP] tag. Otherwise, I will see if I can find a way to make this work. The bunch of JS files that will give this a "Large PR" tag are in `RNTester/js/OutOfTreeTestPlatform` - they are only used by the bundler and not executed at any point in time. So if another file needs to be added when React Native's module structure changes, you do not need to have a functional JS file in there as a stub. `module.exports` could be `null` if you wanted. I just had copied over stubs from `Libraries` because I wanted a non-trivial haste module map to be in the test. Pull Request resolved: https://github.com/facebook/react-native/pull/20932 Reviewed By: axe-fb Differential Revision: D9818112 Pulled By: hramos fbshipit-source-id: 0b53359b84430fdefb972587c95d19f85773c5fa
126 lines
2.7 KiB
JavaScript
126 lines
2.7 KiB
JavaScript
/**
|
|
* 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 fs = require('fs');
|
|
|
|
const {getHasteName} = require('../hasteImpl');
|
|
|
|
// RNPM currently does not support plugins when using Yarn Plug 'n Play
|
|
const testIfNotPnP = fs.existsSync(
|
|
path.join(
|
|
__dirname,
|
|
'../..',
|
|
'node_modules',
|
|
'react-native-dummy',
|
|
'package.json',
|
|
),
|
|
)
|
|
? test
|
|
: test.skip;
|
|
|
|
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');
|
|
}
|
|
});
|
|
|
|
testIfNotPnP(
|
|
'returns the correct haste name for a file with an out-of-tree platform suffix',
|
|
() => {
|
|
for (const platform of ['dummy']) {
|
|
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);
|
|
});
|