test: make cctest full Node.js environment · nodejs/node@e531258 (original) (raw)

Original file line number Diff line number Diff line change
@@ -64,9 +64,19 @@ class NodeTestFixture : public ::testing::Test {
64 64 static TracingAgentUniquePtr tracing_agent;
65 65 static NodePlatformUniquePtr platform;
66 66 static uv_loop_t current_loop;
67 +static bool node_initialized;
67 68 v8::Isolate* isolate_;
68 69
69 70 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 +
70 80 tracing_agent.reset(new node::tracing::Agent());
71 81 node::tracing::TraceEventHelper::SetAgent(tracing_agent.get());
72 82 CHECK_EQ(0, uv_loop_init(&current_loop));
@@ -89,9 +99,11 @@ class NodeTestFixture : public ::testing::Test {
89 99 &node::FreeArrayBufferAllocator);
90 100 isolate_ = NewIsolate(allocator.get(), &current_loop);
91 101 CHECK_NE(isolate_, nullptr);
102 + isolate_->Enter();
92 103 }
93 104
94 105 void TearDown() override {
106 + isolate_->Exit();
95 107 isolate_->Dispose();
96 108 platform->UnregisterIsolate(isolate_);
97 109 isolate_ = nullptr;
@@ -118,6 +130,8 @@ class EnvironmentTestFixture : public NodeTestFixture {
118 130 1, *argv,
119 131 argv.nr_args(), *argv);
120 132 CHECK_NE(nullptr, environment_);
133 +// TODO(addaleax): Make this a public API.
134 +CHECK(!RunBootstrapping(environment_).IsEmpty());
121 135 }
122 136
123 137 ~Env() {