Skip to content

Fix to RCTTestRunner so that RedBox errors are logged when piped thru… #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Libraries/RCTTest/RCTTestRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
if (expectErrorBlock) {
RCTAssert(expectErrorBlock(errors[0]), @"Expected an error but the first one was missing or did not match.");
} else {
RCTAssert(errors == nil, @"RedBox errors: %@", errors);
// [TODO(OSS Candidate ISS#2710739): xcpretty formats the test failure output to show only one line of the assert string followed by a snippet of source code including the assert statement and the lines just before and after.
// Convert the `errors` array into a single line string delimited by \n so that CI logs contain meaningful information.
RCTAssert(errors == nil, @"RedBox errors: %@", [[errors valueForKey:@"description"] componentsJoinedByString:@"\\n"]); // ]TODO(OSS Candidate ISS#2710739)
RCTAssert(testModule.status != RCTTestStatusPending, @"Test didn't finish within %0.f seconds", kTestTimeoutSeconds);
RCTAssert(testModule.status == RCTTestStatusPassed, @"Test failed");
}
Expand Down
6 changes: 5 additions & 1 deletion Libraries/WebSocket/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ class WebSocket extends EventTarget(...WEBSOCKET_EVENTS) {
}

_close(code?: number, reason?: string): void {
if (Platform.OS === 'android' || Platform.OS === 'win32' || Platform.OS == 'windesktop') {
if (
Platform.OS === 'android' ||
Platform.OS === 'win32' ||
Platform.OS === 'windesktop'
) {
// See https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
const statusCode = typeof code === 'number' ? code : CLOSE_NORMAL;
const closeReason = typeof reason === 'string' ? reason : '';
Expand Down
14 changes: 14 additions & 0 deletions RNTester/js/RNTesterApp.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,21 @@ const Header = ({onBack, title}: {onBack?: () => mixed, title: string}) => (
);

class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
_mounted: boolean; // TODO(OSS Candidate ISS#2710739)

UNSAFE_componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', this._handleBack);
}

componentDidMount() {
this._mounted = true; // TODO(OSS Candidate ISS#2710739)
Linking.getInitialURL().then(url => {
AsyncStorage.getItem(APP_STATE_KEY, (err, storedString) => {
// [TODO(OSS Candidate ISS#2710739)
if (!this._mounted) {
return;
}
// ]TODO(OSS Candidate ISS#2710739)
const exampleAction = URIActionMap(
this.props.exampleFromAppetizeParams,
);
Expand All @@ -89,6 +97,12 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
});
}

// [TODO(OSS Candidate ISS#2710739)
componentWillUnmount() {
this._mounted = false;
}
// ]TODO(OSS Candidate ISS#2710739)

_handleBack = () => {
this._handleAction(RNTesterActions.Back());
};
Expand Down
14 changes: 14 additions & 0 deletions RNTester/js/RNTesterApp.macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,21 @@ const Header = ({onBack, title}: {onBack?: () => mixed, title: string}) => (
);

class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
_mounted: boolean; // TODO(OSS Candidate ISS#2710739)

UNSAFE_componentWillMount() {
// BackHandler.addEventListener('hardwareBackPress', this._handleBack);
}

componentDidMount() {
this._mounted = true; // TODO(OSS Candidate ISS#2710739)
Linking.getInitialURL().then(url => {
AsyncStorage.getItem(APP_STATE_KEY, (err, storedString) => {
// [TODO(OSS Candidate ISS#2710739)
if (!this._mounted) {
return;
}
// ]TODO(OSS Candidate ISS#2710739)
const exampleAction = URIActionMap(
this.props.exampleFromAppetizeParams,
);
Expand All @@ -91,6 +99,12 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
});
}

// [TODO(OSS Candidate ISS#2710739)
componentWillUnmount() {
this._mounted = false;
}
// ]TODO(OSS Candidate ISS#2710739)

_handleBack = () => {
this._handleAction(RNTesterActions.Back());
};
Expand Down