Skip to content

Commit 5027375

Browse files
motiz88meta-codesync[bot]
authored andcommitted
Lightly refactor DebuggerSessionObserverTest (facebook#54055)
Summary: Pull Request resolved: facebook#54055 Changelog: [Internal] TSIA Reviewed By: robhogan Differential Revision: D83841197 fbshipit-source-id: e263f4098e09d0789abc1c33ee7ca4dac44600b2
1 parent 07f40ec commit 5027375

File tree

2 files changed

+151
-214
lines changed

2 files changed

+151
-214
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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 <folly/executors/QueuedImmediateExecutor.h>
9+
10+
#include "JsiIntegrationTest.h"
11+
#include "engines/JsiIntegrationTestHermesEngineAdapter.h"
12+
13+
using namespace ::testing;
14+
15+
namespace facebook::react::jsinspector_modern {
16+
17+
class DebuggerSessionObserverTest : public JsiIntegrationPortableTestBase<
18+
JsiIntegrationTestHermesEngineAdapter,
19+
folly::QueuedImmediateExecutor> {
20+
protected:
21+
void enableRuntimeDomain() {
22+
InSequence s;
23+
24+
auto executionContextInfo = expectMessageFromPage(JsonParsed(
25+
AllOf(AtJsonPtr("/method", "Runtime.executionContextCreated"))));
26+
expectMessageFromPage(JsonEq(R"({
27+
"id": 1,
28+
"result": {}
29+
})"));
30+
toPage_->sendMessage(R"({
31+
"id": 1,
32+
"method": "Runtime.enable"
33+
})");
34+
}
35+
36+
void enableLogDomain() {
37+
InSequence s;
38+
39+
EXPECT_CALL(
40+
fromPage(),
41+
onMessage(JsonParsed(AllOf(
42+
AtJsonPtr("/method", "Log.entryAdded"),
43+
AtJsonPtr("/params/entry", Not(IsEmpty()))))))
44+
.Times(AtLeast(1));
45+
expectMessageFromPage(JsonEq(R"({
46+
"id": 1,
47+
"result": {}
48+
})"));
49+
toPage_->sendMessage(R"({
50+
"id": 1,
51+
"method": "Log.enable"
52+
})");
53+
}
54+
55+
void disableRuntimeDomain() {
56+
InSequence s;
57+
expectMessageFromPage(JsonEq(R"({
58+
"id": 1,
59+
"result": {}
60+
})"));
61+
toPage_->sendMessage(R"({
62+
"id": 1,
63+
"method": "Runtime.disable"
64+
})");
65+
}
66+
67+
void disableLogDomain() {
68+
InSequence s;
69+
expectMessageFromPage(JsonEq(R"({
70+
"id": 1,
71+
"result": {}
72+
})"));
73+
toPage_->sendMessage(R"({
74+
"id": 1,
75+
"method": "Log.disable"
76+
})");
77+
}
78+
};
79+
80+
TEST_F(DebuggerSessionObserverTest, InstallsGlobalObserverObjectByDefault) {
81+
EXPECT_TRUE(eval("__DEBUGGER_SESSION_OBSERVER__ != null").asBool());
82+
}
83+
84+
TEST_F(
85+
DebuggerSessionObserverTest,
86+
WillNotEmitStatusUpdateUnlessBothRuntimeAndLogDomainsAreEnabled) {
87+
EXPECT_FALSE(eval("__DEBUGGER_SESSION_OBSERVER__.hasActiveSession").asBool());
88+
89+
connect();
90+
91+
EXPECT_FALSE(eval("__DEBUGGER_SESSION_OBSERVER__.hasActiveSession").asBool());
92+
93+
enableRuntimeDomain();
94+
95+
EXPECT_FALSE(eval("__DEBUGGER_SESSION_OBSERVER__.hasActiveSession").asBool());
96+
97+
enableLogDomain();
98+
99+
EXPECT_TRUE(eval("__DEBUGGER_SESSION_OBSERVER__.hasActiveSession").asBool());
100+
}
101+
102+
TEST_F(
103+
DebuggerSessionObserverTest,
104+
UpdatesTheStatusOnceRuntimeDomainIsDisabled) {
105+
connect();
106+
enableLogDomain();
107+
enableRuntimeDomain();
108+
109+
EXPECT_TRUE(eval("__DEBUGGER_SESSION_OBSERVER__.hasActiveSession").asBool());
110+
111+
disableRuntimeDomain();
112+
113+
EXPECT_FALSE(eval("__DEBUGGER_SESSION_OBSERVER__.hasActiveSession").asBool());
114+
}
115+
116+
TEST_F(DebuggerSessionObserverTest, UpdatesTheStatusOnceLogDomainIsDisabled) {
117+
connect();
118+
enableLogDomain();
119+
enableRuntimeDomain();
120+
121+
EXPECT_TRUE(eval("__DEBUGGER_SESSION_OBSERVER__.hasActiveSession").asBool());
122+
123+
disableLogDomain();
124+
125+
EXPECT_FALSE(eval("__DEBUGGER_SESSION_OBSERVER__.hasActiveSession").asBool());
126+
}
127+
128+
TEST_F(
129+
DebuggerSessionObserverTest,
130+
NotifiesSubscribersWhichWereSubscribedBeforeSessionInitialization) {
131+
eval(
132+
R"(
133+
var latestStatus = undefined;
134+
__DEBUGGER_SESSION_OBSERVER__.subscribers.add(updatedStatus => {
135+
latestStatus = updatedStatus;
136+
});
137+
)");
138+
139+
EXPECT_TRUE(eval("latestStatus").isUndefined());
140+
141+
connect();
142+
enableLogDomain();
143+
enableRuntimeDomain();
144+
EXPECT_TRUE(eval("latestStatus").asBool());
145+
146+
disableLogDomain();
147+
148+
EXPECT_FALSE(eval("latestStatus").asBool());
149+
}
150+
151+
} // namespace facebook::react::jsinspector_modern

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

Lines changed: 0 additions & 214 deletions
This file was deleted.

0 commit comments

Comments
 (0)