mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove existing logs and warnings from tests (#48391)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48391 Changelog: [internal] When we enabled log streaming in Fantom, we saw a lot of logs that we were previously not forwarding (console.error, console.warn) in existing tests. This removes all the warnings and errors from those tests. Reviewed By: rshest Differential Revision: D67602299 fbshipit-source-id: 111f373eafd8707f2746ff727894f1fa4283b83f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d7d9e1c090
commit
fb3b87c2b5
+43
-25
@@ -76,28 +76,30 @@ describe('Fantom', () => {
|
||||
|
||||
// TODO: when error handling is fixed, this should verify using `toThrow`
|
||||
it('should throw when running a task inside another task', () => {
|
||||
let lastCallbackExecuted = 0;
|
||||
let threw = false;
|
||||
|
||||
runTask(() => {
|
||||
lastCallbackExecuted = 1;
|
||||
runTask(() => {
|
||||
lastCallbackExecuted = 2;
|
||||
throw new Error('Recursive runTask should be unreachable');
|
||||
});
|
||||
// TODO replace with expect(() => { ... }).toThrow() when error handling is fixed
|
||||
try {
|
||||
runTask(() => {});
|
||||
} catch {
|
||||
threw = true;
|
||||
}
|
||||
});
|
||||
expect(lastCallbackExecuted).toBe(1);
|
||||
expect(threw).toBe(true);
|
||||
|
||||
threw = false;
|
||||
|
||||
runTask(() => {
|
||||
queueMicrotask(() => {
|
||||
lastCallbackExecuted = 3;
|
||||
runTask(() => {
|
||||
lastCallbackExecuted = 4;
|
||||
throw new Error(
|
||||
'Recursive runTask from micro-task should be unreachable',
|
||||
);
|
||||
});
|
||||
try {
|
||||
runTask(() => {});
|
||||
} catch {
|
||||
threw = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
expect(lastCallbackExecuted).toBe(3);
|
||||
expect(threw).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -125,16 +127,24 @@ describe('Fantom', () => {
|
||||
runTask(() => {
|
||||
root.render(
|
||||
<>
|
||||
<View style={{width: 100, height: 100}} collapsable={false} />
|
||||
<View style={{width: 100, height: 100}} collapsable={false} />
|
||||
<View
|
||||
key="first"
|
||||
style={{width: 100, height: 100}}
|
||||
collapsable={false}
|
||||
/>
|
||||
<View
|
||||
key="second"
|
||||
style={{width: 100, height: 100}}
|
||||
collapsable={false}
|
||||
/>
|
||||
</>,
|
||||
);
|
||||
});
|
||||
|
||||
expect(root.getRenderedOutput().toJSX()).toEqual(
|
||||
<>
|
||||
<rn-view width="100.000000" height="100.000000" />
|
||||
<rn-view width="100.000000" height="100.000000" />
|
||||
<rn-view key="0" width="100.000000" height="100.000000" />
|
||||
<rn-view key="1" width="100.000000" height="100.000000" />
|
||||
</>,
|
||||
);
|
||||
|
||||
@@ -233,18 +243,26 @@ describe('Fantom', () => {
|
||||
runTask(() => {
|
||||
root.render(
|
||||
<>
|
||||
<View style={{width: 100, height: 100}} collapsable={false} />
|
||||
<Text>hello world!</Text>
|
||||
<View style={{width: 200, height: 300}} collapsable={false} />
|
||||
<View
|
||||
key="first"
|
||||
style={{width: 100, height: 100}}
|
||||
collapsable={false}
|
||||
/>
|
||||
<Text key="second">hello world!</Text>
|
||||
<View
|
||||
key="third"
|
||||
style={{width: 200, height: 300}}
|
||||
collapsable={false}
|
||||
/>
|
||||
</>,
|
||||
);
|
||||
});
|
||||
|
||||
expect(root.getRenderedOutput({props: []}).toJSX()).toEqual(
|
||||
<>
|
||||
<rn-view />
|
||||
<rn-paragraph>hello world!</rn-paragraph>
|
||||
<rn-view />
|
||||
<rn-view key="0" />
|
||||
<rn-paragraph key="1">hello world!</rn-paragraph>
|
||||
<rn-view key="2" />
|
||||
</>,
|
||||
);
|
||||
|
||||
|
||||
@@ -152,16 +152,20 @@ function convertRawJsonToJSX(
|
||||
function createJSXElementForTestComparison(
|
||||
type: string,
|
||||
props: mixed,
|
||||
key?: ?string,
|
||||
): React.Node {
|
||||
const Tag = type;
|
||||
return <Tag {...props} />;
|
||||
return <Tag key={key} {...props} />;
|
||||
}
|
||||
|
||||
function rnTypeToTestType(type: string): string {
|
||||
return `rn-${type.substring(0, 1).toLowerCase() + type.substring(1)}`;
|
||||
}
|
||||
|
||||
function jsonChildToJSXChild(jsonChild: FantomJsonObject | string): React.Node {
|
||||
function jsonChildToJSXChild(
|
||||
jsonChild: FantomJsonObject | string,
|
||||
index?: ?number,
|
||||
): React.Node {
|
||||
if (typeof jsonChild === 'string') {
|
||||
return jsonChild;
|
||||
} else {
|
||||
@@ -172,6 +176,7 @@ function jsonChildToJSXChild(jsonChild: FantomJsonObject | string): React.Node {
|
||||
jsxChildren == null
|
||||
? jsonChild.props
|
||||
: {...jsonChild.props, children: jsxChildren},
|
||||
index != null ? String(index) : undefined,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -184,7 +189,7 @@ function jsonChildrenToJSXChildren(jsonChildren: FantomJsonObject['children']) {
|
||||
let allJSXChildrenAreStrings = true;
|
||||
let jsxChildrenString = '';
|
||||
for (let i = 0; i < jsonChildren.length; i++) {
|
||||
const jsxChild = jsonChildToJSXChild(jsonChildren[i]);
|
||||
const jsxChild = jsonChildToJSXChild(jsonChildren[i], i);
|
||||
jsxChildren.push(jsxChild);
|
||||
if (allJSXChildrenAreStrings) {
|
||||
if (typeof jsxChild === 'string') {
|
||||
|
||||
+10
-22
@@ -487,7 +487,6 @@ describe('IntersectionObserver', () => {
|
||||
maybeNode = receivedNode;
|
||||
}}
|
||||
/>
|
||||
,
|
||||
</ScrollView>,
|
||||
);
|
||||
});
|
||||
@@ -549,7 +548,6 @@ describe('IntersectionObserver', () => {
|
||||
maybeNode = receivedNode;
|
||||
}}
|
||||
/>
|
||||
,
|
||||
</ScrollView>,
|
||||
);
|
||||
});
|
||||
@@ -610,7 +608,6 @@ describe('IntersectionObserver', () => {
|
||||
maybeNode = receivedNode;
|
||||
}}
|
||||
/>
|
||||
,
|
||||
</ScrollView>,
|
||||
);
|
||||
});
|
||||
@@ -942,7 +939,6 @@ describe('IntersectionObserver', () => {
|
||||
maybeNode = receivedNode;
|
||||
}}
|
||||
/>
|
||||
,
|
||||
</ScrollView>,
|
||||
);
|
||||
});
|
||||
@@ -1003,7 +999,6 @@ describe('IntersectionObserver', () => {
|
||||
maybeNode = receivedNode;
|
||||
}}
|
||||
/>
|
||||
,
|
||||
</ScrollView>,
|
||||
);
|
||||
});
|
||||
@@ -1314,13 +1309,9 @@ describe('IntersectionObserver', () => {
|
||||
});
|
||||
expect(node.isConnected).toBe(false);
|
||||
|
||||
Fantom.runTask(() => {
|
||||
observer = new IntersectionObserver(() => {});
|
||||
observer.observe(node);
|
||||
// TODO what happens if this throws an exception?
|
||||
observer.unobserve(node);
|
||||
throw new Error('unobserve should not throw');
|
||||
});
|
||||
observer = new IntersectionObserver(() => {});
|
||||
observer.observe(node);
|
||||
observer.unobserve(node);
|
||||
});
|
||||
|
||||
it('should not report the initial state if the target is unobserved before it is delivered', () => {
|
||||
@@ -1497,19 +1488,16 @@ describe('IntersectionObserver', () => {
|
||||
|
||||
const node = ensureReactNativeElement(maybeNode);
|
||||
|
||||
Fantom.runTask(() => {
|
||||
observer1 = new IntersectionObserver(() => {});
|
||||
observer2 = new IntersectionObserver(() => {});
|
||||
observer1 = new IntersectionObserver(() => {});
|
||||
observer2 = new IntersectionObserver(() => {});
|
||||
|
||||
observer1.observe(node);
|
||||
observer2.observe(node);
|
||||
observer1.observe(node);
|
||||
observer2.observe(node);
|
||||
|
||||
observer1.unobserve(node);
|
||||
observer1.unobserve(node);
|
||||
|
||||
// The second call shouldn't log errors (that would make the test fail).
|
||||
observer2.unobserve(node);
|
||||
throw new Error('unobserve should not throw');
|
||||
});
|
||||
// The second call shouldn't log errors (that would make the test fail).
|
||||
observer2.unobserve(node);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Vendored
+8
-8
@@ -383,14 +383,14 @@ describe('MutationObserver', () => {
|
||||
<View
|
||||
key="node1"
|
||||
ref={receivedNode => {
|
||||
maybeObservedNode = ensureReactNativeElement(receivedNode);
|
||||
maybeObservedNode = receivedNode;
|
||||
}}>
|
||||
<View key="node1-1" />
|
||||
</View>,
|
||||
);
|
||||
});
|
||||
|
||||
const observedNode = nullthrows(maybeObservedNode);
|
||||
const observedNode = ensureReactNativeElement(maybeObservedNode);
|
||||
|
||||
const observerCallback = jest.fn();
|
||||
const observer = new MutationObserver(observerCallback);
|
||||
@@ -968,13 +968,13 @@ describe('MutationObserver', () => {
|
||||
<View
|
||||
key="node1"
|
||||
ref={receivedNode => {
|
||||
maybeObservedNode = ensureReactNativeElement(receivedNode);
|
||||
maybeObservedNode = receivedNode;
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
const observedNode = nullthrows(maybeObservedNode);
|
||||
const observedNode = ensureReactNativeElement(maybeObservedNode);
|
||||
|
||||
const observerCallback = jest.fn();
|
||||
const observer = new MutationObserver(observerCallback);
|
||||
@@ -1016,13 +1016,13 @@ describe('MutationObserver', () => {
|
||||
<View
|
||||
key="node1"
|
||||
ref={receivedNode => {
|
||||
maybeObservedNode = ensureReactNativeElement(receivedNode);
|
||||
maybeObservedNode = receivedNode;
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
const observedNode = nullthrows(maybeObservedNode);
|
||||
const observedNode = ensureReactNativeElement(maybeObservedNode);
|
||||
|
||||
const observerCallback = jest.fn();
|
||||
const observer = new MutationObserver(observerCallback);
|
||||
@@ -1048,13 +1048,13 @@ describe('MutationObserver', () => {
|
||||
<View
|
||||
key="node1"
|
||||
ref={receivedNode => {
|
||||
maybeObservedNode = ensureReactNativeElement(receivedNode);
|
||||
maybeObservedNode = receivedNode;
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
const observedNode = nullthrows(maybeObservedNode);
|
||||
const observedNode = ensureReactNativeElement(maybeObservedNode);
|
||||
|
||||
Fantom.runTask(() => {
|
||||
root.render(<></>);
|
||||
|
||||
Reference in New Issue
Block a user