Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve N-API test coverage #13006

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/addons-napi/test_globals/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "test_globals",
"sources": [ "test_globals.c" ]
}
]
}
8 changes: 8 additions & 0 deletions test/addons-napi/test_globals/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';
const common = require('../../common');
const assert = require('assert');

const test_globals = require(`./build/${common.buildType}/test_globals`);

assert.strictEqual(test_globals.getUndefined(), undefined);
assert.strictEqual(test_globals.getNull(), null);
26 changes: 26 additions & 0 deletions test/addons-napi/test_globals/test_globals.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <node_api.h>
#include "../common.h"

napi_value getNull(napi_env env, napi_callback_info info) {
napi_value result;
NAPI_CALL(env, napi_get_null(env, &result));
return result;
}

napi_value getUndefined(napi_env env, napi_callback_info info) {
napi_value result;
NAPI_CALL(env, napi_get_undefined(env, &result));
return result;
}

void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("getUndefined", getUndefined),
DECLARE_NAPI_PROPERTY("getNull", getNull),
};

NAPI_CALL_RETURN_VOID(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
}

NAPI_MODULE(addon, Init)