Implemented thread control for exported methods

This commit is contained in:
Nick Lockwood
2015-04-18 10:43:20 -07:00
parent 2b9aaac2ff
commit ead0f2e020
23 changed files with 384 additions and 403 deletions

View File

@@ -12,21 +12,25 @@
#import "FBSnapshotTestController.h"
#import "RCTAssert.h"
#import "RCTLog.h"
#import "RCTUIManager.h"
@implementation RCTTestModule
{
__weak FBSnapshotTestController *_snapshotController;
__weak UIView *_view;
NSMutableDictionary *_snapshotCounter;
}
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE()
- (instancetype)initWithSnapshotController:(FBSnapshotTestController *)controller view:(UIView *)view
- (dispatch_queue_t)methodQueue
{
return _bridge.uiManager.methodQueue;
}
- (instancetype)init
{
if ((self = [super init])) {
_snapshotController = controller;
_view = view;
_snapshotCounter = [NSMutableDictionary new];
}
return self;
@@ -34,30 +38,29 @@ RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(verifySnapshot:(RCTResponseSenderBlock)callback)
{
if (!_snapshotController) {
RCTLogWarn(@"No snapshot controller configured.");
callback(@[]);
return;
}
RCTAssert(_controller != nil, @"No snapshot controller configured.");
[_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *testName = NSStringFromSelector(_testSelector);
_snapshotCounter[testName] = @([_snapshotCounter[testName] integerValue] + 1);
_snapshotCounter[testName] = [@([_snapshotCounter[testName] integerValue] + 1) stringValue];
NSError *error = nil;
BOOL success = [_snapshotController compareSnapshotOfView:_view
selector:_testSelector
identifier:[_snapshotCounter[testName] stringValue]
error:&error];
BOOL success = [_controller compareSnapshotOfView:_view
selector:_testSelector
identifier:_snapshotCounter[testName]
error:&error];
RCTAssert(success, @"Snapshot comparison failed: %@", error);
callback(@[]);
});
}];
}
RCT_EXPORT_METHOD(markTestCompleted)
{
dispatch_async(dispatch_get_main_queue(), ^{
[_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
_done = YES;
});
}];
}
@end