@@ -60,18 +60,26 @@ using ArrayBufferUniquePtr = std::unique_ptr<node::ArrayBufferAllocator,
6060using TracingAgentUniquePtr = std::unique_ptr<node::tracing::Agent>;
6161using NodePlatformUniquePtr = std::unique_ptr<node::NodePlatform>;
6262
63+ class NodeTestEnvironment final : public ::testing::Environment {
64+ public:
65+ NodeTestEnvironment () = default ;
66+ void SetUp () override ;
67+ void TearDown () override ;
68+ };
69+
70+
6371class NodeZeroIsolateTestFixture : public ::testing::Test {
6472 protected:
65- static ArrayBufferUniquePtr allocator;
66- static TracingAgentUniquePtr tracing_agent;
67- static NodePlatformUniquePtr platform;
6873 static uv_loop_t current_loop;
6974 static bool node_initialized;
75+ static ArrayBufferUniquePtr allocator;
76+ static NodePlatformUniquePtr platform;
77+ static TracingAgentUniquePtr tracing_agent;
7078
7179 static void SetUpTestCase () {
7280 if (!node_initialized) {
73- uv_os_unsetenv (" NODE_OPTIONS" );
7481 node_initialized = true ;
82+ uv_os_unsetenv (" NODE_OPTIONS" );
7583 std::vector<std::string> argv { " cctest" };
7684 std::vector<std::string> exec_argv;
7785 std::vector<std::string> errors;
@@ -80,32 +88,22 @@ class NodeZeroIsolateTestFixture : public ::testing::Test {
8088 CHECK_EQ (exitcode, 0 );
8189 CHECK (errors.empty ());
8290 }
83-
84- tracing_agent = std::make_unique<node::tracing::Agent>();
85- node::tracing::TraceEventHelper::SetAgent (tracing_agent.get ());
86- node::tracing::TracingController* tracing_controller =
87- tracing_agent->GetTracingController ();
8891 CHECK_EQ (0 , uv_loop_init (¤t_loop));
89- static constexpr int kV8ThreadPoolSize = 4 ;
90- platform.reset (
91- new node::NodePlatform (kV8ThreadPoolSize , tracing_controller));
92- v8::V8::InitializePlatform (platform.get ());
93- v8::V8::Initialize ();
9492 }
9593
9694 static void TearDownTestCase () {
97- platform->Shutdown ();
9895 while (uv_loop_alive (¤t_loop)) {
9996 uv_run (¤t_loop, UV_RUN_ONCE);
10097 }
101- v8::V8::DisposePlatform ();
10298 CHECK_EQ (0 , uv_loop_close (¤t_loop));
10399 }
104100
105101 void SetUp () override {
106102 allocator = ArrayBufferUniquePtr (node::CreateArrayBufferAllocator (),
107103 &node::FreeArrayBufferAllocator);
108104 }
105+
106+ friend NodeTestEnvironment;
109107};
110108
111109
0 commit comments