mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Revert changes in RN preprocessor
Summary: Changelog: [General][Fixed] Revert changes in Jest preprocessor to fix tests in external projects Reviewed By: yungsters Differential Revision: D32250044 fbshipit-source-id: 0ed4c9f7bcfa82349b5c2ec7af2ccda970bbb0ef
This commit is contained in:
@@ -11,12 +11,12 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as React from 'react';
|
||||
import ScrollView from '../ScrollView';
|
||||
import * as ReactNativeTestTools from '../../../Utilities/ReactNativeTestTools';
|
||||
import ReactTestRenderer from 'react-test-renderer';
|
||||
import View from '../../View/View';
|
||||
import Text from '../../../Text/Text';
|
||||
const React = require('react');
|
||||
const ScrollView = require('../ScrollView');
|
||||
const ReactNativeTestTools = require('../../../Utilities/ReactNativeTestTools');
|
||||
const ReactTestRenderer = require('react-test-renderer');
|
||||
const View = require('../../View/View');
|
||||
const Text = require('../../../Text/Text');
|
||||
|
||||
describe('<ScrollView />', () => {
|
||||
it('should render as expected', () => {
|
||||
|
||||
@@ -10,12 +10,13 @@
|
||||
*/
|
||||
|
||||
import type {PressEvent} from '../../Types/CoreEventTypes';
|
||||
import * as HoverState from '../HoverState';
|
||||
import Pressability from '../Pressability';
|
||||
import invariant from 'invariant';
|
||||
import nullthrows from 'nullthrows';
|
||||
import Platform from '../../Utilities/Platform';
|
||||
import UIManager from '../../ReactNative/UIManager';
|
||||
|
||||
const HoverState = require('../HoverState');
|
||||
const Pressability = require('../Pressability').default;
|
||||
const invariant = require('invariant');
|
||||
const nullthrows = require('nullthrows');
|
||||
const Platform = require('../../Utilities/Platform');
|
||||
const UIManager = require('../../ReactNative/UIManager');
|
||||
|
||||
// TODO: Move this util to a shared location.
|
||||
function getMock<TArguments: $ReadOnlyArray<mixed>, TReturn>(
|
||||
|
||||
+7
-75
@@ -13,42 +13,10 @@
|
||||
'use strict';
|
||||
|
||||
const babelRegisterOnly = require('metro-babel-register');
|
||||
const nullthrows = require('nullthrows');
|
||||
const createCacheKeyFunction = require('@jest/create-cache-key-function')
|
||||
.default;
|
||||
const t = require('@babel/types');
|
||||
const {statements} = require('@babel/template').default;
|
||||
|
||||
const importDefault = '__importDefault__';
|
||||
const importAll = '__importAll__';
|
||||
|
||||
// prelude
|
||||
const importPrelude = statements(`
|
||||
function ${importDefault}(moduleId) {
|
||||
const exports = require(moduleId);
|
||||
|
||||
if (exports && exports.__esModule) {
|
||||
return exports.default;
|
||||
}
|
||||
|
||||
return exports;
|
||||
};
|
||||
|
||||
function ${importAll}(moduleId) {
|
||||
const exports = require(moduleId);
|
||||
|
||||
if (exports && exports.__esModule) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
return Object.assign({}, exports, {default: exports});
|
||||
};
|
||||
`);
|
||||
|
||||
const {
|
||||
transformSync: babelTransformSync,
|
||||
transformFromAstSync: babelTransformFromAstSync,
|
||||
} = require('@babel/core');
|
||||
const {transformSync: babelTransformSync} = require('@babel/core');
|
||||
const generate = require('@babel/generator').default;
|
||||
|
||||
const nodeFiles = new RegExp(
|
||||
@@ -73,13 +41,13 @@ module.exports = {
|
||||
}).code;
|
||||
}
|
||||
|
||||
let {ast} = transformer.transform({
|
||||
const {ast} = transformer.transform({
|
||||
filename: file,
|
||||
options: {
|
||||
ast: true, // needed for open source (?) https://github.com/facebook/react-native/commit/f8d6b97140cffe8d18b2558f94570c8d1b410d5c#r28647044
|
||||
dev: true,
|
||||
enableBabelRuntime: false,
|
||||
experimentalImportSupport: true,
|
||||
experimentalImportSupport: false,
|
||||
globalPrefix: '',
|
||||
hot: false,
|
||||
inlineRequires: true,
|
||||
@@ -111,6 +79,10 @@ module.exports = {
|
||||
[require('@babel/plugin-transform-regenerator')],
|
||||
[require('@babel/plugin-transform-sticky-regex')],
|
||||
[require('@babel/plugin-transform-unicode-regex')],
|
||||
[
|
||||
require('@babel/plugin-transform-modules-commonjs'),
|
||||
{strict: false, allowTopLevelThis: true},
|
||||
],
|
||||
[require('@babel/plugin-transform-classes')],
|
||||
[require('@babel/plugin-transform-arrow-functions')],
|
||||
[require('@babel/plugin-transform-spread')],
|
||||
@@ -127,46 +99,6 @@ module.exports = {
|
||||
],
|
||||
});
|
||||
|
||||
// We're not using @babel/plugin-transform-modules-commonjs so
|
||||
// we need to add 'use strict' manually
|
||||
const directives = ast.program.directives;
|
||||
|
||||
if (
|
||||
ast.program.sourceType === 'module' &&
|
||||
(directives == null ||
|
||||
directives.findIndex(d => d.value.value === 'use strict') === -1)
|
||||
) {
|
||||
ast.program.directives = [
|
||||
...(directives || []),
|
||||
t.directive(t.directiveLiteral('use strict')),
|
||||
];
|
||||
}
|
||||
|
||||
// Postprocess the transformed module to handle ESM and inline requires.
|
||||
// We need to do this in a separate pass to avoid issues tracking references.
|
||||
const babelTransformResult = babelTransformFromAstSync(ast, src, {
|
||||
ast: true,
|
||||
retainLines: true,
|
||||
plugins: [
|
||||
[
|
||||
require('metro-transform-plugins').importExportPlugin,
|
||||
{importDefault, importAll},
|
||||
],
|
||||
[
|
||||
require('babel-preset-fbjs/plugins/inline-requires.js'),
|
||||
{inlineableCalls: [importDefault, importAll]},
|
||||
],
|
||||
],
|
||||
sourceType: 'module',
|
||||
});
|
||||
|
||||
ast = nullthrows(babelTransformResult.ast);
|
||||
|
||||
// Inject import helpers *after* running the inline-requires transform,
|
||||
// because otherwise it will assume they are user code and bail out of
|
||||
// inlining calls to them.
|
||||
ast.program.body.unshift(...importPrelude());
|
||||
|
||||
return generate(
|
||||
ast,
|
||||
// $FlowFixMe[prop-missing] Error found when improving flow typing for libs
|
||||
|
||||
@@ -11,13 +11,10 @@
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.14.0",
|
||||
"@babel/generator": "^7.14.0",
|
||||
"@babel/template": "^7.0.0",
|
||||
"@babel/types": "^7.0.0",
|
||||
"@react-native-community/eslint-plugin": "*",
|
||||
"@reactions/component": "^2.0.2",
|
||||
"async": "^2.4.0",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"babel-preset-fbjs": "^3.4.0",
|
||||
"clang-format": "^1.2.4",
|
||||
"connect": "^3.6.5",
|
||||
"coveralls": "^3.0.2",
|
||||
@@ -41,7 +38,6 @@
|
||||
"jest-junit": "^10.0.0",
|
||||
"jscodeshift": "^0.11.0",
|
||||
"metro-babel-register": "0.66.2",
|
||||
"metro-transform-plugins": "^0.66.2",
|
||||
"mkdirp": "^0.5.1",
|
||||
"prettier": "1.19.1",
|
||||
"react": "17.0.2",
|
||||
|
||||
@@ -4730,7 +4730,7 @@ metro-symbolicate@0.66.2:
|
||||
through2 "^2.0.1"
|
||||
vlq "^1.0.0"
|
||||
|
||||
metro-transform-plugins@0.66.2, metro-transform-plugins@^0.66.2:
|
||||
metro-transform-plugins@0.66.2:
|
||||
version "0.66.2"
|
||||
resolved "https://registry.yarnpkg.com/metro-transform-plugins/-/metro-transform-plugins-0.66.2.tgz#39dd044a23b1343e4f2d2ec34d08128cdf255ed4"
|
||||
integrity sha512-KTvqplh0ut7oDKovvDG6yzXM02R6X+9b2oVG+qYq8Zd3aCGTi51ASx4ThCNkAHyEvCuJdYg9fxXTL+j+wvhB5w==
|
||||
|
||||
Reference in New Issue
Block a user