Skip to content

Commit

Permalink
Make RCTTestModule TurboModule-compatible
Browse files Browse the repository at this point in the history
Reviewed By: fkgozali

Differential Revision: D18545790

fbshipit-source-id: 035df69671ec44d13b79b014bfe90f5af9f43e58
  • Loading branch information
RSNara authored and facebook-github-bot committed Feb 1, 2020
1 parent 6adba40 commit ff3b839
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 19 deletions.
4 changes: 2 additions & 2 deletions RNTester/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ end

target 'RNTesterUnitTests' do
pods()
pod 'React-RCTTest', :path => "RCTTest"
pod 'React-RCTTest', :path => "./RCTTest"
end

target 'RNTesterIntegrationTests' do
pods()
pod 'React-RCTTest', :path => "RCTTest"
pod 'React-RCTTest', :path => "./RCTTest"
end

post_install do |installer|
Expand Down
11 changes: 7 additions & 4 deletions RNTester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ PODS:
- React-Core/RCTSettingsHeaders (= 1000.0.0)
- ReactCommon/turbomodule/core (= 1000.0.0)
- React-RCTTest (1000.0.0):
- Folly (= 2020.01.13.00)
- React-Core (= 1000.0.0)
- React-CoreModules (= 1000.0.0)
- React-jsi (= 1000.0.0)
- ReactCommon/turbomodule/core (= 1000.0.0)
- React-RCTText (1000.0.0):
- React-Core/RCTTextHeaders (= 1000.0.0)
- React-RCTVibration (1000.0.0):
Expand Down Expand Up @@ -304,7 +307,7 @@ DEPENDENCIES:
- React-RCTNetwork (from `../Libraries/Network`)
- React-RCTPushNotification (from `../Libraries/PushNotificationIOS`)
- React-RCTSettings (from `../Libraries/Settings`)
- React-RCTTest (from `RCTTest`)
- React-RCTTest (from `./RCTTest`)
- React-RCTText (from `../Libraries/Text`)
- React-RCTVibration (from `../Libraries/Vibration`)
- ReactCommon/callinvoker (from `../ReactCommon`)
Expand Down Expand Up @@ -364,7 +367,7 @@ EXTERNAL SOURCES:
React-RCTSettings:
:path: "../Libraries/Settings"
React-RCTTest:
:path: RCTTest
:path: "./RCTTest"
React-RCTText:
:path: "../Libraries/Text"
React-RCTVibration:
Expand Down Expand Up @@ -399,12 +402,12 @@ SPEC CHECKSUMS:
React-RCTNetwork: d16dd52792dc3d66c3e23b464afe0f759d3a5670
React-RCTPushNotification: 9290035bbd9ecef15f03d760cc422a219b55be07
React-RCTSettings: f7daf792f772c8582b31c7aeeb1f146df61a52a7
React-RCTTest: 80b44b7e8f5a30d9663c921adfb22a0b185e69f4
React-RCTTest: e10acfa457347879d3723bc85f1d2754414b9d2c
React-RCTText: b3eb3514addd9b105c0edb05ed32333428ba2a52
React-RCTVibration: e2856bb9408f7e8eccfe870e123e5644ab744219
ReactCommon: c3834cbee58b60f71c8155c04a3f44e60ec017fb
Yoga: f7fa200d8c49f97b54c9421079e781fb900b5cae

PODFILE CHECKSUM: fa397603c9a8f7cb49d7edc7fe85536d0789f34f
PODFILE CHECKSUM: 31cb1ffc6e72e1bbb948da2fb648d4f7aca92168

COCOAPODS: 1.8.4
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,69 @@
#import <React/RCTEventDispatcher.h>
#import <React/RCTLog.h>
#import <React/RCTUIManager.h>
#import <ReactCommon/RCTTurboModule.h>

#import "FBSnapshotTestController.h"

#import "RCTTestPlugins.h"

