Skip to content

Commit

Permalink
Fix snapshottests under iOS10
Browse files Browse the repository at this point in the history
Reviewed By: dinhviethoa

Differential Revision: D3722988

fbshipit-source-id: 4345b757e28700ac61e1de38b61430e78948e58a
  • Loading branch information
javache authored and Facebook Github Bot 7 committed Aug 17, 2016
1 parent 0da5fd2 commit a0b3565
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 10 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ @implementation UIExplorerSnapshotTests
- (void)setUp
{
_runner = RCTInitRunnerForApp(@"Examples/UIExplorer/js/UIExplorerApp.ios", nil);
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10) {
_runner.testSuffix = @"-iOS10";
}
_runner.recordMode = NO;
}

Expand All @@ -46,8 +49,8 @@ - (void)test##name \
RCT_TEST(LayoutExample)
RCT_TEST(TextExample)
RCT_TEST(SwitchExample)
//RCT_TEST(SliderExample) // Disabled: #8985988
//RCT_TEST(TabBarExample) // Disabled: #8985988
RCT_TEST(SliderExample)
RCT_TEST(TabBarExample)

- (void)testZZZNotInRecordMode
{
Expand Down
5 changes: 5 additions & 0 deletions Examples/UIExplorer/UIExplorerUnitTests/TestBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

var __fbBatchedBridge = {
flushedQueue: function() {
return null;
}
};
2 changes: 2 additions & 0 deletions Libraries/RCTTest/RCTTestModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ typedef NS_ENUM(NSInteger, RCTTestStatus) {
*/
@property (nonatomic, readonly) RCTTestStatus status;

@property (nonatomic, copy) NSString *testSuffix;

@end
20 changes: 12 additions & 8 deletions Libraries/RCTTest/RCTTestModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
#import "RCTLog.h"
#import "RCTUIManager.h"

@implementation RCTTestModule
{
NSMutableDictionary<NSString *, NSString *> *_snapshotCounter;
@implementation RCTTestModule {
NSMutableDictionary<NSString *, NSNumber *> *_snapshotCounter;
}

@synthesize bridge = _bridge;
Expand All @@ -34,18 +33,23 @@ - (dispatch_queue_t)methodQueue
RCTAssert(_controller != nil, @"No snapshot controller configured.");

[_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {

NSString *testName = NSStringFromSelector(self->_testSelector);
if (!self->_snapshotCounter) {
self->_snapshotCounter = [NSMutableDictionary new];
}
self->_snapshotCounter[testName] = (@([self->_snapshotCounter[testName] integerValue] + 1)).stringValue;

NSNumber *counter = @([self->_snapshotCounter[testName] integerValue] + 1);
self->_snapshotCounter[testName] = counter;

NSError *error = nil;
NSString *identifier = [counter stringValue];
if (self->_testSuffix) {
identifier = [identifier stringByAppendingString:self->_testSuffix];
}
BOOL success = [self->_controller compareSnapshotOfView:self->_view
selector:self->_testSelector
identifier:self->_snapshotCounter[testName]
error:&error];
selector:self->_testSelector
identifier:identifier
error:&error];
callback(@[@(success)]);
}];
}
Expand Down
2 changes: 2 additions & 0 deletions Libraries/RCTTest/RCTTestRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
*/
@property (nonatomic, assign) BOOL recordMode;

@property (nonatomic, copy) NSString *testSuffix;

@property (nonatomic, readonly) NSURL *scriptURL;

/**
Expand Down
1 change: 1 addition & 0 deletions Libraries/RCTTest/RCTTestRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
RCTAssert(_testController != nil, @"_testController should not be nil");
testModule.controller = _testController;
testModule.testSelector = test;
testModule.testSuffix = _testSuffix;
testModule.view = rootView;

UIViewController *vc = [UIApplication sharedApplication].delegate.window.rootViewController;
Expand Down

0 comments on commit a0b3565

Please sign in to comment.