From 58b00f4cca79ac61864009e3c24194c4bc5c8de2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 5 Mar 2019 20:14:44 +0100 Subject: [PATCH] test: make cctest full Node.js environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure `node::Init()` is called once, and execute `RunBootstrapping()` so that Node’s internals are ready when the cctests run. PR-URL: https://github.com/nodejs/node/pull/26457 Reviewed-By: Ben Noordhuis Reviewed-By: Joyee Cheung Reviewed-By: Shelley Vohr Reviewed-By: James M Snell --- test/cctest/node_test_fixture.cc | 1 + test/cctest/node_test_fixture.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/test/cctest/node_test_fixture.cc b/test/cctest/node_test_fixture.cc index f13481824734fb..1a50e58dd9e8fa 100644 --- a/test/cctest/node_test_fixture.cc +++ b/test/cctest/node_test_fixture.cc @@ -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; diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h index f7ecb9cdea744e..02c1164691b138 100644 --- a/test/cctest/node_test_fixture.h +++ b/test/cctest/node_test_fixture.h @@ -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(¤t_loop)); @@ -89,9 +99,11 @@ class NodeTestFixture : public ::testing::Test { &node::FreeArrayBufferAllocator); isolate_ = NewIsolate(allocator.get(), ¤t_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() {