Skip to content

Commit e531258

Browse files
addaleaxtargos
authored andcommitted
test: make cctest full Node.js environment
Make sure `node::Init()` is called once, and execute `RunBootstrapping()` so that Node’s internals are ready when the cctests run. PR-URL: #26457 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 070faf0 commit e531258

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: test/cctest/node_test_fixture.cc

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ ArrayBufferUniquePtr NodeTestFixture::allocator{nullptr, nullptr};
44
uv_loop_t NodeTestFixture::current_loop;
55
NodePlatformUniquePtr NodeTestFixture::platform;
66
TracingAgentUniquePtr NodeTestFixture::tracing_agent;
7+
bool NodeTestFixture::node_initialized = false;

Diff for: test/cctest/node_test_fixture.h

+14
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,19 @@ class NodeTestFixture : public ::testing::Test {
6464
static TracingAgentUniquePtr tracing_agent;
6565
static NodePlatformUniquePtr platform;
6666
static uv_loop_t current_loop;
67+
static bool node_initialized;
6768
v8::Isolate* isolate_;
6869

6970
static void SetUpTestCase() {
71+
if (!node_initialized) {
72+
node_initialized = true;
73+
int argc = 1;
74+
const char* argv0 = "cctest";
75+
int exec_argc;
76+
const char** exec_argv;
77+
node::Init(&argc, &argv0, &exec_argc, &exec_argv);
78+
}
79+
7080
tracing_agent.reset(new node::tracing::Agent());
7181
node::tracing::TraceEventHelper::SetAgent(tracing_agent.get());
7282
CHECK_EQ(0, uv_loop_init(&current_loop));
@@ -89,9 +99,11 @@ class NodeTestFixture : public ::testing::Test {
8999
&node::FreeArrayBufferAllocator);
90100
isolate_ = NewIsolate(allocator.get(), &current_loop);
91101
CHECK_NE(isolate_, nullptr);
102+
isolate_->Enter();
92103
}
93104

94105
void TearDown() override {
106+
isolate_->Exit();
95107
isolate_->Dispose();
96108
platform->UnregisterIsolate(isolate_);
97109
isolate_ = nullptr;
@@ -118,6 +130,8 @@ class EnvironmentTestFixture : public NodeTestFixture {
118130
1, *argv,
119131
argv.nr_args(), *argv);
120132
CHECK_NE(nullptr, environment_);
133+
// TODO(addaleax): Make this a public API.
134+
CHECK(!RunBootstrapping(environment_).IsEmpty());
121135
}
122136

123137
~Env() {

0 commit comments

Comments
 (0)