From cae9ae5b486d04b889af9d1685bcbbb33557c791 Mon Sep 17 00:00:00 2001 From: Edmond Chui Date: Thu, 15 Aug 2024 19:42:52 -0700 Subject: [PATCH] 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 --- .../tests/ConsoleApiTest.cpp | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/ConsoleApiTest.cpp b/packages/react-native/ReactCommon/jsinspector-modern/tests/ConsoleApiTest.cpp index 1f30fcd2262..56e15c65a34 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/ConsoleApiTest.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/ConsoleApiTest.cpp @@ -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 (: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(