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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Anna Henningsen authored and Ruben Bridgewater committed 2019-03-09 00:29:34 +01:00
1 parent 2699f8c860
commit 58b00f4cca
2 files changed
+15

No files matched your search

+1
View File
@@ -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
View File
@@ -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() {