mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-01 09:23:16 +08:00
Added RCTBundleURLProvider
Reviewed By: javache Differential Revision: D3352568 fbshipit-source-id: fbba6771a1c581e2676bd0f81d3da62dbf21916b
This commit is contained in:
committed by
Facebook Github Bot 6
parent
c2c370c886
commit
3ccd99fb53
@@ -63,6 +63,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 */; };
|
||||
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 */; };
|
||||
8385CEF51B873B5C00C6273E /* RCTImageLoaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8385CEF41B873B5C00C6273E /* RCTImageLoaderTests.m */; };
|
||||
@@ -248,6 +249,7 @@
|
||||
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>"; };
|
||||
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>"; };
|
||||
8385CEF41B873B5C00C6273E /* RCTImageLoaderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTImageLoaderTests.m; sourceTree = "<group>"; };
|
||||
8385CF031B87479200C6273E /* RCTImageLoaderHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTImageLoaderHelpers.m; sourceTree = "<group>"; };
|
||||
@@ -415,6 +417,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
13B6C1A21C34225900D3FAF5 /* RCTURLUtilsTests.m */,
|
||||
68FF44371CF6111500720EFD /* RCTBundleURLProviderTests.m */,
|
||||
1497CFA41B21F5E400C1F8F2 /* RCTAllocationTests.m */,
|
||||
1497CFA51B21F5E400C1F8F2 /* RCTBridgeTests.m */,
|
||||
1497CFA61B21F5E400C1F8F2 /* RCTJSCExecutorTests.m */,
|
||||
@@ -903,6 +906,7 @@
|
||||
138D6A181B53CD440074A87E /* RCTShadowViewTests.m in Sources */,
|
||||
13B6C1A31C34225900D3FAF5 /* RCTURLUtilsTests.m in Sources */,
|
||||
8385CF041B87479200C6273E /* RCTImageLoaderHelpers.m in Sources */,
|
||||
68FF44381CF6111500720EFD /* RCTBundleURLProviderTests.m in Sources */,
|
||||
8385CEF51B873B5C00C6273E /* RCTImageLoaderTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* The examples provided by Facebook are for non-commercial testing and
|
||||
* evaluation purposes only.
|
||||
*
|
||||
* Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
||||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "RCTBundleURLProvider.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
|
||||
static NSString *const testFile = @"test.jsbundle";
|
||||
static NSString *const mainBundle = @"main.jsbundle";
|
||||
|
||||
static NSURL *mainBundleURL()
|
||||
{
|
||||
return [[[NSBundle mainBundle] bundleURL] URLByAppendingPathComponent:mainBundle];
|
||||
}
|
||||
|
||||
static NSURL *localhostBundleURL()
|
||||
{
|
||||
return [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true&minify=false", testFile]];
|
||||
}
|
||||
|
||||
static NSURL *ipBundleURL()
|
||||
{
|
||||
return [NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.1:8081/%@.bundle?platform=ios&dev=true&minify=false", testFile]];
|
||||
}
|
||||
|
||||
@implementation NSBundle (RCTBundleURLProviderTests)
|
||||
|
||||
- (NSURL *)RCT_URLForResource:(NSString *)name withExtension:(NSString *)ext
|
||||
{
|
||||
// Ensure that test files is always reported as existing
|
||||
if ([[name stringByAppendingFormat:@".%@", ext] isEqualToString:mainBundle]) {
|
||||
return [[self bundleURL] URLByAppendingPathComponent:mainBundle];
|
||||
}
|
||||
return [self RCT_URLForResource:name withExtension:ext];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface RCTBundleURLProviderTests : XCTestCase
|
||||
@end
|
||||
|
||||
@implementation RCTBundleURLProviderTests
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
[super setUp];
|
||||
|
||||
RCTSwapInstanceMethods([NSBundle class],
|
||||
@selector(URLForResource:withExtension:),
|
||||
@selector(RCT_URLForResource:withExtension:));
|
||||
[[RCTBundleURLProvider sharedSettings] setDefaults];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
RCTSwapInstanceMethods([NSBundle class],
|
||||
@selector(URLForResource:withExtension:),
|
||||
@selector(RCT_URLForResource:withExtension:));
|
||||
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testBundleURL
|
||||
{
|
||||
RCTBundleURLProvider *settings = [RCTBundleURLProvider sharedSettings];
|
||||
settings.jsLocation = nil;
|
||||
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile fallbackResource:nil];
|
||||
if (!getenv("CI_USE_PACKAGER")) {
|
||||
XCTAssertEqualObjects(URL, mainBundleURL());
|
||||
} else {
|
||||
XCTAssertEqualObjects(URL, localhostBundleURL());
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testLocalhostURL
|
||||
{
|
||||
RCTBundleURLProvider *settings = [RCTBundleURLProvider sharedSettings];
|
||||
settings.jsLocation = @"localhost";
|
||||
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile fallbackResource:nil];
|
||||
XCTAssertEqualObjects(URL, localhostBundleURL());
|
||||
}
|
||||
|
||||
- (void)testIPURL
|
||||
{
|
||||
RCTBundleURLProvider *settings = [RCTBundleURLProvider sharedSettings];
|
||||
settings.jsLocation = @"192.168.1.1";
|
||||
NSURL *URL = [settings jsBundleURLForBundleRoot:testFile fallbackResource:nil];
|
||||
XCTAssertEqualObjects(URL, ipBundleURL());
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user