-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port Xcode 9 XCTAttachment API integration from FB repo #19
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*
aligned with the variable
} | ||
|
||
return nil; | ||
} | ||
|
||
- (void) addAttachmentsWithErrors:(NSArray<NSError *> *)errors identifier:(NSString *)identifier { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/attachement/attachment
} | ||
|
||
return nil; | ||
} | ||
|
||
- (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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.