mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 12:04:25 +00:00

* Get rid of recursive `make` when building the node binary. An earlier commit makes GYP write out rules that we can use for proper dependency tracking. * Use module name 'binding' in addons.md and addons-napi/*/binding.gyp. This massively simplifies the logic for generating the build rules. * Check in auto-generated add-on tests from `doc/api/addons.md`. The files change rarely and generating them dynamically causes no end of race conditions and special-casing during the build. PR-URL: https://github.com/nodejs/node/pull/17407 Reviewed-By: Richard Lau <riclau@uk.ibm.com>
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../../common');
|
|
|
|
// This tests the promise-related n-api calls
|
|
|
|
const assert = require('assert');
|
|
const test_promise = require(`./build/${common.buildType}/binding`);
|
|
|
|
common.crashOnUnhandledRejection();
|
|
|
|
// A resolution
|
|
{
|
|
const expected_result = 42;
|
|
const promise = test_promise.createPromise();
|
|
promise.then(
|
|
common.mustCall(function(result) {
|
|
assert.strictEqual(result, expected_result);
|
|
}),
|
|
common.mustNotCall());
|
|
test_promise.concludeCurrentPromise(expected_result, true);
|
|
}
|
|
|
|
// A rejection
|
|
{
|
|
const expected_result = 'It\'s not you, it\'s me.';
|
|
const promise = test_promise.createPromise();
|
|
promise.then(
|
|
common.mustNotCall(),
|
|
common.mustCall(function(result) {
|
|
assert.strictEqual(result, expected_result);
|
|
}));
|
|
test_promise.concludeCurrentPromise(expected_result, false);
|
|
}
|
|
|
|
// Chaining
|
|
{
|
|
const expected_result = 'chained answer';
|
|
const promise = test_promise.createPromise();
|
|
promise.then(
|
|
common.mustCall(function(result) {
|
|
assert.strictEqual(result, expected_result);
|
|
}),
|
|
common.mustNotCall());
|
|
test_promise.concludeCurrentPromise(Promise.resolve('chained answer'), true);
|
|
}
|
|
|
|
assert.strictEqual(test_promise.isPromise(test_promise.createPromise()), true);
|
|
|
|
const rejectPromise = Promise.reject(-1);
|
|
const expected_reason = -1;
|
|
assert.strictEqual(test_promise.isPromise(rejectPromise), true);
|
|
rejectPromise.catch((reason) => {
|
|
assert.strictEqual(reason, expected_reason);
|
|
});
|
|
|
|
assert.strictEqual(test_promise.isPromise(2.4), false);
|
|
assert.strictEqual(test_promise.isPromise('I promise!'), false);
|
|
assert.strictEqual(test_promise.isPromise(undefined), false);
|
|
assert.strictEqual(test_promise.isPromise(null), false);
|
|
assert.strictEqual(test_promise.isPromise({}), false);
|