• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <cstdio>
3 #include <string>
4 #include "env-inl.h"
5 #include "gtest/gtest.h"
6 #include "node_api_internals.h"
7 #include "node_binding.h"
8 #include "node_test_fixture.h"
9 
10 using v8::Local;
11 using v8::Object;
12 
13 static napi_env addon_env;
14 
15 class NodeApiTest : public EnvironmentTestFixture {
16  private:
SetUp()17   void SetUp() override { EnvironmentTestFixture::SetUp(); }
18 
TearDown()19   void TearDown() override { NodeTestFixture::TearDown(); }
20 };
21 
TEST_F(NodeApiTest,CreateNodeApiEnv)22 TEST_F(NodeApiTest, CreateNodeApiEnv) {
23   const v8::HandleScope handle_scope(isolate_);
24   Argv argv;
25 
26   Env test_env{handle_scope, argv};
27 
28   node::Environment* env = *test_env;
29   node::LoadEnvironment(env, "");
30 
31   napi_addon_register_func init = [](napi_env env, napi_value exports) {
32     addon_env = env;
33     return exports;
34   };
35   Local<Object> module_obj = Object::New(isolate_);
36   Local<Object> exports_obj = Object::New(isolate_);
37   napi_module_register_by_symbol(exports_obj, module_obj, env->context(), init);
38   ASSERT_NE(addon_env, nullptr);
39   node_napi_env internal_env = reinterpret_cast<node_napi_env>(addon_env);
40   EXPECT_EQ(internal_env->node_env(), env);
41 }
42