@protocol NativeTestModuleSpec <RCTBridgeModule, RCTTurboModule>

- (void)markTestCompleted;
- (void)markTestPassed:(BOOL)success;
- (void)verifySnapshot:(RCTResponseSenderBlock)callback;

@end

namespace facebook {
namespace react {
/**
* ObjC++ class for module 'TestModule'
*/

class JSI_EXPORT NativeTestModuleSpecJSI : public ObjCTurboModule {
public:
NativeTestModuleSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<CallInvoker> jsInvoker);

};
} // namespace react
} // namespace facebook

namespace facebook {
namespace react {


static facebook::jsi::Value __hostFunction_NativeTestModuleSpecJSI_markTestCompleted(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "markTestCompleted", @selector(markTestCompleted), args, count);
}

static facebook::jsi::Value __hostFunction_NativeTestModuleSpecJSI_markTestPassed(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "markTestPassed", @selector(markTestPassed:), args, count);
}

static facebook::jsi::Value __hostFunction_NativeTestModuleSpecJSI_verifySnapshot(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "verifySnapshot", @selector(verifySnapshot:), args, count);
}


NativeTestModuleSpecJSI::NativeTestModuleSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<CallInvoker> jsInvoker)
: ObjCTurboModule("TestModule", instance, jsInvoker) {

methodMap_["markTestCompleted"] = MethodMetadata {0, __hostFunction_NativeTestModuleSpecJSI_markTestCompleted};


methodMap_["markTestPassed"] = MethodMetadata {1, __hostFunction_NativeTestModuleSpecJSI_markTestPassed};


methodMap_["verifySnapshot"] = MethodMetadata {1, __hostFunction_NativeTestModuleSpecJSI_verifySnapshot};
}

} // namespace react
} // namespace facebook

@interface RCTTestModule() <NativeTestModuleSpec>
@end

@implementation RCTTestModule {
NSMutableDictionary<NSString *, NSNumber *> *_snapshotCounter;
}
Expand Down Expand Up @@ -86,4 +146,13 @@ - (dispatch_queue_t)methodQueue
}];
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
{
return std::make_shared<facebook::react::NativeTestModuleSpecJSI>(self, jsInvoker);
}

@end

Class RCTTestModuleCls(void) {
return RCTTestModule.class;
}
40 changes: 40 additions & 0 deletions RNTester/RCTTest/RCTTestPlugins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by an internal plugin build system
*/

#ifdef RN_DISABLE_OSS_PLUGIN_HEADER

// FB Internal: FBRCTTestPlugins.h is autogenerated by the build system.
#import <React/FBRCTTestPlugins.h>

#else

// OSS-compatibility layer

#import <Foundation/Foundation.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"

#ifdef __cplusplus
extern "C" {
#endif

// RCTTurboModuleManagerDelegate should call this to resolve module classes.
Class RCTTestClassProvider(const char *name);

// Lookup functions
Class RCTTestModuleCls(void) __attribute__((used));

#ifdef __cplusplus
}
#endif

#pragma GCC diagnostic pop

#endif // RN_DISABLE_OSS_PLUGIN_HEADER
32 changes: 32 additions & 0 deletions RNTester/RCTTest/RCTTestPlugins.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by an internal plugin build system
*/

#ifndef RN_DISABLE_OSS_PLUGIN_HEADER

// OSS-compatibility layer

#import "RCTTestPlugins.h"

#import <string>
#import <unordered_map>

Class RCTTestClassProvider(const char *name) {
static std::unordered_map<std::string, Class (*)(void)> sCoreModuleClassMap = {
{"TestModule", RCTTestModuleCls},
};

auto p = sCoreModuleClassMap.find(name);
if (p != sCoreModuleClassMap.end()) {
auto classFunc = p->second;
return classFunc();
}
return nil;
}

