Skip to content

Commit

Permalink
test: make cctest full Node.js environment
Browse files Browse the repository at this point in the history
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 <info@bnoordhuis.nl>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and targos committed Mar 27, 2019
1 parent 070faf0 commit e531258
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/cctest/node_test_fixture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ArrayBufferUniquePtr NodeTestFixture::allocator{nullptr, nullptr};
uv_loop_t NodeTestFixture::current_loop;
NodePlatformUniquePtr NodeTestFixture::platform;
TracingAgentUniquePtr NodeTestFixture::tracing_agent;
bool NodeTestFixture::node_initialized = false;
14 changes: 14 additions & 0 deletions test/cctest/node_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,19 @@ class NodeTestFixture : public ::testing::Test {
static TracingAgentUniquePtr tracing_agent;
static NodePlatformUniquePtr platform;
static uv_loop_t current_loop;
static bool node_initialized;
v8::Isolate* isolate_;

static void SetUpTestCase() {
if (!node_initialized) {
node_initialized = true;
int argc = 1;
const char* argv0 = "cctest";
int exec_argc;
const char** exec_argv;
node::Init(&argc, &argv0, &exec_argc, &exec_argv);
}

tracing_agent.reset(new node::tracing::Agent());
node::tracing::TraceEventHelper::SetAgent(tracing_agent.get());
CHECK_EQ(0, uv_loop_init(&current_loop));
Expand All @@ -89,9 +99,11 @@ class NodeTestFixture : public ::testing::Test {
&node::FreeArrayBufferAllocator);
isolate_ = NewIsolate(allocator.get(), &current_loop);
CHECK_NE(isolate_, nullptr);
isolate_->Enter();
}

void TearDown() override {
isolate_->Exit();
isolate_->Dispose();
platform->UnregisterIsolate(isolate_);
isolate_ = nullptr;
Expand All @@ -118,6 +130,8 @@ class EnvironmentTestFixture : public NodeTestFixture {
1, *argv,
argv.nr_args(), *argv);
CHECK_NE(nullptr, environment_);
// TODO(addaleax): Make this a public API.
CHECK(!RunBootstrapping(environment_).IsEmpty());
}

~Env() {
Expand Down

0 comments on commit e531258

Please sign in to comment.