Skip to content

Commit a7fde7c

Browse files
huntiefacebook-github-bot
authored andcommitted
Enable JSI integration tests for Hermes CDPAgent (#43391)
Summary: Pull Request resolved: #43391 ## Context We are migrating to the new Hermes `CDPAgent` and `CDPDebugAPI` APIs in the modern CDP server (previously `HermesCDPHandler`). ## This diff Bootstraps `HermesRuntimeAgentDelegateNew` within `JsiIntegrationTest.cpp`. Test cases which currently do not pass with `HermesRuntimeAgentDelegateNew` are selectively matched against a new alias to exclude them: `JsiIntegrationHermesLegacyTest`. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D53810357 fbshipit-source-id: 2d7d7446038530d19d93add71361b4bf581cff18
1 parent c6ca7d6 commit a7fde7c

9 files changed

+109
-8
lines changed

packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "UniquePtrFactory.h"
2323
#include "engines/JsiIntegrationTestGenericEngineAdapter.h"
2424
#include "engines/JsiIntegrationTestHermesEngineAdapter.h"
25+
#include "engines/JsiIntegrationTestHermesWithCDPAgentEngineAdapter.h"
2526

2627
using namespace ::testing;
2728
using folly::sformat;
@@ -52,7 +53,9 @@ class JsiIntegrationPortableTest : public Test, private HostTargetDelegate {
5253
folly::QueuedImmediateExecutor immediateExecutor_;
5354

5455
protected:
55-
JsiIntegrationPortableTest() : engineAdapter_{immediateExecutor_} {
56+
JsiIntegrationPortableTest()
57+
: inspectorFlagsGuard_{EngineAdapter::getInspectorFlagOverrides()},
58+
engineAdapter_{immediateExecutor_} {
5659
instance_ = &page_->registerInstance(instanceTargetDelegate_);
5760
runtimeTarget_ = &instance_->registerRuntime(
5861
engineAdapter_->getRuntimeTargetDelegate(),
@@ -136,6 +139,7 @@ class JsiIntegrationPortableTest : public Test, private HostTargetDelegate {
136139
InstanceTarget* instance_{};
137140
RuntimeTarget* runtimeTarget_{};
138141

142+
InspectorFlagOverridesGuard inspectorFlagsGuard_;
139143
MockInstanceTargetDelegate instanceTargetDelegate_;
140144
std::optional<EngineAdapter> engineAdapter_;
141145

@@ -168,17 +172,27 @@ class JsiIntegrationPortableTest : public Test, private HostTargetDelegate {
168172
*/
169173
using AllEngines = Types<
170174
JsiIntegrationTestHermesEngineAdapter,
175+
JsiIntegrationTestHermesWithCDPAgentEngineAdapter,
171176
JsiIntegrationTestGenericEngineAdapter>;
172177

173-
using AllHermesVariants = Types<JsiIntegrationTestHermesEngineAdapter>;
178+
using AllHermesVariants = Types<
179+
JsiIntegrationTestHermesEngineAdapter,
180+
JsiIntegrationTestHermesWithCDPAgentEngineAdapter>;
181+
182+
using LegacyHermesVariants = Types<JsiIntegrationTestHermesEngineAdapter>;
174183

175184
TYPED_TEST_SUITE(JsiIntegrationPortableTest, AllEngines);
176185

177186
template <typename EngineAdapter>
178187
using JsiIntegrationHermesTest = JsiIntegrationPortableTest<EngineAdapter>;
179188
TYPED_TEST_SUITE(JsiIntegrationHermesTest, AllHermesVariants);
180189

181-
////////////////////////////////////////////////////////////////////////////////
190+
template <typename EngineAdapter>
191+
using JsiIntegrationHermesLegacyTest =
192+
JsiIntegrationPortableTest<EngineAdapter>;
193+
TYPED_TEST_SUITE(JsiIntegrationHermesLegacyTest, LegacyHermesVariants);
194+
195+
#pragma region JsiIntegrationPortableTest
182196

183197
TYPED_TEST(JsiIntegrationPortableTest, ConnectWithoutCrashing) {
184198
this->connect();
@@ -458,7 +472,8 @@ TYPED_TEST(JsiIntegrationPortableTest, ExceptionDuringAddBindingIsIgnored) {
458472
EXPECT_TRUE(this->eval("globalThis.foo === 42").getBool());
459473
}
460474

461-
////////////////////////////////////////////////////////////////////////////////
475+
#pragma endregion
476+
#pragma region JsiIntegrationHermesTest
462477

463478
TYPED_TEST(JsiIntegrationHermesTest, EvaluateExpression) {
464479
this->connect();
@@ -479,7 +494,11 @@ TYPED_TEST(JsiIntegrationHermesTest, EvaluateExpression) {
479494
})");
480495
}
481496

482-
TYPED_TEST(JsiIntegrationHermesTest, EvaluateExpressionInExecutionContext) {
497+
// TODO(T181299386): Restore stale execution context validation under
498+
// HermesRuntimeAgentDelegateNew
499+
TYPED_TEST(
500+
JsiIntegrationHermesLegacyTest,
501+
EvaluateExpressionInExecutionContext) {
483502
this->connect();
484503

485504
InSequence s;
@@ -538,7 +557,9 @@ TYPED_TEST(JsiIntegrationHermesTest, EvaluateExpressionInExecutionContext) {
538557
std::to_string(executionContextId)));
539558
}
540559

541-
TYPED_TEST(JsiIntegrationHermesTest, ResolveBreakpointAfterReload) {
560+
// TODO(T178858701): Restore breakpoint reload persistence under
561+
// HermesRuntimeAgentDelegateNew
562+
TYPED_TEST(JsiIntegrationHermesLegacyTest, ResolveBreakpointAfterReload) {
542563
this->connect();
543564

544565
InSequence s;
@@ -580,4 +601,6 @@ TYPED_TEST(JsiIntegrationHermesTest, ResolveBreakpointAfterReload) {
580601
scriptInfo->value()["params"]["scriptId"]);
581602
}
582603

604+
#pragma endregion
605+
583606
} // namespace facebook::react::jsinspector_modern

packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestGenericEngineAdapter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ JsiIntegrationTestGenericEngineAdapter::JsiIntegrationTestGenericEngineAdapter(
2121
runtimeTargetDelegate_{
2222
"Generic engine (" + runtime_->description() + ")"} {}
2323

24+
/* static */ InspectorFlagOverrides
25+
JsiIntegrationTestGenericEngineAdapter::getInspectorFlagOverrides() noexcept {
26+
return {.enableModernCDPRegistry = true};
27+
}
28+
2429
RuntimeTargetDelegate&
2530
JsiIntegrationTestGenericEngineAdapter::getRuntimeTargetDelegate() {
2631
return runtimeTargetDelegate_;

packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestGenericEngineAdapter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include "../utils/InspectorFlagOverridesGuard.h"
11+
1012
#include <jsinspector-modern/FallbackRuntimeTargetDelegate.h>
1113
#include <jsinspector-modern/RuntimeTarget.h>
1214

@@ -26,6 +28,8 @@ class JsiIntegrationTestGenericEngineAdapter {
2628
public:
2729
explicit JsiIntegrationTestGenericEngineAdapter(folly::Executor& jsExecutor);
2830

31+
static InspectorFlagOverrides getInspectorFlagOverrides() noexcept;
32+
2933
RuntimeTargetDelegate& getRuntimeTargetDelegate();
3034

3135
jsi::Runtime& getRuntime() const noexcept;

packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestHermesEngineAdapter.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#include <folly/executors/QueuedImmediateExecutor.h>
9-
108
#include "JsiIntegrationTestHermesEngineAdapter.h"
9+
#include "../utils/InspectorFlagOverridesGuard.h"
10+
11+
#include <folly/executors/QueuedImmediateExecutor.h>
1112

1213
using facebook::hermes::makeHermesRuntime;
1314

@@ -19,6 +20,11 @@ JsiIntegrationTestHermesEngineAdapter::JsiIntegrationTestHermesEngineAdapter(
1920
jsExecutor_{jsExecutor},
2021
runtimeTargetDelegate_{runtime_} {}
2122

23+
/* static */ InspectorFlagOverrides
24+
JsiIntegrationTestHermesEngineAdapter::getInspectorFlagOverrides() noexcept {
25+
return {.enableModernCDPRegistry = true};
26+
}
27+
2228
RuntimeTargetDelegate&
2329
JsiIntegrationTestHermesEngineAdapter::getRuntimeTargetDelegate() {
2430
return runtimeTargetDelegate_;

packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestHermesEngineAdapter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include "../utils/InspectorFlagOverridesGuard.h"
11+
1012
#include <jsinspector-modern/RuntimeTarget.h>
1113

1214
#include <folly/executors/QueuedImmediateExecutor.h>
@@ -26,6 +28,8 @@ class JsiIntegrationTestHermesEngineAdapter {
2628
public:
2729
explicit JsiIntegrationTestHermesEngineAdapter(folly::Executor& jsExecutor);
2830

31+
static InspectorFlagOverrides getInspectorFlagOverrides() noexcept;
32+
2933
RuntimeTargetDelegate& getRuntimeTargetDelegate();
3034

3135
jsi::Runtime& getRuntime() const noexcept;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "JsiIntegrationTestHermesWithCDPAgentEngineAdapter.h"
9+
10+
namespace facebook::react::jsinspector_modern {
11+
12+
JsiIntegrationTestHermesWithCDPAgentEngineAdapter::
13+
JsiIntegrationTestHermesWithCDPAgentEngineAdapter(
14+
folly::Executor& jsExecutor)
15+
: JsiIntegrationTestHermesEngineAdapter(jsExecutor) {}
16+
17+
/* static */ InspectorFlagOverrides
18+
JsiIntegrationTestHermesWithCDPAgentEngineAdapter::
19+
getInspectorFlagOverrides() noexcept {
20+
return {
21+
.enableHermesCDPAgent = true,
22+
.enableModernCDPRegistry = true,
23+
};
24+
}
25+
26+
} // namespace facebook::react::jsinspector_modern
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include "../utils/InspectorFlagOverridesGuard.h"
11+
#include "JsiIntegrationTestHermesEngineAdapter.h"
12+
13+
namespace facebook::react::jsinspector_modern {
14+
15+
/**
16+
* An engine adapter for JsiIntegrationTest that uses Hermes (and Hermes's
17+
* new CDPAgent API).
18+
*/
19+
class JsiIntegrationTestHermesWithCDPAgentEngineAdapter
20+
: public JsiIntegrationTestHermesEngineAdapter {
21+
public:
22+
explicit JsiIntegrationTestHermesWithCDPAgentEngineAdapter(
23+
folly::Executor& jsExecutor);
24+
25+
static InspectorFlagOverrides getInspectorFlagOverrides() noexcept;
26+
};
27+
28+
} // namespace facebook::react::jsinspector_modern

packages/react-native/ReactCommon/jsinspector-modern/tests/utils/InspectorFlagOverridesGuard.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class ReactNativeFeatureFlagsOverrides
3030
return overrides_.enableCxxInspectorPackagerConnection;
3131
}
3232

33+
bool inspectorEnableHermesCDPAgent() override {
34+
return overrides_.enableHermesCDPAgent;
35+
}
36+
3337
bool inspectorEnableModernCDPRegistry() override {
3438
return overrides_.enableModernCDPRegistry;
3539
}

packages/react-native/ReactCommon/jsinspector-modern/tests/utils/InspectorFlagOverridesGuard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct InspectorFlagOverrides {
1818
// NOTE: Keep these entries in sync with ReactNativeFeatureFlagsOverrides in
1919
// the implementation file.
2020
bool enableCxxInspectorPackagerConnection = false;
21+
bool enableHermesCDPAgent = false;
2122
bool enableModernCDPRegistry = false;
2223
};
2324

0 commit comments

Comments
 (0)