Skip to content

Port Xcode 9 XCTAttachment API integration from FB repo - #19

Closed
delebedev wants to merge 5 commits into
uber:masterfrom
delebedev:attachments
Closed

Port Xcode 9 XCTAttachment API integration from FB repo#19
delebedev wants to merge 5 commits into
uber:masterfrom
delebedev:attachments

Conversation

@delebedev

@delebedev delebedev commented Feb 26, 2018

Copy link
Copy Markdown
Contributor

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

CLAassistant commented Feb 26, 2018

Copy link
Copy Markdown

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
Comment thread FBSnapshotTestCase/FBSnapshotTestCase.m Outdated
- (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
Copy Markdown
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

Comment thread FBSnapshotTestCase/FBSnapshotTestCase.m Outdated
return nil;
}

- (void) addAttachmentsWithErrors:(NSArray<NSError *> *)errors identifier:(NSString *)identifier {

Copy link
Copy Markdown
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

Comment thread FBSnapshotTestCase/FBSnapshotTestCase.m Outdated
if (self.recordMode) {
UIImage* image = [_snapshotController referenceImageForSelector:self.invocation.selector identifier:identifier error:nil];
if (image) {
XCTAttachment *attachement = [XCTAttachment attachmentWithImage:image];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/attachement/attachment

Comment thread FBSnapshotTestCase/FBSnapshotTestCase.m Outdated

- (void) addAttachmentsWithErrors:(NSArray<NSError *> *)errors identifier:(NSString *)identifier {
#if defined(__IPHONE_11_0) || defined(__TVOS_11_0)
if (self.recordMode) {

Copy link
Copy Markdown
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

Comment thread FBSnapshotTestCase/FBSnapshotTestCase.m Outdated
} else if (errors.firstObject != nil) {
NSError *error = errors.firstObject;
if (error.userInfo[FBReferenceImageKey] != nil) {
XCTAttachment *attachement = [XCTAttachment attachmentWithImage:error.userInfo[FBReferenceImageKey]];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/attachement/attachment

Comment thread FBSnapshotTestCase/FBSnapshotTestCase.m Outdated
[self addAttachment:attachement];
}
if (error.userInfo[FBCapturedImageKey] != nil) {
XCTAttachment *attachement = [XCTAttachment attachmentWithImage:error.userInfo[FBCapturedImageKey]];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/attachement/attachment

Comment thread FBSnapshotTestCase/FBSnapshotTestCase.m Outdated
[self addAttachment:attachement];
}
if (error.userInfo[FBDiffedImageKey] != nil) {
XCTAttachment *attachement = [XCTAttachment attachmentWithImage:error.userInfo[FBDiffedImageKey]];

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

@alanzeino alanzeino Mar 9, 2018

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

delebedev commented Mar 10, 2018

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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