From 938e11882b96e19b443477571455088baaa054d8 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Sat, 17 Nov 2018 12:34:54 -0800 Subject: test: partition N-API tests Partition test/addons-napi into test/js-native-api and test/node-api to isolate the Node.js-agnostic portion of the N-API tests from the Node.js-specific portion. PR-URL: https://github.com/nodejs/node/pull/24557 Reviewed-By: Refael Ackermann Reviewed-By: Daniel Bevenius --- test/js-native-api/4_object_factory/binding.c | 23 +++++++++++++++++++++++ test/js-native-api/4_object_factory/binding.gyp | 11 +++++++++++ test/js-native-api/4_object_factory/test.js | 8 ++++++++ 3 files changed, 42 insertions(+) create mode 100644 test/js-native-api/4_object_factory/binding.c create mode 100644 test/js-native-api/4_object_factory/binding.gyp create mode 100644 test/js-native-api/4_object_factory/test.js (limited to 'test/js-native-api/4_object_factory') diff --git a/test/js-native-api/4_object_factory/binding.c b/test/js-native-api/4_object_factory/binding.c new file mode 100644 index 0000000000..5e1403a892 --- /dev/null +++ b/test/js-native-api/4_object_factory/binding.c @@ -0,0 +1,23 @@ +#include +#include "../common.h" + +static napi_value CreateObject(napi_env env, napi_callback_info info) { + size_t argc = 1; + napi_value args[1]; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); + + napi_value obj; + NAPI_CALL(env, napi_create_object(env, &obj)); + + NAPI_CALL(env, napi_set_named_property(env, obj, "msg", args[0])); + + return obj; +} + +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { + NAPI_CALL(env, + napi_create_function(env, "exports", -1, CreateObject, NULL, &exports)); + return exports; +} +EXTERN_C_END diff --git a/test/js-native-api/4_object_factory/binding.gyp b/test/js-native-api/4_object_factory/binding.gyp new file mode 100644 index 0000000000..2a144bab42 --- /dev/null +++ b/test/js-native-api/4_object_factory/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ + "../entry_point.c", + "binding.c" + ] + } + ] +} diff --git a/test/js-native-api/4_object_factory/test.js b/test/js-native-api/4_object_factory/test.js new file mode 100644 index 0000000000..15313c1547 --- /dev/null +++ b/test/js-native-api/4_object_factory/test.js @@ -0,0 +1,8 @@ +'use strict'; +const common = require('../../common'); +const assert = require('assert'); +const addon = require(`./build/${common.buildType}/binding`); + +const obj1 = addon('hello'); +const obj2 = addon('world'); +assert.strictEqual(`${obj1.msg} ${obj2.msg}`, 'hello world'); -- cgit v1.2.3