Skip to content

Commit

Permalink
Fix getLoadedScripts test
Browse files Browse the repository at this point in the history
Summary:
The `getLoadedScripts` test was invoking the observer that was
installed in the `DebuggerAPITest` setup, and inspecting program
state at an inopportune time. Make the test construct its own
runtime instead.

Reviewed By: ftanuma

Differential Revision: D54800717

fbshipit-source-id: c2a438e3744601857792e770c63523cc3b914ee4
  • Loading branch information
Matt Blagden authored and facebook-github-bot committed Mar 12, 2024
1 parent b0fb9c9 commit b8cd4ff
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions unittests/API/DebuggerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ struct DebuggerAPITest : public ::testing::Test {
TestEventObserver observer;

DebuggerAPITest()
: rt(makeHermesRuntime(
((hermes::vm::RuntimeConfig::Builder())
.withEnableBlockScoping(true)
.withCompilationMode(
hermes::vm::CompilationMode::ForceLazyCompilation)
.build()))) {
: rt(makeHermesRuntime(((hermes::vm::RuntimeConfig::Builder())
.withEnableBlockScoping(true)
.build()))) {
rt->getDebugger().setEventObserver(&observer);
}
};
Expand Down Expand Up @@ -135,11 +132,21 @@ TEST_F(DebuggerAPITest, SingleFrameStackTraceTest) {
}

TEST_F(DebuggerAPITest, GetLoadedScriptsTest) {
auto scripts = rt->getDebugger().getLoadedScripts();
// Don't use the member runtime, as we don't want to
// trigger the observer on script loads.
std::unique_ptr<HermesRuntime> runtime = makeHermesRuntime(
((hermes::vm::RuntimeConfig::Builder())
.withCompilationMode(
hermes::vm::CompilationMode::ForceLazyCompilation)
.build()));

auto scripts = runtime->getDebugger().getLoadedScripts();
EXPECT_EQ(scripts.size(), 0);

eval("var x = 1;");
scripts = rt->getDebugger().getLoadedScripts();
runtime->global()
.getPropertyAsFunction(*runtime, "eval")
.call(*runtime, "var x = 1;");
scripts = runtime->getDebugger().getLoadedScripts();
EXPECT_EQ(scripts.size(), 1);
EXPECT_EQ(scripts[0].line, 1);
EXPECT_EQ(scripts[0].column, 1);
Expand All @@ -151,8 +158,8 @@ TEST_F(DebuggerAPITest, GetLoadedScriptsTest) {
// compilation in the test setup) to cause multiple runtime modules for this
// single script, allowing this test to verify we don't get duplicate
// results.
rt->debugJavaScript("(function(){var x = 2;})()", "Test.js", {});
scripts = rt->getDebugger().getLoadedScripts();
runtime->debugJavaScript("(function(){var x = 2;})()", "Test.js", {});
scripts = runtime->getDebugger().getLoadedScripts();
EXPECT_EQ(scripts.size(), 2);
for (auto script : scripts) {
if (script.fileName == "JavaScript") {
Expand Down

0 comments on commit b8cd4ff

Please sign in to comment.