Skip to content

Commit 47c3c58

Browse files
committed
test: improve N-API test coverage
Add tests to cover functions that return globals PR-URL: #13006 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jason Ginchereau <[email protected]>
1 parent 1b28022 commit 47c3c58

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "test_globals",
5+
"sources": [ "test_globals.c" ]
6+
}
7+
]
8+
}

test/addons-napi/test_globals/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
const common = require('../../common');
3+
const assert = require('assert');
4+
5+
const test_globals = require(`./build/${common.buildType}/test_globals`);
6+
7+
assert.strictEqual(test_globals.getUndefined(), undefined);
8+
assert.strictEqual(test_globals.getNull(), null);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <node_api.h>
2+
#include "../common.h"
3+
4+
napi_value getNull(napi_env env, napi_callback_info info) {
5+
napi_value result;
6+
NAPI_CALL(env, napi_get_null(env, &result));
7+
return result;
8+
}
9+
10+
napi_value getUndefined(napi_env env, napi_callback_info info) {
11+
napi_value result;
12+
NAPI_CALL(env, napi_get_undefined(env, &result));
13+
return result;
14+
}
15+
16+
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
17+
napi_property_descriptor descriptors[] = {
18+
DECLARE_NAPI_PROPERTY("getUndefined", getUndefined),
19+
DECLARE_NAPI_PROPERTY("getNull", getNull),
20+
};
21+
22+
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
23+
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
24+
}
25+
26+
NAPI_MODULE(addon, Init)

0 commit comments

Comments
 (0)