#endif // RN_DISABLE_OSS_PLUGIN_HEADER
14 changes: 13 additions & 1 deletion RNTester/RCTTest/React-RCTTest.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ else
source[:tag] = "v#{version}"
end

folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
folly_version = '2020.01.13.00'

Pod::Spec.new do |s|
s.name = "React-RCTTest"
s.version = version
Expand All @@ -24,12 +27,21 @@ Pod::Spec.new do |s|
s.license = package["license"]
s.author = "Facebook, Inc. and its affiliates"
s.platforms = { :ios => "10.0", :tvos => "10.0" }
s.compiler_flags = folly_compiler_flags + ' -Wno-nullability-completeness'
s.source = source
s.source_files = "**/*.{h,m}"
s.source_files = "**/*.{h,m,mm}"
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
s.framework = "XCTest"
s.header_dir = "RCTTest"
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
}

s.dependency "Folly", folly_version
s.dependency "React-Core", version
s.dependency "React-CoreModules", version
s.dependency "ReactCommon/turbomodule/core", version
s.dependency "React-jsi", version
end
24 changes: 12 additions & 12 deletions RNTester/RNTesterPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
27F441EC1BEBE5030039B79C /* FlexibleSizeExampleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 27F441E81BEBE5030039B79C /* FlexibleSizeExampleView.m */; };
2DDEF0101F84BF7B00DBDF73 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2DDEF00F1F84BF7B00DBDF73 /* Images.xcassets */; };
3D2AFAF51D646CF80089D1A3 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 3D2AFAF41D646CF80089D1A3 /* [email protected] */; };
42C7FD8921D436BBA216216D /* libPods-RNTester.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EA4C77A9826FF02A56911142 /* libPods-RNTester.a */; };
57E63A755AEDF197848E52C0 /* libPods-RNTesterIntegrationTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 076801A3AA34E645F870C076 /* libPods-RNTesterIntegrationTests.a */; };
5C60EB1C226440DB0018C04F /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C60EB1B226440DB0018C04F /* AppDelegate.mm */; };
5CB07C9B226467E60039471C /* RNTesterTurboModuleProvider.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CB07C99226467E60039471C /* RNTesterTurboModuleProvider.mm */; };
69B65AC442B001534251D909 /* libPods-RNTesterIntegrationTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5BBFF3E3792E27C4FBA2CB43 /* libPods-RNTesterIntegrationTests.a */; };
C23B0809CAE8A115772B092E /* libPods-RNTesterUnitTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 42A6C306038665FDDA3E54E2 /* libPods-RNTesterUnitTests.a */; };
CA98220F79ABB17F6FE10829 /* libPods-RNTester.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4610AEE3F1885AD3F6741BD1 /* libPods-RNTester.a */; };
E24D92BB73326FCC593E9450 /* libPods-RNTesterUnitTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 060D8FF3BA18357FD288E8C8 /* libPods-RNTesterUnitTests.a */; };
E7C1241A22BEC44B00DA25C0 /* RNTesterIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7C1241922BEC44B00DA25C0 /* RNTesterIntegrationTests.m */; };
E7DB20D122B2BAA6005AC45F /* RCTBundleURLProviderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20A922B2BAA3005AC45F /* RCTBundleURLProviderTests.m */; };
E7DB20D222B2BAA6005AC45F /* RCTModuleInitNotificationRaceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7DB20AA22B2BAA3005AC45F /* RCTModuleInitNotificationRaceTests.m */; };
Expand Down Expand Up @@ -69,6 +69,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
060D8FF3BA18357FD288E8C8 /* libPods-RNTesterUnitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNTesterUnitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
076801A3AA34E645F870C076 /* libPods-RNTesterIntegrationTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNTesterIntegrationTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
13B07F961A680F5B00A75B9A /* RNTester.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RNTester.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = RNTester/AppDelegate.h; sourceTree = "<group>"; };
13B07FB21A68108700A75B9A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
Expand All @@ -81,8 +83,7 @@
2DDEF00F1F84BF7B00DBDF73 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = RNTester/Images.xcassets; sourceTree = "<group>"; };
34028D6B10F47E490042EB27 /* Pods-RNTesterUnitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNTesterUnitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RNTesterUnitTests/Pods-RNTesterUnitTests.debug.xcconfig"; sourceTree = "<group>"; };
3D2AFAF41D646CF80089D1A3 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "RNTester/[email protected]"; sourceTree = "<group>"; };
42A6C306038665FDDA3E54E2 /* libPods-RNTesterUnitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNTesterUnitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
5BBFF3E3792E27C4FBA2CB43 /* libPods-RNTesterIntegrationTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNTesterIntegrationTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4610AEE3F1885AD3F6741BD1 /* libPods-RNTester.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNTester.a"; sourceTree = BUILT_PRODUCTS_DIR; };
5BEC8567F3741044B6A5EFC5 /* Pods-RNTester.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNTester.release.xcconfig"; path = "Pods/Target Support Files/Pods-RNTester/Pods-RNTester.release.xcconfig"; sourceTree = "<group>"; };
5C60EB1B226440DB0018C04F /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = RNTester/AppDelegate.mm; sourceTree = "<group>"; };
5CB07C99226467E60039471C /* RNTesterTurboModuleProvider.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RNTesterTurboModuleProvider.mm; path = RNTester/RNTesterTurboModuleProvider.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -163,15 +164,14 @@
E7DB216122B2F3EC005AC45F /* RCTRootViewIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTRootViewIntegrationTests.m; sourceTree = "<group>"; };
E7DB218B22B41FCD005AC45F /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
E9618482EC8608D4872A6E28 /* Pods-RNTesterUnitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNTesterUnitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-RNTesterUnitTests/Pods-RNTesterUnitTests.release.xcconfig"; sourceTree = "<group>"; };
EA4C77A9826FF02A56911142 /* libPods-RNTester.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNTester.a"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
13B07F8C1A680F5B00A75B9A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
42C7FD8921D436BBA216216D /* libPods-RNTester.a in Frameworks */,
CA98220F79ABB17F6FE10829 /* libPods-RNTester.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -181,7 +181,7 @@
files = (
E7DB213122B2C649005AC45F /* JavaScriptCore.framework in Frameworks */,
E7DB213222B2C67D005AC45F /* libOCMock.a in Frameworks */,
C23B0809CAE8A115772B092E /* libPods-RNTesterUnitTests.a in Frameworks */,
E24D92BB73326FCC593E9450 /* libPods-RNTesterUnitTests.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -191,7 +191,7 @@
files = (
E7DB218C22B41FCD005AC45F /* XCTest.framework in Frameworks */,
E7DB216722B2F69F005AC45F /* JavaScriptCore.framework in Frameworks */,
69B65AC442B001534251D909 /* libPods-RNTesterIntegrationTests.a in Frameworks */,
57E63A755AEDF197848E52C0 /* libPods-RNTesterIntegrationTests.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -261,9 +261,9 @@
E7DB211822B2BD53005AC45F /* libReact-RCTText.a */,
E7DB211A22B2BD53005AC45F /* libReact-RCTVibration.a */,
E7DB212222B2BD53005AC45F /* libyoga.a */,
EA4C77A9826FF02A56911142 /* libPods-RNTester.a */,
5BBFF3E3792E27C4FBA2CB43 /* libPods-RNTesterIntegrationTests.a */,
42A6C306038665FDDA3E54E2 /* libPods-RNTesterUnitTests.a */,
4610AEE3F1885AD3F6741BD1 /* libPods-RNTester.a */,
076801A3AA34E645F870C076 /* libPods-RNTesterIntegrationTests.a */,
060D8FF3BA18357FD288E8C8 /* libPods-RNTesterUnitTests.a */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down

0 comments on commit ff3b839

Please sign in to comment.