Remove code for testing without JS bundle

Reviewed By: mmmulani

Differential Revision: D3542347

fbshipit-source-id: d0dcfb65645faf515e6e48e6ff733646e1bcf907
This commit is contained in:
Pieter De Baets 2016-07-11 13:16:09 -07:00 committed by Facebook Github Bot 8
parent 2ae23d9f36
commit 81f59dfdc2
8 changed files with 49 additions and 60 deletions

View File

@ -0,0 +1,9 @@
/**
* Copyright (c) 2013-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.
*/

View File

@ -64,6 +64,7 @@
27F441EC1BEBE5030039B79C /* FlexibleSizeExampleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 27F441E81BEBE5030039B79C /* FlexibleSizeExampleView.m */; };
3578590A1B28D2CF00341EDB /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 357859011B28D2C500341EDB /* libRCTLinking.a */; };
3DB99D0C1BA0340600302749 /* UIExplorerIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DB99D0B1BA0340600302749 /* UIExplorerIntegrationTests.m */; };
3DEFCE371D33A67200256E76 /* TestBundle.js in Resources */ = {isa = PBXBuildFile; fileRef = 3DEFCE351D33A61500256E76 /* TestBundle.js */; };
68FF44381CF6111500720EFD /* RCTBundleURLProviderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 68FF44371CF6111500720EFD /* RCTBundleURLProviderTests.m */; };
834C36EC1AF8DED70019C93C /* libRCTSettings.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 834C36D21AF8DA610019C93C /* libRCTSettings.a */; };
83636F8F1B53F22C009F943E /* RCTUIManagerScenarioTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 83636F8E1B53F22C009F943E /* RCTUIManagerScenarioTests.m */; };
@ -220,12 +221,6 @@
13DF61B51B67A45000EDB188 /* RCTMethodArgumentTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTMethodArgumentTests.m; sourceTree = "<group>"; };
13E5019C1D07A502005F35D8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = ../../Libraries/NativeAnimation/RCTAnimation.xcodeproj; sourceTree = "<group>"; };
143BC57E1B21E18100462512 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
143BC5811B21E18100462512 /* testLayoutExampleSnapshot_1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "testLayoutExampleSnapshot_1@2x.png"; sourceTree = "<group>"; };
143BC5821B21E18100462512 /* testSliderExampleSnapshot_1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "testSliderExampleSnapshot_1@2x.png"; sourceTree = "<group>"; };
143BC5831B21E18100462512 /* testSwitchExampleSnapshot_1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "testSwitchExampleSnapshot_1@2x.png"; sourceTree = "<group>"; };
143BC5841B21E18100462512 /* testTabBarExampleSnapshot_1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "testTabBarExampleSnapshot_1@2x.png"; sourceTree = "<group>"; };
143BC5851B21E18100462512 /* testTextExampleSnapshot_1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "testTextExampleSnapshot_1@2x.png"; sourceTree = "<group>"; };
143BC5861B21E18100462512 /* testViewExampleSnapshot_1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "testViewExampleSnapshot_1@2x.png"; sourceTree = "<group>"; };
143BC5951B21E3E100462512 /* UIExplorerIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UIExplorerIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
143BC5981B21E3E100462512 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
143BC5A01B21E45C00462512 /* UIExplorerSnapshotTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIExplorerSnapshotTests.m; sourceTree = "<group>"; };
@ -257,6 +252,7 @@
27F441EA1BEBE5030039B79C /* FlexibleSizeExampleView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FlexibleSizeExampleView.h; path = UIExplorer/NativeExampleViews/FlexibleSizeExampleView.h; sourceTree = "<group>"; };
357858F81B28D2C400341EDB /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = ../../Libraries/LinkingIOS/RCTLinking.xcodeproj; sourceTree = "<group>"; };
3DB99D0B1BA0340600302749 /* UIExplorerIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIExplorerIntegrationTests.m; sourceTree = "<group>"; };
3DEFCE351D33A61500256E76 /* TestBundle.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = TestBundle.js; sourceTree = "<group>"; };
58005BE41ABA80530062E044 /* RCTTest.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTTest.xcodeproj; path = ../../Libraries/RCTTest/RCTTest.xcodeproj; sourceTree = "<group>"; };
68FF44371CF6111500720EFD /* RCTBundleURLProviderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTBundleURLProviderTests.m; sourceTree = "<group>"; };
83636F8E1B53F22C009F943E /* RCTUIManagerScenarioTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUIManagerScenarioTests.m; sourceTree = "<group>"; };
@ -344,6 +340,7 @@
1323F18D1C04ABAC0091BED0 /* Supporting Files */ = {
isa = PBXGroup;
children = (
3DEFCE351D33A61500256E76 /* TestBundle.js */,
13B07FB61A68108700A75B9A /* Info.plist */,
1323F1851C04AB9F0091BED0 /* bunny.png */,
1323F1861C04AB9F0091BED0 /* flux@3x.png */,
@ -459,32 +456,10 @@
143BC57E1B21E18100462512 /* Info.plist */,
14D6D7101B220EB3001FB087 /* libOCMock.a */,
14D6D7011B220AE3001FB087 /* OCMock */,
143BC57F1B21E18100462512 /* ReferenceImages */,
);
path = UIExplorerUnitTests;
sourceTree = "<group>";
};
143BC57F1B21E18100462512 /* ReferenceImages */ = {
isa = PBXGroup;
children = (
143BC5801B21E18100462512 /* Examples-UIExplorer-UIExplorerApp */,
);
path = ReferenceImages;
sourceTree = "<group>";
};
143BC5801B21E18100462512 /* Examples-UIExplorer-UIExplorerApp */ = {
isa = PBXGroup;
children = (
143BC5811B21E18100462512 /* testLayoutExampleSnapshot_1@2x.png */,
143BC5821B21E18100462512 /* testSliderExampleSnapshot_1@2x.png */,
143BC5831B21E18100462512 /* testSwitchExampleSnapshot_1@2x.png */,
143BC5841B21E18100462512 /* testTabBarExampleSnapshot_1@2x.png */,
143BC5851B21E18100462512 /* testTextExampleSnapshot_1@2x.png */,
143BC5861B21E18100462512 /* testViewExampleSnapshot_1@2x.png */,
);
path = "Examples-UIExplorer-UIExplorerApp";
sourceTree = "<group>";
};
143BC5961B21E3E100462512 /* UIExplorerIntegrationTests */ = {
isa = PBXGroup;
children = (
@ -887,6 +862,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3DEFCE371D33A67200256E76 /* TestBundle.js in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -92,6 +92,11 @@ RCT_EXPORT_MODULE()
block();
}
- (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block
{
block();
}
- (void)injectJSONText:(NSString *)script
asGlobalObjectNamed:(NSString *)objectName
callback:(RCTJavaScriptCompleteBlock)onComplete
@ -151,7 +156,8 @@ RCT_EXPORT_MODULE(TestModule)
[super setUp];
_unregisteredTestModule = [UnregisteredTestModule new];
_bridge = [[RCTBridge alloc] initWithBundleURL:nil
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
_bridge = [[RCTBridge alloc] initWithBundleURL:[bundle URLForResource:@"TestBundle" withExtension:@"js"]
moduleProvider:^{ return @[self, self->_unregisteredTestModule]; }
launchOptions:nil];

View File

@ -95,7 +95,8 @@ RCT_CUSTOM_VIEW_PROPERTY(customProp, NSString, RCTPropsTestView)
{
[super setUp];
_bridge = [[RCTBridge alloc] initWithBundleURL:nil
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
_bridge = [[RCTBridge alloc] initWithBundleURL:[bundle URLForResource:@"TestBundle" withExtension:@"js"]
moduleProvider:nil
launchOptions:nil];
}

View File

@ -33,7 +33,15 @@ RCTDefineImageDecoder(RCTImageLoaderTestsDecoder2)
@end
@implementation RCTImageLoaderTests
@implementation RCTImageLoaderTests {
NSURL *_bundleURL;
}
- (void)setUp
{
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
_bundleURL = [bundle URLForResource:@"TestBundle" withExtension:@"js"];
}
- (void)testImageLoading
{
@ -47,7 +55,7 @@ RCTDefineImageDecoder(RCTImageLoaderTestsDecoder2)
return nil;
}];
NS_VALID_UNTIL_END_OF_SCOPE RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:nil moduleProvider:^{ return @[loader]; } launchOptions:nil];
NS_VALID_UNTIL_END_OF_SCOPE RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_bundleURL moduleProvider:^{ return @[loader]; } launchOptions:nil];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://facebook.github.io/react/img/logo_og.png"]];
[bridge.imageLoader loadImageWithURLRequest:urlRequest size:CGSizeMake(100, 100) scale:1.0 clipped:YES resizeMode:RCTResizeModeContain progressBlock:^(int64_t progress, int64_t total) {
@ -78,7 +86,7 @@ RCTDefineImageDecoder(RCTImageLoaderTestsDecoder2)
return nil;
}];
NS_VALID_UNTIL_END_OF_SCOPE RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:nil moduleProvider:^{ return @[loader1, loader2]; } launchOptions:nil];
NS_VALID_UNTIL_END_OF_SCOPE RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_bundleURL moduleProvider:^{ return @[loader1, loader2]; } launchOptions:nil];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://facebook.github.io/react/img/logo_og.png"]];
[bridge.imageLoader loadImageWithURLRequest:urlRequest size:CGSizeMake(100, 100) scale:1.0 clipped:YES resizeMode:RCTResizeModeContain progressBlock:^(int64_t progress, int64_t total) {
@ -103,7 +111,7 @@ RCTDefineImageDecoder(RCTImageLoaderTestsDecoder2)
return nil;
}];
NS_VALID_UNTIL_END_OF_SCOPE RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:nil moduleProvider:^{ return @[decoder]; } launchOptions:nil];
NS_VALID_UNTIL_END_OF_SCOPE RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_bundleURL moduleProvider:^{ return @[decoder]; } launchOptions:nil];
RCTImageLoaderCancellationBlock cancelBlock = [bridge.imageLoader decodeImageData:data size:CGSizeMake(1, 1) scale:1.0 clipped:NO resizeMode:RCTResizeModeStretch completionBlock:^(NSError *decodeError, id decodedImage) {
XCTAssertEqualObjects(decodedImage, image);
@ -132,7 +140,7 @@ RCTDefineImageDecoder(RCTImageLoaderTestsDecoder2)
return nil;
}];
NS_VALID_UNTIL_END_OF_SCOPE RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:nil moduleProvider:^{ return @[decoder1, decoder2]; } launchOptions:nil];
NS_VALID_UNTIL_END_OF_SCOPE RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_bundleURL moduleProvider:^{ return @[decoder1, decoder2]; } launchOptions:nil];
RCTImageLoaderCancellationBlock cancelBlock = [bridge.imageLoader decodeImageData:data size:CGSizeMake(1, 1) scale:1.0 clipped:NO resizeMode:RCTResizeModeStretch completionBlock:^(NSError *decodeError, id decodedImage) {
XCTAssertEqualObjects(decodedImage, image);

View File

@ -99,7 +99,8 @@ RCT_EXPORT_MODULE()
- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
{
return nil;
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
return [bundle URLForResource:@"TestBundle" withExtension:@"js"];
}
- (NSArray *)extraModulesForBridge:(__unused RCTBridge *)bridge

View File

@ -147,7 +147,8 @@ RCT_EXPORT_MODULE()
- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
{
return nil;
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
return [bundle URLForResource:@"TestBundle" withExtension:@"js"];
}
- (NSArray *)extraModulesForBridge:(__unused RCTBridge *)bridge

View File

@ -171,7 +171,9 @@ RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
if ([self.delegate respondsToSelector:@selector(loadSourceForBridge:withBlock:)]) {
[self.delegate loadSourceForBridge:_parentBridge withBlock:onSourceLoad];
} else if (self.bundleURL) {
} else {
RCTAssert(self.bundleURL, @"bundleURL must be non-nil when not implementing loadSourceForBridge");
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onComplete:^(NSError *error, NSData *source, int64_t sourceLength) {
if (error && [self.delegate respondsToSelector:@selector(fallbackSourceURLForBridge:)]) {
NSURL *fallbackURL = [self.delegate fallbackSourceURLForBridge:self->_parentBridge];
@ -184,17 +186,6 @@ RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
}
onSourceLoad(error, source, sourceLength);
}];
} else {
// Allow testing without a script
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter]
postNotificationName:RCTJavaScriptDidLoadNotification
object:self->_parentBridge userInfo:@{@"bridge": self}];
});
[self flushPendingCalls];
onSourceLoad(nil, nil, 0);
}
}
@ -487,11 +478,10 @@ RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
object:self->_parentBridge userInfo:@{@"bridge": self}];
});
[self flushPendingCalls];
[self _flushPendingCalls];
}];
#if RCT_DEV
if ([RCTGetURLQueryParam(self.bundleURL, @"hot") boolValue]) {
NSString *path = [self.bundleURL.path substringFromIndex:1]; // strip initial slash
NSString *host = self.bundleURL.host;
@ -501,18 +491,15 @@ RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
#endif
}
- (void)flushPendingCalls
- (void)_flushPendingCalls
{
RCTAssertJSThread();
[_performanceLogger markStopForTag:RCTPLBridgeStartup];
[_javaScriptExecutor executeBlockOnJavaScriptQueue:^{
for (dispatch_block_t call in self->_pendingCalls) {
_loading = NO;
for (dispatch_block_t call in _pendingCalls) {
call();
}
}];
_loading = NO;
for (dispatch_block_t call in self->_pendingCalls) {
call();
}
}
- (void)stopLoadingWithError:(NSError *)error