2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-03-14 01:32:38 +00:00
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
2017-04-07 18:11:03 +00:00
|
|
|
#import <React/RCTBridge.h>
|
|
|
|
|
2015-11-02 18:58:55 +00:00
|
|
|
#ifndef FB_REFERENCE_IMAGE_DIR
|
|
|
|
#define FB_REFERENCE_IMAGE_DIR ""
|
|
|
|
#endif
|
|
|
|
|
2017-07-24 13:46:01 +00:00
|
|
|
#define RCT_RUN_RUNLOOP_WHILE(CONDITION) \
|
|
|
|
{ \
|
2017-08-25 16:47:51 +00:00
|
|
|
NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:30]; \
|
2017-07-24 13:46:01 +00:00
|
|
|
NSRunLoop *runloop = [NSRunLoop mainRunLoop]; \
|
|
|
|
while ((CONDITION)) { \
|
|
|
|
[runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.01]]; \
|
|
|
|
if ([timeout timeIntervalSinceNow] <= 0) { \
|
|
|
|
XCTFail(@"Runloop timed out before condition was met"); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
2017-04-21 15:16:17 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 17:20:13 +00:00
|
|
|
/**
|
2015-11-02 18:58:55 +00:00
|
|
|
* Use the RCTInitRunnerForApp macro for typical usage. See FBSnapshotTestCase.h for more information
|
|
|
|
* on how to configure the snapshotting system.
|
2015-03-24 17:20:13 +00:00
|
|
|
*/
|
2017-11-12 21:30:13 +00:00
|
|
|
#define RCTInitRunnerForApp(app__, moduleProvider__, scriptURL__) \
|
2015-07-07 23:19:40 +00:00
|
|
|
[[RCTTestRunner alloc] initWithApp:(app__) \
|
|
|
|
referenceDirectory:@FB_REFERENCE_IMAGE_DIR \
|
2017-11-12 21:30:13 +00:00
|
|
|
moduleProvider:(moduleProvider__) \
|
|
|
|
scriptURL: scriptURL__]
|
2015-03-24 17:20:13 +00:00
|
|
|
|
2015-11-03 22:45:46 +00:00
|
|
|
@protocol RCTBridgeModule;
|
2015-11-18 16:25:30 +00:00
|
|
|
@class RCTBridge;
|
2015-11-03 22:45:46 +00:00
|
|
|
|
2015-11-13 16:34:26 +00:00
|
|
|
@class RCTRootView;
|
|
|
|
|
2015-03-14 01:32:38 +00:00
|
|
|
@interface RCTTestRunner : NSObject
|
|
|
|
|
2015-11-18 16:25:30 +00:00
|
|
|
/**
|
|
|
|
* Controls the mode snapshots are run in. If set to true, new snapshots are written to disk,
|
|
|
|
* otherwise, the UI will be compared to the existing snapshot.
|
|
|
|
*/
|
2015-03-24 17:20:13 +00:00
|
|
|
@property (nonatomic, assign) BOOL recordMode;
|
2015-11-18 16:25:30 +00:00
|
|
|
|
2017-09-22 01:25:37 +00:00
|
|
|
@property (nonatomic, assign, readwrite) BOOL useBundler;
|
|
|
|
|
|
|
|
@property (nonatomic, assign, readwrite) BOOL useJSDebugger;
|
|
|
|
|
2016-08-17 17:37:01 +00:00
|
|
|
@property (nonatomic, copy) NSString *testSuffix;
|
|
|
|
|
2015-11-18 16:25:30 +00:00
|
|
|
@property (nonatomic, readonly) NSURL *scriptURL;
|
2015-03-14 01:32:38 +00:00
|
|
|
|
2015-03-24 17:20:13 +00:00
|
|
|
/**
|
2015-04-15 00:51:28 +00:00
|
|
|
* Initialize a runner. It's recommended that you use the RCTInitRunnerForApp
|
|
|
|
* macro instead of calling this directly.
|
2015-03-24 17:20:13 +00:00
|
|
|
*
|
|
|
|
* @param app The path to the app bundle without suffixes, e.g. IntegrationTests/IntegrationTestsApp
|
2015-11-02 18:58:55 +00:00
|
|
|
* @param referenceDirectory The path for snapshot references images.
|
2015-07-07 23:19:40 +00:00
|
|
|
* @param block A block that returns an array of extra modules to be used by the test runner.
|
2015-03-24 17:20:13 +00:00
|
|
|
*/
|
2015-07-07 23:19:40 +00:00
|
|
|
- (instancetype)initWithApp:(NSString *)app
|
|
|
|
referenceDirectory:(NSString *)referenceDirectory
|
2017-11-12 21:30:13 +00:00
|
|
|
moduleProvider:(RCTBridgeModuleListProvider)block
|
|
|
|
scriptURL:(NSURL *)scriptURL NS_DESIGNATED_INITIALIZER;
|
2015-03-24 17:20:13 +00:00
|
|
|
|
|
|
|
/**
|
2015-04-15 00:51:28 +00:00
|
|
|
* Simplest runTest function simply mounts the specified JS module with no
|
|
|
|
* initialProps and waits for it to call
|
2015-03-24 17:20:13 +00:00
|
|
|
*
|
|
|
|
* RCTTestModule.markTestCompleted()
|
|
|
|
*
|
2015-04-15 00:51:28 +00:00
|
|
|
* JS errors/exceptions and timeouts will fail the test. Snapshot tests call
|
|
|
|
* RCTTestModule.verifySnapshot whenever they want to verify what has been
|
|
|
|
* rendered (typically via requestAnimationFrame to make sure the latest state
|
|
|
|
* has been rendered in native.
|
2015-03-24 17:20:13 +00:00
|
|
|
*
|
|
|
|
* @param test Selector of the test, usually just `_cmd`.
|
|
|
|
* @param moduleName Name of the JS component as registered by `AppRegistry.registerComponent` in JS.
|
|
|
|
*/
|
|
|
|
- (void)runTest:(SEL)test module:(NSString *)moduleName;
|
|
|
|
|
|
|
|
/**
|
2015-04-15 00:51:28 +00:00
|
|
|
* Same as runTest:, but allows for passing initialProps for providing mock data
|
2015-11-13 16:34:26 +00:00
|
|
|
* or requesting different behaviors, configurationBlock provides arbitrary logic for the hosting
|
|
|
|
* root view manipulation.
|
|
|
|
*
|
|
|
|
* @param test Selector of the test, usually just `_cmd`.
|
|
|
|
* @param moduleName Name of the JS component as registered by `AppRegistry.registerComponent` in JS.
|
|
|
|
* @param initialProps props that are passed into the component when rendered.
|
|
|
|
* @param configurationBlock A block that takes the hosting root view and performs arbitrary manipulation after its creation.
|
|
|
|
*/
|
2015-11-14 18:25:00 +00:00
|
|
|
- (void)runTest:(SEL)test module:(NSString *)moduleName
|
|
|
|
initialProps:(NSDictionary<NSString *, id> *)initialProps
|
|
|
|
configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock;
|
2015-11-13 16:34:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as runTest:, but allows for passing initialProps for providing mock data
|
|
|
|
* or requesting different behaviors, configurationBlock provides arbitrary logic for the hosting
|
|
|
|
* root view manipulation, and expectErrorRegex verifies that the error you expected was thrown.
|
2015-03-24 17:20:13 +00:00
|
|
|
*
|
|
|
|
* @param test Selector of the test, usually just `_cmd`.
|
|
|
|
* @param moduleName Name of the JS component as registered by `AppRegistry.registerComponent` in JS.
|
|
|
|
* @param initialProps props that are passed into the component when rendered.
|
2015-11-13 16:34:26 +00:00
|
|
|
* @param configurationBlock A block that takes the hosting root view and performs arbitrary manipulation after its creation.
|
2015-03-24 17:20:13 +00:00
|
|
|
* @param expectErrorRegex A regex that must match the error thrown. If no error is thrown, the test fails.
|
|
|
|
*/
|
2015-11-14 18:25:00 +00:00
|
|
|
- (void)runTest:(SEL)test module:(NSString *)moduleName
|
|
|
|
initialProps:(NSDictionary<NSString *, id> *)initialProps
|
|
|
|
configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock
|
|
|
|
expectErrorRegex:(NSString *)expectErrorRegex;
|
2015-03-24 17:20:13 +00:00
|
|
|
|
|
|
|
/**
|
2015-04-15 00:51:28 +00:00
|
|
|
* Same as runTest:, but allows for passing initialProps for providing mock data
|
2015-11-13 16:34:26 +00:00
|
|
|
* or requesting different behaviors, configurationBlock provides arbitrary logic for the hosting
|
|
|
|
* root view manipulation, and expectErrorBlock provides arbitrary
|
2015-04-15 00:51:28 +00:00
|
|
|
* logic for processing errors (nil will cause any error to fail the test).
|
2015-03-24 17:20:13 +00:00
|
|
|
*
|
|
|
|
* @param test Selector of the test, usually just `_cmd`.
|
|
|
|
* @param moduleName Name of the JS component as registered by `AppRegistry.registerComponent` in JS.
|
|
|
|
* @param initialProps props that are passed into the component when rendered.
|
2015-11-13 16:34:26 +00:00
|
|
|
* @param configurationBlock A block that takes the hosting root view and performs arbitrary manipulation after its creation.
|
2015-03-24 17:20:13 +00:00
|
|
|
* @param expectErrorBlock A block that takes the error message and returns NO to fail the test.
|
|
|
|
*/
|
2015-11-14 18:25:00 +00:00
|
|
|
- (void)runTest:(SEL)test module:(NSString *)moduleName
|
|
|
|
initialProps:(NSDictionary<NSString *, id> *)initialProps
|
|
|
|
configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock
|
|
|
|
expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock;
|
2015-03-14 01:32:38 +00:00
|
|
|
|
|
|
|
@end
|