mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
Update RCTFormatError to support segment ids
Reviewed By: PeteTheHeat Differential Revision: D13507444 fbshipit-source-id: ed55ce4cfa26f54db87a753867b6cf710936ba5a
This commit is contained in:
committed by
Facebook Github Bot
parent
ae121690eb
commit
97eb53d14f
@@ -128,6 +128,8 @@
|
||||
8385CEF51B873B5C00C6273E /* RCTImageLoaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8385CEF41B873B5C00C6273E /* RCTImageLoaderTests.m */; };
|
||||
8385CF041B87479200C6273E /* RCTImageLoaderHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 8385CF031B87479200C6273E /* RCTImageLoaderHelpers.m */; };
|
||||
BC9C03401DC9F1D600B1C635 /* RCTDevMenuTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BC9C033F1DC9F1D600B1C635 /* RCTDevMenuTests.m */; };
|
||||
C60A228221C9726800B820FE /* RCTFormatErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C60A228121C9726800B820FE /* RCTFormatErrorTests.m */; };
|
||||
C60A228321C9726800B820FE /* RCTFormatErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C60A228121C9726800B820FE /* RCTFormatErrorTests.m */; };
|
||||
C654F0B31EB34A73000B7A9A /* RNTesterTestModule.m in Sources */ = {isa = PBXBuildFile; fileRef = C654F0B21EB34A73000B7A9A /* RNTesterTestModule.m */; };
|
||||
C654F17E1EB34D24000B7A9A /* RNTesterTestModule.m in Sources */ = {isa = PBXBuildFile; fileRef = C654F0B21EB34A73000B7A9A /* RNTesterTestModule.m */; };
|
||||
D85B829E1AB6D5D7003F4FE2 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D85B829C1AB6D5CE003F4FE2 /* libRCTVibration.a */; };
|
||||
@@ -563,6 +565,7 @@
|
||||
8385CF031B87479200C6273E /* RCTImageLoaderHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTImageLoaderHelpers.m; sourceTree = "<group>"; };
|
||||
8385CF051B8747A000C6273E /* RCTImageLoaderHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTImageLoaderHelpers.h; sourceTree = "<group>"; };
|
||||
BC9C033F1DC9F1D600B1C635 /* RCTDevMenuTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDevMenuTests.m; sourceTree = "<group>"; };
|
||||
C60A228121C9726800B820FE /* RCTFormatErrorTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTFormatErrorTests.m; sourceTree = "<group>"; };
|
||||
C654F0B21EB34A73000B7A9A /* RNTesterTestModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNTesterTestModule.m; sourceTree = "<group>"; };
|
||||
D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = ../Libraries/Vibration/RCTVibration.xcodeproj; sourceTree = "<group>"; };
|
||||
ED2970982150247000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS12.0.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; };
|
||||
@@ -801,6 +804,7 @@
|
||||
1497CFA71B21F5E400C1F8F2 /* RCTConvert_NSURLTests.m */,
|
||||
1497CFA81B21F5E400C1F8F2 /* RCTFontTests.m */,
|
||||
1497CFA91B21F5E400C1F8F2 /* RCTEventDispatcherTests.m */,
|
||||
C60A228121C9726800B820FE /* RCTFormatErrorTests.m */,
|
||||
1300627E1B59179B0043FE5A /* RCTGzipTests.m */,
|
||||
8385CF051B8747A000C6273E /* RCTImageLoaderHelpers.h */,
|
||||
8385CF031B87479200C6273E /* RCTImageLoaderHelpers.m */,
|
||||
@@ -1696,6 +1700,7 @@
|
||||
1497CFB01B21F5E400C1F8F2 /* RCTFontTests.m in Sources */,
|
||||
13BCE84F1C9C209600DD7AAD /* RCTComponentPropsTests.m in Sources */,
|
||||
144D21241B2204C5006DB32B /* RCTImageUtilTests.m in Sources */,
|
||||
C60A228221C9726800B820FE /* RCTFormatErrorTests.m in Sources */,
|
||||
1393D0381B68CD1300E1B601 /* RCTModuleMethodTests.mm in Sources */,
|
||||
1300627F1B59179B0043FE5A /* RCTGzipTests.m in Sources */,
|
||||
1497CFAF1B21F5E400C1F8F2 /* RCTConvert_NSURLTests.m in Sources */,
|
||||
@@ -1778,6 +1783,7 @@
|
||||
2D4BD8DA1DA2E20D005AC8A8 /* RCTGzipTests.m in Sources */,
|
||||
2D4BD8DB1DA2E20D005AC8A8 /* RCTImageLoaderHelpers.m in Sources */,
|
||||
2D4BD8D71DA2E20D005AC8A8 /* RCTConvert_NSURLTests.m in Sources */,
|
||||
C60A228321C9726800B820FE /* RCTFormatErrorTests.m in Sources */,
|
||||
2D4BD8E21DA2E20D005AC8A8 /* RCTModuleMethodTests.mm in Sources */,
|
||||
2D4BD8DF1DA2E20D005AC8A8 /* RCTMethodArgumentTests.m in Sources */,
|
||||
2D4BD8D31DA2E20D005AC8A8 /* RCTBundleURLProviderTests.m in Sources */,
|
||||
|
||||
40
RNTester/RNTesterUnitTests/RCTFormatErrorTests.m
Normal file
40
RNTester/RNTesterUnitTests/RCTFormatErrorTests.m
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
*/
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import <React/RCTAssert.h>
|
||||
|
||||
@interface RCTFormatErrorTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTFormatErrorTests
|
||||
|
||||
- (void)testSymbolication {
|
||||
NSArray<NSDictionary<NSString *, id> *> *stackTrace = @[
|
||||
@{@"methodName": @"method_from_bundle", @"column": @11, @"lineNumber": @7, @"file": @"Fb4aBundle.js"},
|
||||
@{@"methodName": @"method_from_ram_bundle", @"column": @13, @"lineNumber": @18, @"file": @"199.js"},
|
||||
@{@"methodName": @"method_from_ram_bundle_with_address", @"column": @13, @"lineNumber": @18, @"file": @"address at 199.js"},
|
||||
@{@"methodName": @"method_from_segment", @"column": @18, @"lineNumber": @9, @"file": @"seg-1.js"},
|
||||
@{@"methodName": @"method_from_segment_with_address", @"column": @18, @"lineNumber": @9, @"file": @"address at seg-1.js"},
|
||||
@{@"methodName": @"method_from_ram_segment", @"column": @20, @"lineNumber": @10, @"file": @"seg-3_198.js"},
|
||||
@{@"methodName": @"method_from_ram_segment_with_address", @"column": @20, @"lineNumber": @10, @"file": @"address at seg-3_198.js"}
|
||||
];
|
||||
NSString *message = RCTFormatError(@"Error", stackTrace, 0);
|
||||
XCTAssertEqualObjects(message, @"Error, stack:\n"
|
||||
"method_from_bundle@7:11\n"
|
||||
"method_from_ram_bundle@199.js:18:13\n"
|
||||
"method_from_ram_bundle_with_address@199.js:18:13\n"
|
||||
"method_from_segment@seg-1.js:9:18\n"
|
||||
"method_from_segment_with_address@seg-1.js:9:18\n"
|
||||
"method_from_ram_segment@seg-3_198.js:10:20\n"
|
||||
"method_from_ram_segment_with_address@seg-3_198.js:10:20\n");
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -169,13 +169,14 @@ NSString *RCTFormatError(NSString *message, NSArray<NSDictionary<NSString *, id>
|
||||
if (stackTrace) {
|
||||
[prettyStack appendString:@", stack:\n"];
|
||||
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^(\\d+\\.js)$"
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\b((?:seg-\\d+(?:_\\d+)?|\\d+)\\.js)"
|
||||
options:NSRegularExpressionCaseInsensitive
|
||||
error:NULL];
|
||||
for (NSDictionary<NSString *, id> *frame in stackTrace) {
|
||||
NSString *fileName = [frame[@"file"] lastPathComponent];
|
||||
if (fileName && [regex numberOfMatchesInString:fileName options:0 range:NSMakeRange(0, [fileName length])]) {
|
||||
fileName = [fileName stringByAppendingString:@":"];
|
||||
NSTextCheckingResult *match = fileName != nil ? [regex firstMatchInString:fileName options:0 range:NSMakeRange(0, fileName.length)] : nil;
|
||||
if (match) {
|
||||
fileName = [NSString stringWithFormat:@"%@:", [fileName substringWithRange:match.range]];
|
||||
} else {
|
||||
fileName = @"";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user