kill RCTRootViewIntegrationTests (#38871)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38871

Changelog: [Internal]

these tests are the last callsite where we are getting event emitter off of RCTRootView... these particular tests have been disabled and they're like 8 years old, sooooooo i think it's just easier for me to delete them

Reviewed By: cipolleschi

Differential Revision: D48179389

fbshipit-source-id: 9fe36323606f53c9b6fde8b4c20d51a2cb1f6c9c
This commit is contained in:
Phillip Pan
2023-08-22 19:45:27 -07:00
committed by Facebook GitHub Bot
parent ab6349a0e4
commit 97efa25afa
6 changed files with 0 additions and 468 deletions
@@ -1,29 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const React = require('react');
const ReactNative = require('react-native');
const {View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
class PropertiesUpdateTest extends React.Component {
render() {
if (this.props.markTestPassed) {
TestModule.markTestPassed(true);
}
return <View />;
}
}
PropertiesUpdateTest.displayName = 'PropertiesUpdateTest';
module.exports = PropertiesUpdateTest;
@@ -1,86 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const React = require('react');
const ReactNative = require('react-native');
const {AppRegistry, ScrollView, StyleSheet, Text, TouchableOpacity, View} =
ReactNative;
/* Keep this list in sync with RCTRootViewIntegrationTests.m */
const TESTS = [
require('./PropertiesUpdateTest'),
require('./ReactContentSizeUpdateTest'),
require('./SizeFlexibilityUpdateTest'),
];
TESTS.forEach(test =>
AppRegistry.registerComponent(test.displayName, () => test),
);
class RCTRootViewIntegrationTestApp extends React.Component {
state = {
test: null,
};
render() {
if (this.state.test) {
return (
<ScrollView>
<this.state.test />
</ScrollView>
);
}
return (
<View style={styles.container}>
<Text style={styles.row}>
Click on a test to run it in this shell for easier debugging and
development. Run all tests in the testing environment with cmd+U in
Xcode.
</Text>
<View style={styles.separator} />
<ScrollView>
{TESTS.map(test => [
<TouchableOpacity
onPress={() => this.setState({test})}
style={styles.row}>
<Text style={styles.testName}>{test.displayName}</Text>
</TouchableOpacity>,
<View style={styles.separator} />,
])}
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
marginTop: 40,
margin: 15,
},
row: {
padding: 10,
},
testName: {
fontWeight: '500',
},
separator: {
height: 1,
backgroundColor: '#bbbbbb',
},
});
AppRegistry.registerComponent(
'RCTRootViewIntegrationTestApp',
() => RCTRootViewIntegrationTestApp,
);
@@ -1,89 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/
const RCTNativeAppEventEmitter = require('react-native/Libraries/EventEmitter/RCTNativeAppEventEmitter');
const React = require('react');
const ReactNative = require('react-native');
const {View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
import {type EventSubscription} from 'react-native/Libraries/vendor/emitter/EventEmitter';
const reactViewWidth = 101;
const reactViewHeight = 102;
const newReactViewWidth = 201;
const newReactViewHeight = 202;
type Props = {||};
type State = {|
height: number,
width: number,
|};
class ReactContentSizeUpdateTest extends React.Component<Props, State> {
_timeoutID: ?TimeoutID = null;
_subscription: ?EventSubscription = null;
state: State = {
height: reactViewHeight,
width: reactViewWidth,
};
UNSAFE_componentWillMount() {
this._subscription = RCTNativeAppEventEmitter.addListener(
'rootViewDidChangeIntrinsicSize',
this.rootViewDidChangeIntrinsicSize,
);
}
componentDidMount() {
this._timeoutID = setTimeout(() => {
this.updateViewSize();
}, 1000);
}
componentWillUnmount() {
if (this._timeoutID != null) {
clearTimeout(this._timeoutID);
}
if (this._subscription != null) {
this._subscription.remove();
}
}
updateViewSize() {
this.setState({
height: newReactViewHeight,
width: newReactViewWidth,
});
}
rootViewDidChangeIntrinsicSize: (intrinsicSize: State) => void = (
intrinsicSize: State,
) => {
if (
intrinsicSize.height === newReactViewHeight &&
intrinsicSize.width === newReactViewWidth
) {
TestModule.markTestPassed(true);
}
};
render(): React.Node {
return (
<View style={{height: this.state.height, width: this.state.width}} />
);
}
}
module.exports = ReactContentSizeUpdateTest;
@@ -1,106 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/
const RCTNativeAppEventEmitter = require('react-native/Libraries/EventEmitter/RCTNativeAppEventEmitter');
const React = require('react');
const ReactNative = require('react-native');
const {View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
import {type EventSubscription} from 'react-native/Libraries/vendor/emitter/EventEmitter';
const reactViewWidth = 111;
const reactViewHeight = 222;
let finalState = false;
type Props = $ReadOnly<{|
width: boolean,
height: boolean,
both: boolean,
none: boolean,
|}>;
class SizeFlexibilityUpdateTest extends React.Component<Props> {
_subscription: ?EventSubscription = null;
UNSAFE_componentWillMount() {
this._subscription = RCTNativeAppEventEmitter.addListener(
'rootViewDidChangeIntrinsicSize',
this.rootViewDidChangeIntrinsicSize,
);
}
componentWillUnmount() {
if (this._subscription != null) {
this._subscription.remove();
}
}
markPassed: () => void = () => {
TestModule.markTestPassed(true);
finalState = true;
};
rootViewDidChangeIntrinsicSize: (intrinsicSize: {
height: number,
width: number,
...
}) => void = (intrinsicSize: {width: number, height: number, ...}) => {
if (finalState) {
// If a test reaches its final state, it is not expected to do anything more
TestModule.markTestPassed(false);
return;
}
if (this.props.both) {
if (
intrinsicSize.width === reactViewWidth &&
intrinsicSize.height === reactViewHeight
) {
this.markPassed();
return;
}
}
if (this.props.height) {
if (
intrinsicSize.width !== reactViewWidth &&
intrinsicSize.height === reactViewHeight
) {
this.markPassed();
return;
}
}
if (this.props.width) {
if (
intrinsicSize.width === reactViewWidth &&
intrinsicSize.height !== reactViewHeight
) {
this.markPassed();
return;
}
}
if (this.props.none) {
if (
intrinsicSize.width !== reactViewWidth &&
intrinsicSize.height !== reactViewHeight
) {
this.markPassed();
return;
}
}
};
render(): React.Node {
return <View style={{height: reactViewHeight, width: reactViewWidth}} />;
}
}
module.exports = SizeFlexibilityUpdateTest;
@@ -1,154 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <RCTTest/RCTTestRunner.h>
#import <React/RCTEventDispatcherProtocol.h>
#import <React/RCTRootView.h>
#import <React/RCTRootViewDelegate.h>
#define RCT_TEST_DATA_CONFIGURATION_BLOCK(appName, testType, input, block) \
-(void)DISABLED_test##appName##_##testType##_##input \
{ \
[_runner runTest:_cmd module:@ #appName initialProps:@{@ #input : @YES} configurationBlock:block]; \
}
#define RCT_TEST_CONFIGURATION_BLOCK(appName, block) \
-(void)DISABLED_test##appName \
{ \
[_runner runTest:_cmd module:@ #appName initialProps:nil configurationBlock:block]; \
}
#define RCTNone RCTRootViewSizeFlexibilityNone
#define RCTHeight RCTRootViewSizeFlexibilityHeight
#define RCTWidth RCTRootViewSizeFlexibilityWidth
#define RCTBoth RCTRootViewSizeFlexibilityWidthAndHeight
typedef void (^ControlBlock)(RCTRootView *);
@interface SizeFlexibilityTestDelegate : NSObject <RCTRootViewDelegate>
@end
@implementation SizeFlexibilityTestDelegate
- (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[rootView.eventDispatcher
sendAppEventWithName:@"rootViewDidChangeIntrinsicSize"
body:@{@"width" : @(rootView.intrinsicSize.width), @"height" : @(rootView.intrinsicSize.height)}];
#pragma clang diagnostic pop
}
@end
static SizeFlexibilityTestDelegate *sizeFlexibilityDelegate(void)
{
static SizeFlexibilityTestDelegate *delegate;
if (delegate == nil) {
delegate = [SizeFlexibilityTestDelegate new];
}
return delegate;
}
static ControlBlock simpleSizeFlexibilityBlock(RCTRootViewSizeFlexibility sizeFlexibility)
{
return ^(RCTRootView *rootView) {
rootView.delegate = sizeFlexibilityDelegate();
rootView.sizeFlexibility = sizeFlexibility;
};
}
static ControlBlock multipleSizeFlexibilityUpdatesBlock(RCTRootViewSizeFlexibility finalSizeFlexibility)
{
return ^(RCTRootView *rootView) {
NSInteger arr[4] = {RCTNone, RCTHeight, RCTWidth, RCTBoth};
rootView.delegate = sizeFlexibilityDelegate();
for (int i = 0; i < 4; ++i) {
if (arr[i] != finalSizeFlexibility) {
rootView.sizeFlexibility = arr[i];
}
}
rootView.sizeFlexibility = finalSizeFlexibility;
};
}
static ControlBlock reactContentSizeUpdateBlock(RCTRootViewSizeFlexibility sizeFlexibility)
{
return ^(RCTRootView *rootView) {
rootView.delegate = sizeFlexibilityDelegate();
rootView.sizeFlexibility = sizeFlexibility;
};
}
@interface RCTRootViewIntegrationTests : XCTestCase
@end
@implementation RCTRootViewIntegrationTests {
RCTTestRunner *_runner;
}
- (void)setUp
{
_runner = RCTInitRunnerForApp(@"IntegrationTests/RCTRootViewIntegrationTestApp", nil, nil);
}
#pragma mark Logic Tests
// This list should be kept in sync with RCTRootViewIntegrationTestsApp.js
// Simple size flexibility tests - test if the content is measured properly
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, SingleUpdate, none, simpleSizeFlexibilityBlock(RCTNone));
RCT_TEST_DATA_CONFIGURATION_BLOCK(
SizeFlexibilityUpdateTest,
SingleUpdate,
height,
simpleSizeFlexibilityBlock(RCTHeight));
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, SingleUpdate, width, simpleSizeFlexibilityBlock(RCTWidth));
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, SingleUpdate, both, simpleSizeFlexibilityBlock(RCTBoth));
// Consider multiple size flexibility updates in a row. Test if the view's flexibility mode eventually is set to the
// expected value
RCT_TEST_DATA_CONFIGURATION_BLOCK(
SizeFlexibilityUpdateTest,
MultipleUpdates,
none,
multipleSizeFlexibilityUpdatesBlock(RCTNone));
RCT_TEST_DATA_CONFIGURATION_BLOCK(
SizeFlexibilityUpdateTest,
MultipleUpdates,
height,
multipleSizeFlexibilityUpdatesBlock(RCTHeight));
RCT_TEST_DATA_CONFIGURATION_BLOCK(
SizeFlexibilityUpdateTest,
MultipleUpdates,
width,
multipleSizeFlexibilityUpdatesBlock(RCTWidth));
RCT_TEST_DATA_CONFIGURATION_BLOCK(
SizeFlexibilityUpdateTest,
MultipleUpdates,
both,
multipleSizeFlexibilityUpdatesBlock(RCTBoth));
// Test if the 'rootViewDidChangeIntrinsicSize' delegate method is called after the RN app decides internally to resize
RCT_TEST_CONFIGURATION_BLOCK(ReactContentSizeUpdateTest, reactContentSizeUpdateBlock(RCTBoth))
// Test if setting 'appProperties' property updates the RN app
RCT_TEST_CONFIGURATION_BLOCK(PropertiesUpdateTest, ^(RCTRootView *rootView) {
rootView.appProperties = @{@"markTestPassed" : @YES};
})
@end
@@ -56,7 +56,6 @@
E7DB216322B2F3EC005AC45F /* RCTLoggingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB215E22B2F3EC005AC45F /* RCTLoggingTests.m */; };
E7DB216422B2F3EC005AC45F /* RCTUIManagerScenarioTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB215F22B2F3EC005AC45F /* RCTUIManagerScenarioTests.m */; };
E7DB216522B2F3EC005AC45F /* RNTesterSnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB216022B2F3EC005AC45F /* RNTesterSnapshotTests.m */; };
E7DB216622B2F3EC005AC45F /* RCTRootViewIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB216122B2F3EC005AC45F /* RCTRootViewIntegrationTests.m */; };
E7DB216722B2F69F005AC45F /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7DB213022B2C649005AC45F /* JavaScriptCore.framework */; };
E7DB218C22B41FCD005AC45F /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7DB218B22B41FCD005AC45F /* XCTest.framework */; };
/* End PBXBuildFile section */
@@ -176,7 +175,6 @@
E7DB215E22B2F3EC005AC45F /* RCTLoggingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTLoggingTests.m; sourceTree = "<group>"; };
E7DB215F22B2F3EC005AC45F /* RCTUIManagerScenarioTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUIManagerScenarioTests.m; sourceTree = "<group>"; };
E7DB216022B2F3EC005AC45F /* RNTesterSnapshotTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNTesterSnapshotTests.m; sourceTree = "<group>"; };
E7DB216122B2F3EC005AC45F /* RCTRootViewIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTRootViewIntegrationTests.m; sourceTree = "<group>"; };
E7DB218B22B41FCD005AC45F /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = XCTest.framework; sourceTree = DEVELOPER_DIR; };
/* End PBXFileReference section */
@@ -391,7 +389,6 @@
children = (
E7C1241922BEC44B00DA25C0 /* RNTesterIntegrationTests.m */,
E7DB215E22B2F3EC005AC45F /* RCTLoggingTests.m */,
E7DB216122B2F3EC005AC45F /* RCTRootViewIntegrationTests.m */,
E7DB215F22B2F3EC005AC45F /* RCTUIManagerScenarioTests.m */,
E7DB216022B2F3EC005AC45F /* RNTesterSnapshotTests.m */,
E7DB215D22B2F3EC005AC45F /* RNTesterTestModule.m */,
@@ -798,7 +795,6 @@
E7DB216222B2F3EC005AC45F /* RNTesterTestModule.m in Sources */,
E7C1241A22BEC44B00DA25C0 /* RNTesterIntegrationTests.m in Sources */,
E7DB216322B2F3EC005AC45F /* RCTLoggingTests.m in Sources */,
E7DB216622B2F3EC005AC45F /* RCTRootViewIntegrationTests.m in Sources */,
E7DB216422B2F3EC005AC45F /* RCTUIManagerScenarioTests.m in Sources */,
E7DB216522B2F3EC005AC45F /* RNTesterSnapshotTests.m in Sources */,
);