2016-03-01 17:44:05 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
2016-03-01 17:44:05 +00:00
|
|
|
*
|
2017-05-06 03:50:47 +00:00
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2016-03-01 17:44:05 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
|
2017-04-21 15:16:17 +00:00
|
|
|
#import <RCTTest/RCTTestRunner.h>
|
2016-11-24 17:44:51 +00:00
|
|
|
#import <React/RCTBridge.h>
|
|
|
|
#import <React/RCTBridgeModule.h>
|
|
|
|
#import <React/RCTJavaScriptExecutor.h>
|
|
|
|
#import <React/RCTUIManager.h>
|
|
|
|
#import <React/RCTViewManager.h>
|
2016-03-01 17:44:05 +00:00
|
|
|
|
|
|
|
@interface RCTTestViewManager : RCTViewManager
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTTestViewManager
|
|
|
|
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2016-05-23 16:08:51 +00:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
|
|
|
|
|
2016-10-27 13:54:28 +00:00
|
|
|
- (NSArray<NSString *> *)customBubblingEventTypes
|
2016-03-01 17:44:05 +00:00
|
|
|
{
|
|
|
|
return @[@"foo"];
|
|
|
|
}
|
|
|
|
|
2016-05-23 16:08:51 +00:00
|
|
|
#pragma clang diagnostic pop
|
|
|
|
|
2016-03-01 17:44:05 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@interface RCTNotificationObserverModule : NSObject <RCTBridgeModule>
|
|
|
|
|
|
|
|
@property (nonatomic, assign) BOOL didDetectViewManagerInit;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTNotificationObserverModule
|
|
|
|
|
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
|
|
|
- (void)setBridge:(RCTBridge *)bridge
|
|
|
|
{
|
|
|
|
_bridge = bridge;
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didInitViewManager:) name:RCTDidInitializeModuleNotification object:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didInitViewManager:(NSNotification *)note
|
|
|
|
{
|
|
|
|
id<RCTBridgeModule> module = note.userInfo[@"module"];
|
|
|
|
if ([module isKindOfClass:[RCTTestViewManager class]]) {
|
|
|
|
_didDetectViewManagerInit = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@interface RCTModuleInitNotificationRaceTests : XCTestCase <RCTBridgeDelegate>
|
|
|
|
{
|
|
|
|
RCTBridge *_bridge;
|
|
|
|
RCTNotificationObserverModule *_notificationObserver;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTModuleInitNotificationRaceTests
|
|
|
|
|
|
|
|
- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
|
|
|
|
{
|
2016-07-11 20:16:09 +00:00
|
|
|
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
|
2017-05-06 03:50:47 +00:00
|
|
|
return [bundle URLForResource:@"RNTesterUnitTestsBundle" withExtension:@"js"];
|
2016-03-01 17:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)extraModulesForBridge:(__unused RCTBridge *)bridge
|
|
|
|
{
|
2016-03-03 10:20:20 +00:00
|
|
|
return @[[RCTTestViewManager new], _notificationObserver];
|
2016-03-01 17:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setUp
|
|
|
|
{
|
|
|
|
[super setUp];
|
|
|
|
|
|
|
|
_notificationObserver = [RCTNotificationObserverModule new];
|
|
|
|
_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tearDown
|
|
|
|
{
|
|
|
|
[super tearDown];
|
|
|
|
|
|
|
|
_notificationObserver = nil;
|
|
|
|
[_bridge invalidate];
|
|
|
|
_bridge = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)testViewManagerNotInitializedBeforeSetBridgeModule
|
|
|
|
{
|
2017-04-21 15:16:17 +00:00
|
|
|
RCT_RUN_RUNLOOP_WHILE(!_notificationObserver.didDetectViewManagerInit);
|
2016-03-01 17:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|