Port Xcode 9 XCTAttachment API integration from FB repo#19
Port Xcode 9 XCTAttachment API integration from FB repo#19delebedev wants to merge 5 commits intouber:masterfrom delebedev:attachments
Conversation
|
|
| - (void) addAttachmentsWithErrors:(NSArray<NSError *> *)errors identifier:(NSString *)identifier { | ||
| #if defined(__IPHONE_11_0) || defined(__TVOS_11_0) | ||
| if (self.recordMode) { | ||
| UIImage* image = [_snapshotController referenceImageForSelector:self.invocation.selector identifier:identifier error:nil]; |
There was a problem hiding this comment.
* aligned with the variable
| return nil; | ||
| } | ||
|
|
||
| - (void) addAttachmentsWithErrors:(NSArray<NSError *> *)errors identifier:(NSString *)identifier { |
There was a problem hiding this comment.
An internal method should be prefixed with _, there should be no space between the return type and the start of the method name, and the first opening brace should be on a new line
| if (self.recordMode) { | ||
| UIImage* image = [_snapshotController referenceImageForSelector:self.invocation.selector identifier:identifier error:nil]; | ||
| if (image) { | ||
| XCTAttachment *attachement = [XCTAttachment attachmentWithImage:image]; |
There was a problem hiding this comment.
s/attachement/attachment
|
|
||
| - (void) addAttachmentsWithErrors:(NSArray<NSError *> *)errors identifier:(NSString *)identifier { | ||
| #if defined(__IPHONE_11_0) || defined(__TVOS_11_0) | ||
| if (self.recordMode) { |
There was a problem hiding this comment.
I would pass this in to the method, say as ranInRecordMode
| } else if (errors.firstObject != nil) { | ||
| NSError *error = errors.firstObject; | ||
| if (error.userInfo[FBReferenceImageKey] != nil) { | ||
| XCTAttachment *attachement = [XCTAttachment attachmentWithImage:error.userInfo[FBReferenceImageKey]]; |
There was a problem hiding this comment.
s/attachement/attachment
| [self addAttachment:attachement]; | ||
| } | ||
| if (error.userInfo[FBCapturedImageKey] != nil) { | ||
| XCTAttachment *attachement = [XCTAttachment attachmentWithImage:error.userInfo[FBCapturedImageKey]]; |
There was a problem hiding this comment.
s/attachement/attachment
| [self addAttachment:attachement]; | ||
| } | ||
| if (error.userInfo[FBDiffedImageKey] != nil) { | ||
| XCTAttachment *attachement = [XCTAttachment attachmentWithImage:error.userInfo[FBDiffedImageKey]]; |
There was a problem hiding this comment.
s/attachement/attachment
| if (self.recordMode) { | ||
| return @"Test ran in record mode. Reference image is now saved. Disable record mode to perform an actual snapshot comparison!"; | ||
| if (errors.count > 0) { | ||
| return [NSString stringWithFormat:@"Snapshot comparison failed: %@", errors.firstObject]; |
There was a problem hiding this comment.
Is this possible? Looking at L102-L105, it is doing this:
BOOL referenceImageSaved = [self _compareSnapshotOfViewOrLayer:viewOrLayer referenceImagesDirectory:referenceImagesDirectory identifier:(identifier) tolerance:tolerance error:&error];
if (!referenceImageSaved) {
[errors addObject:error];
}
When self.recordMode is on, compareSnapshotOfViewOrLayer:... the BOOL from the function relates to whether or not the reference image was saved.
| FBSnapshotVerifyViewOrLayer(layer, identifier: identifier, suffixes: suffixes, tolerance: tolerance, file: file, line: line) | ||
| } | ||
|
|
||
| private func FBSnapshotVerifyViewOrLayer(_ viewOrLayer: AnyObject, identifier: String = "", suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), tolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) { |
There was a problem hiding this comment.
I believe there's a good reason why SwiftSupport.swift uses its own FBSnapshotVerifyViewOrLayer function instead of leveraging the Objective-C one. This should probably stay as is, with modifications to support this new attachment feature though.
|
Not sure how much of these questions you can answer, since you weren't the original author. If you want, I can take this PR and make the change instead. |
|
@alanzeino I tried to understand what was the reasoning behind deleting part of swift code and how I can apply new attachement logic to I've fixed coding style and some other issues you've flagged and would appreciate your help with reverting changes to |
|
@alanzeino any chance you can have a look at this PR? I appreciate you maintaining the lib and I think this PR is very useful addition to the upstream |
|
@delebedev I was waiting on you to revert the changes to SwiftSupport.swift and to reimplement this as needed there (you can revert a change in a file in git using Would you like me to implement this feature? I think since the original author isn't around it would be better if I just take a look at this. |
|
@alanzeino please do it, as I've written above in the comments I don't really know which parts of |
|
This feature was added by #86 |
facebookarchive/ios-snapshot-test-case#230 (comment)
Author of original PR (@SiarheiFedartsou was Ok with delegating it to me 😄 )
===
I've signed CLA but it's taking a while to update it seems.