console preview for Error objects (#46010)

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

X-link: https://github.com/facebook/hermes/pull/1474

Changelog:
[General][Added]: support for rendering Error object previews in Chrome DevTools console

On web, an array of Error objects have previews. This diff brings the parity to RN DevTools

Reviewed By: huntie

Differential Revision: D61243518

fbshipit-source-id: d9c6af4b44cef44cb63c4462eee649a8e498a429
This commit is contained in:
Edmond Chui
2024-08-15 19:42:52 -07:00
committed by Facebook GitHub Bot
parent 1740a56a46
commit cae9ae5b48
@@ -306,6 +306,35 @@ TEST_P(ConsoleApiTest, testConsoleLogWithErrorObject) {
})())");
}
TEST_P(ConsoleApiTest, testConsoleLogWithArrayOfErrors) {
InSequence s;
expectConsoleApiCallImmediate(AllOf(
AtJsonPtr("/type", "log"),
AtJsonPtr("/args/0/type", "object"),
AtJsonPtr("/args/0/subtype", "array"),
AtJsonPtr("/args/0/description", "Array(2)"),
AtJsonPtr("/args/0/preview/description", "Array(2)"),
AtJsonPtr("/args/0/preview/type", "object"),
AtJsonPtr("/args/0/preview/subtype", "array"),
AtJsonPtr("/args/0/preview/properties/0/type", "object"),
AtJsonPtr("/args/0/preview/properties/0/subtype", "error"),
AtJsonPtr(
"/args/0/preview/properties/0/value",
"Error: wut\n"
" at typicallyUrlsAreLongAndWillHitTheAbbreviationLimit (<eval>:6:29)\n"
" at reallyLon…")));
expectConsoleApiCallBuffered(AllOf(AtJsonPtr("/type", "log")));
eval(R"((() => {
function reallyLongFunctionNameToAssertMaxLengthOfAbbreviatedString() {
typicallyUrlsAreLongAndWillHitTheAbbreviationLimit();
}
function typicallyUrlsAreLongAndWillHitTheAbbreviationLimit() {
console.log([new Error('wut'), new TypeError('why')]);
}
reallyLongFunctionNameToAssertMaxLengthOfAbbreviatedString();
})())");
}
TEST_P(ConsoleApiTest, testConsoleWarn) {
InSequence s;
expectConsoleApiCall(AllOf(