Skip to content

Commit fb73070

Browse files
mhdawsonjasnell
authored andcommitted
test: consolidate n-api test addons - part2
It takes time to build each of the addons used to test n-api. Consolidate a few of the smaller ones to save build time. Get rid of one more small addon. PR-URL: #13380 Reviewed-By: Jason Ginchereau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent b8e90dd commit fb73070

File tree

4 files changed

+34
-54
lines changed

4 files changed

+34
-54
lines changed

test/addons-napi/test_napi_status/test.js test/addons-napi/test_general/testNapiStatus.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const addon = require(`./build/${common.buildType}/test_napi_status`);
4+
const addon = require(`./build/${common.buildType}/test_general`);
55
const assert = require('assert');
66

77
addon.createNapiError();

test/addons-napi/test_general/test_general.c

+33
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,37 @@ napi_value getUndefined(napi_env env, napi_callback_info info) {
5959
return result;
6060
}
6161

62+
napi_value createNapiError(napi_env env, napi_callback_info info) {
63+
napi_value value;
64+
NAPI_CALL(env, napi_create_string_utf8(env, "xyz", 3, &value));
65+
66+
double double_value;
67+
napi_status status = napi_get_value_double(env, value, &double_value);
68+
69+
NAPI_ASSERT(env, status != napi_ok, "Failed to produce error condition");
70+
71+
const napi_extended_error_info *error_info = 0;
72+
NAPI_CALL(env, napi_get_last_error_info(env, &error_info));
73+
74+
NAPI_ASSERT(env, error_info->error_code == status,
75+
"Last error info code should match last status");
76+
NAPI_ASSERT(env, error_info->error_message,
77+
"Last error info message should not be null");
78+
79+
return NULL;
80+
}
81+
82+
napi_value testNapiErrorCleanup(napi_env env, napi_callback_info info) {
83+
const napi_extended_error_info *error_info = 0;
84+
NAPI_CALL(env, napi_get_last_error_info(env, &error_info));
85+
86+
napi_value result;
87+
bool is_ok = error_info->error_code == napi_ok;
88+
NAPI_CALL(env, napi_get_boolean(env, is_ok, &result));
89+
90+
return result;
91+
}
92+
6293
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
6394
napi_property_descriptor descriptors[] = {
6495
DECLARE_NAPI_PROPERTY("testStrictEquals", testStrictEquals),
@@ -67,6 +98,8 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
6798
DECLARE_NAPI_PROPERTY("doInstanceOf", doInstanceOf),
6899
DECLARE_NAPI_PROPERTY("getUndefined", getUndefined),
69100
DECLARE_NAPI_PROPERTY("getNull", getNull),
101+
DECLARE_NAPI_PROPERTY("createNapiError", createNapiError),
102+
DECLARE_NAPI_PROPERTY("testNapiErrorCleanup", testNapiErrorCleanup),
70103
};
71104

72105
NAPI_CALL_RETURN_VOID(env, napi_define_properties(

test/addons-napi/test_napi_status/binding.gyp

-8
This file was deleted.

test/addons-napi/test_napi_status/test_napi_status.cc

-45
This file was deleted.

0 commit comments

Comments
 (0)