diff --git a/tachyon/node/base/test/BUILD.bazel b/tachyon/node/base/test/BUILD.bazel index e352e8d62..dd5c7a0c9 100644 --- a/tachyon/node/base/test/BUILD.bazel +++ b/tachyon/node/base/test/BUILD.bazel @@ -24,32 +24,12 @@ tachyon_cc_library( ) tachyon_node_library( - name = "class", + name = "test", testonly = True, - srcs = ["class.cc"], + srcs = ["test.cc"], deps = [ ":color", ":point", - "//tachyon/node/base:node_base", - ], -) - -tachyon_node_library( - name = "enum", - testonly = True, - srcs = ["enum.cc"], - deps = [ - ":color", - "//tachyon/node/base:node_base", - ], -) - -tachyon_node_library( - name = "function", - testonly = True, - srcs = ["function.cc"], - deps = [ "//tachyon/base/binding/test:functions", - "//tachyon/node/base:node_base", ], ) diff --git a/tachyon/node/base/test/color.cc b/tachyon/node/base/test/color.cc index 8aa466e40..6874544cb 100644 --- a/tachyon/node/base/test/color.cc +++ b/tachyon/node/base/test/color.cc @@ -6,10 +6,6 @@ void AddColor(tachyon::node::NodeModule& m) { using namespace tachyon::base::test; - m.NewEnum("color") - .AddValue("red", Color::kRed) - .AddValue("green", Color::kGreen) - .AddValue("blue", Color::kBlue); } #endif // defined(TACHYON_NODE_BINDING) diff --git a/tachyon/node/base/test/enum.cc b/tachyon/node/base/test/enum.cc deleted file mode 100644 index b1d0f8bf9..000000000 --- a/tachyon/node/base/test/enum.cc +++ /dev/null @@ -1,13 +0,0 @@ -#if defined(TACHYON_NODE_BINDING) - -#include "tachyon/node/base/test/color.h" - -Napi::Object Init(Napi::Env env, Napi::Object exports) { - tachyon::node::NodeModule module(env, exports); - AddColor(module); - return exports; -} - -NODE_API_MODULE(enum, Init) - -#endif // defined(TACHYON_NODE_BINDING) diff --git a/tachyon/node/base/test/function.cc b/tachyon/node/base/test/function.cc deleted file mode 100644 index 7c087a642..000000000 --- a/tachyon/node/base/test/function.cc +++ /dev/null @@ -1,17 +0,0 @@ -#if defined(TACHYON_NODE_BINDING) - -#include "tachyon/base/binding/test/functions.h" -#include "tachyon/node/base/node_module.h" - -Napi::Object Init(Napi::Env env, Napi::Object exports) { - using namespace tachyon::base::test; - tachyon::node::NodeModule module(env, exports); - module.AddFunction("hello", &Hello) - .AddFunction("sum", &Sum, 1, 2) - .AddFunction("do_nothing", &DoNothing); - return exports; -} - -NODE_API_MODULE(function, Init) - -#endif // defined(TACHYON_NODE_BINDING) diff --git a/tachyon/node/base/test/class.cc b/tachyon/node/base/test/test.cc similarity index 76% rename from tachyon/node/base/test/class.cc rename to tachyon/node/base/test/test.cc index ca2302e2b..afeed4bea 100644 --- a/tachyon/node/base/test/class.cc +++ b/tachyon/node/base/test/test.cc @@ -2,8 +2,10 @@ #include "tachyon/base/binding/test/adder.h" #include "tachyon/base/binding/test/colored_point.h" +#include "tachyon/base/binding/test/functions.h" #include "tachyon/base/binding/test/rect.h" #include "tachyon/base/binding/test/variant.h" +#include "tachyon/node/base/node_module.h" #include "tachyon/node/base/test/color.h" #include "tachyon/node/base/test/point.h" @@ -12,22 +14,31 @@ void AcceptColoredPoint(tachyon::base::test::ColoredPoint& cp) {} Napi::Object Init(Napi::Env env, Napi::Object exports) { using namespace tachyon::base::test; - tachyon::node::NodeModule module(env, exports); - AddColor(module); + tachyon::node::NodeModule m(env, exports); + + m.AddFunction("hello", &Hello) + .AddFunction("sum", &Sum, 1, 2) + .AddFunction("do_nothing", &DoNothing); + + m.NewEnum("color") + .AddValue("red", Color::kRed) + .AddValue("green", Color::kGreen) + .AddValue("blue", Color::kBlue); + // TODO(chokobole): I tried testing all these variation either in same addon // or different addon. But it somehow corrupts this addon. So I need to figure // out how to gracefully test! Uncomment either one of AddXXXPoint. - AddPoint(module); + AddPoint(m); // This enable 'shared_ptr' test in 'class.spec.ts'. - // AddSharedPoint(module); + // AddSharedPoint(m); // This enable 'unique_ptr' test in 'class.spec.ts'. - // AddUniquePoint(module); + // AddUniquePoint(m); - module.NewClass("ColoredPoint") + m.NewClass("ColoredPoint") .AddConstructor<>() .AddConstructor(); - module.NewClass("Rect") + m.NewClass("Rect") .AddConstructor<>() .AddConstructor() .AddReadWrite("topLeft", &Rect::top_left) @@ -37,12 +48,12 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { .AddMethod("getBottomRight", &Rect::GetBottomRight) .AddMethod("getConstBottomRight", &Rect::GetConstBottomRight); - module.NewClass("Adder") + m.NewClass("Adder") .AddConstructor<>() .AddMethod("add", &Adder::Add, 1, 2, 3, 4) .AddStaticMethod("sAdd", &Adder::SAdd, 1, 2, 3, 4); - module.NewClass("Variant") + m.NewClass("Variant") .AddConstructor() .AddConstructor() .AddConstructor() @@ -57,7 +68,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { .AddReadWrite("ivec", &Variant::ivec) .AddReadWrite("p", &Variant::p); - module.AddFunction("doubleWithValue", &DoubleWithValue) + m.AddFunction("doubleWithValue", &DoubleWithValue) .AddFunction("doubleWithReference", &DoubleWithReference) .AddFunction("doubleWithSharedPtr", &DoubleWithSharedPtr) .AddFunction("doubleWithUniquePtr", &DoubleWithUniquePtr) @@ -65,6 +76,6 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { return exports; } -NODE_API_MODULE(class, Init) +NODE_API_MODULE(test, Init) #endif // defined(TACHYON_NODE_BINDING) diff --git a/tachyon/node/test/src/base/test/BUILD.bazel b/tachyon/node/test/src/base/test/BUILD.bazel index 16fa21f21..f58131933 100644 --- a/tachyon/node/test/src/base/test/BUILD.bazel +++ b/tachyon/node/test/src/base/test/BUILD.bazel @@ -9,11 +9,7 @@ tachyon_ts_project( "enum.spec.ts", "function.spec.ts", ], - data = [ - "@kroma_network_tachyon//tachyon/node/base/test:class", - "@kroma_network_tachyon//tachyon/node/base/test:enum", - "@kroma_network_tachyon//tachyon/node/base/test:function", - ], + data = ["@kroma_network_tachyon//tachyon/node/base/test"], ) tachyon_jest_test( diff --git a/tachyon/node/test/src/base/test/class.spec.ts b/tachyon/node/test/src/base/test/class.spec.ts index 158daf554..dfee7fb47 100644 --- a/tachyon/node/test/src/base/test/class.spec.ts +++ b/tachyon/node/test/src/base/test/class.spec.ts @@ -1,6 +1,7 @@ import { describe, expect, test } from '@jest/globals'; -const class_test = require('../../../external/kroma_network_tachyon/tachyon/node/base/test/class.node'); +const class_test = require( + '../../../external/kroma_network_tachyon/tachyon/node/base/test/test.node'); const callNonConstMethod = TypeError('Call non-const method'); const noSuchConstructor = TypeError('No such constructor'); diff --git a/tachyon/node/test/src/base/test/enum.spec.ts b/tachyon/node/test/src/base/test/enum.spec.ts index d906a0619..724189f86 100644 --- a/tachyon/node/test/src/base/test/enum.spec.ts +++ b/tachyon/node/test/src/base/test/enum.spec.ts @@ -1,6 +1,7 @@ import { describe, expect, test } from '@jest/globals'; -const enum_test = require('../../../external/kroma_network_tachyon/tachyon/node/base/test/enum.node'); +const enum_test = require( + '../../../external/kroma_network_tachyon/tachyon/node/base/test/test.node'); describe('enum', () => { test('enum values', () => { diff --git a/tachyon/node/test/src/base/test/function.spec.ts b/tachyon/node/test/src/base/test/function.spec.ts index ad492e2ff..058f9e965 100644 --- a/tachyon/node/test/src/base/test/function.spec.ts +++ b/tachyon/node/test/src/base/test/function.spec.ts @@ -1,6 +1,7 @@ import { describe, expect, test } from '@jest/globals'; -const functionTest = require('../../../external/kroma_network_tachyon/tachyon/node/base/test/function.node'); +const functionTest = require( + '../../../external/kroma_network_tachyon/tachyon/node/base/test/test.node'); const wrongNumberOfArguments = TypeError('Wrong number of arguments');