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: consolidate n-api test addons - part2 #13380

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const common = require('../../common');
const addon = require(`./build/${common.buildType}/test_napi_status`);
const addon = require(`./build/${common.buildType}/test_general`);
const assert = require('assert');

addon.createNapiError();
Expand Down
33 changes: 33 additions & 0 deletions test/addons-napi/test_general/test_general.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,37 @@ napi_value getUndefined(napi_env env, napi_callback_info info) {
return result;
}

napi_value createNapiError(napi_env env, napi_callback_info info) {
napi_value value;
NAPI_CALL(env, napi_create_string_utf8(env, "xyz", 3, &value));

double double_value;
napi_status status = napi_get_value_double(env, value, &double_value);

NAPI_ASSERT(env, status != napi_ok, "Failed to produce error condition");

const napi_extended_error_info *error_info = 0;
NAPI_CALL(env, napi_get_last_error_info(env, &error_info));

NAPI_ASSERT(env, error_info->error_code == status,
"Last error info code should match last status");
NAPI_ASSERT(env, error_info->error_message,
"Last error info message should not be null");

return NULL;
}

napi_value testNapiErrorCleanup(napi_env env, napi_callback_info info) {
const napi_extended_error_info *error_info = 0;
NAPI_CALL(env, napi_get_last_error_info(env, &error_info));

napi_value result;
bool is_ok = error_info->error_code == napi_ok;
NAPI_CALL(env, napi_get_boolean(env, is_ok, &result));

return result;
}

void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("testStrictEquals", testStrictEquals),
Expand All @@ -67,6 +98,8 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_PROPERTY("doInstanceOf", doInstanceOf),
DECLARE_NAPI_PROPERTY("getUndefined", getUndefined),
DECLARE_NAPI_PROPERTY("getNull", getNull),
DECLARE_NAPI_PROPERTY("createNapiError", createNapiError),
DECLARE_NAPI_PROPERTY("testNapiErrorCleanup", testNapiErrorCleanup),
};

NAPI_CALL_RETURN_VOID(env, napi_define_properties(
Expand Down
8 changes: 0 additions & 8 deletions test/addons-napi/test_napi_status/binding.gyp

This file was deleted.

45 changes: 0 additions & 45 deletions test/addons-napi/test_napi_status/test_napi_status.cc

This file was deleted.