Skip to content
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

Closed
wants to merge 5 commits into from
Closed

Port Xcode 9 XCTAttachment API integration from FB repo #19

wants to merge 5 commits into from

Conversation

delebedev
Copy link
Contributor

@delebedev delebedev commented Feb 26, 2018

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.

@CLAassistant
Copy link

CLAassistant commented Feb 26, 2018

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ SiarheiFedartsou
❌ delebedev
You have signed the CLA already but the status is still pending? Let us recheck it.

@delebedev delebedev changed the title Port Xcode 9 integration using XCTAttachment API from FB repo Port Xcode 9 XCTAttachment API integration from FB repo Feb 26, 2018
- (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];
Copy link
Collaborator

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 {
Copy link
Collaborator

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];
Copy link
Collaborator

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) {
Copy link
Collaborator

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]];
Copy link
Collaborator

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]];
Copy link
Collaborator

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]];
Copy link
Collaborator

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];
Copy link
Collaborator

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) {
Copy link
Collaborator

@alanzeino alanzeino Mar 9, 2018

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.

@alanzeino
Copy link
Collaborator

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.

@delebedev
Copy link
Contributor Author

delebedev commented Mar 10, 2018

@alanzeino I tried to understand what was the reasoning behind deleting part of swift code and how I can apply new attachement logic to FBSnapshotVerifyViewOrLayer in swift but due to quite a few ifs there I am just not certain how to do it right.

I've fixed coding style and some other issues you've flagged and would appreciate your help with reverting changes to SwiftSupport.swift.

@delebedev
Copy link
Contributor Author

@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

@alanzeino
Copy link
Collaborator

@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 git checkout HEAD^ path/to/the/file.swift — assuming you only have one commit on the branch, otherwise replace HEAD^ with the base commit).

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.

@delebedev
Copy link
Contributor Author

@alanzeino please do it, as I've written above in the comments I don't really know which parts of SwiftSupport should be reverted and which kept, better if you do it right yourself 👍

@reidmain
Copy link

This feature was added by #86

@reidmain reidmain closed this Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants