From 6957b79105b9663f7d314fc824d4ba90ee7edb85 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Wed, 24 Nov 2021 14:00:55 -0800 Subject: [PATCH] fix RCTBundleURLProviderTests Summary: a year ago or so, there was a change that updated the way RCTBundleURLProvider creates the IP url depending on if HERMES_BYTECODE_VERSION existed, and this test was never updated, so fixing it accordingly Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D32638669 fbshipit-source-id: 3824b90570f60ad5299939b09b99fb56d2b3ddaa --- packages/rn-tester/BUCK | 5 ++++- .../RCTBundleURLProviderTests.m | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/rn-tester/BUCK b/packages/rn-tester/BUCK index 01653b0589..3e577b4b78 100644 --- a/packages/rn-tester/BUCK +++ b/packages/rn-tester/BUCK @@ -1,3 +1,4 @@ +load("@fbsource//xplat/hermes/defs:hermes.bzl", "HERMES_BYTECODE_VERSION") load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native") load("//tools/build_defs:fb_xplat_platform_specific_rule.bzl", "fb_xplat_platform_specific_rule") load("//tools/build_defs:fb_xplat_resource.bzl", "fb_xplat_resource") @@ -121,7 +122,9 @@ fb_apple_test( "QuartzCore", "UIKit", ], - preprocessor_flags = get_objc_arc_preprocessor_flags() + get_preprocessor_flags_for_build_mode(), + preprocessor_flags = get_objc_arc_preprocessor_flags() + [ + "-DHERMES_BYTECODE_VERSION={}".format(HERMES_BYTECODE_VERSION), + ] + get_preprocessor_flags_for_build_mode(), visibility = [ "//fbobjc/Libraries/FBReactKit:workspace", ], diff --git a/packages/rn-tester/RNTesterUnitTests/RCTBundleURLProviderTests.m b/packages/rn-tester/RNTesterUnitTests/RCTBundleURLProviderTests.m index 309ccaa6a1..9a72c65def 100644 --- a/packages/rn-tester/RNTesterUnitTests/RCTBundleURLProviderTests.m +++ b/packages/rn-tester/RNTesterUnitTests/RCTBundleURLProviderTests.m @@ -22,22 +22,42 @@ static NSURL *mainBundleURL() static NSURL *localhostBundleURL() { +#ifdef HERMES_BYTECODE_VERSION + return [NSURL + URLWithString: + [NSString + stringWithFormat: + @"http://localhost:8081/%@.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&runtimeBytecodeVersion=%u&app=com.apple.dt.xctest.tool", + testFile, + HERMES_BYTECODE_VERSION]]; +#else return [NSURL URLWithString: [NSString stringWithFormat: @"http://localhost:8081/%@.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.apple.dt.xctest.tool", testFile]]; +#endif } static NSURL *ipBundleURL() { +#ifdef HERMES_BYTECODE_VERSION + return [NSURL + URLWithString: + [NSString + stringWithFormat: + @"http://192.168.1.1:8081/%@.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&runtimeBytecodeVersion=%u&app=com.apple.dt.xctest.tool", + testFile, + HERMES_BYTECODE_VERSION]]; +#else return [NSURL URLWithString: [NSString stringWithFormat: @"http://192.168.1.1:8081/%@.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.apple.dt.xctest.tool", testFile]]; +#endif } @implementation NSBundle (RCTBundleURLProviderTests) @@ -88,6 +108,8 @@ static NSURL *ipBundleURL() - (void)testLocalhostURL { + id classMock = OCMClassMock([RCTBundleURLProvider class]); + [[[classMock stub] andReturnValue:@YES] isPackagerRunning:[OCMArg any] scheme:[OCMArg any]]; RCTBundleURLProvider *settings = [RCTBundleURLProvider sharedSettings]; settings.jsLocation = @"localhost"; NSURL *URL = [settings jsBundleURLForBundleRoot:testFile fallbackResource:nil];