Skip to content
Permalink
Browse files

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 <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 5, 2019
1 parent 070faf0 commit e5312585c1e7619e05e7d7fe222169deca744ebc
Showing with 15 additions and 0 deletions.
  1. +1 −0 test/cctest/node_test_fixture.cc
  2. +14 −0 test/cctest/node_test_fixture.h
@@ -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;
@@ -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));
@@ -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;
@@ -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() {

0 comments on commit e531258

Please sign in to comment.
You can’t perform that action at this time.