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

Fix race condition bug in test, and show assertion failure values #16037

Closed
wants to merge 4 commits into from
Closed
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
71 changes: 30 additions & 41 deletions test/addons-napi/test_promise/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,34 @@ const common = require('../../common');
const test_promise = require(`./build/${common.buildType}/test_promise`);
const assert = require('assert');

let expected_result, promise;

// A resolution
expected_result = 42;
promise = test_promise.createPromise();
promise.then(
common.mustCall(function(result) {
assert.strictEqual(result, expected_result,
'promise resolved as expected');
}),
common.mustNotCall());
test_promise.concludeCurrentPromise(expected_result, true);
{
const expected_result = 42;
const promise = test_promise.createPromise();
promise.then(
common.mustCall(function(result) {
assert.strictEqual(result, expected_result,
`promise resolved as expected, received ${result}`);
}),
common.mustNotCall());
test_promise.concludeCurrentPromise(expected_result, true);
}

// A rejection
expected_result = 'It\'s not you, it\'s me.';
promise = test_promise.createPromise();
promise.then(
common.mustNotCall(),
common.mustCall(function(result) {
assert.strictEqual(result, expected_result,
'promise rejected as expected');
}));
test_promise.concludeCurrentPromise(expected_result, false);
{
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,
`promise rejected as expected, received ${result}`);
}));
test_promise.concludeCurrentPromise(expected_result, false);
}

// Chaining
promise = test_promise.createPromise();
const promise = test_promise.createPromise();
promise.then(
common.mustCall(function(result) {
assert.strictEqual(result, 'chained answer',
Expand All @@ -38,23 +40,10 @@ promise.then(
common.mustNotCall());
test_promise.concludeCurrentPromise(Promise.resolve('chained answer'), true);

assert.strictEqual(test_promise.isPromise(promise), true,
'natively created promise is recognized as a promise');

assert.strictEqual(test_promise.isPromise(Promise.reject(-1)), true,
'Promise created with JS is recognized as a promise');

assert.strictEqual(test_promise.isPromise(2.4), false,
'Number is recognized as not a promise');

assert.strictEqual(test_promise.isPromise('I promise!'), false,
'String is recognized as not a promise');

assert.strictEqual(test_promise.isPromise(undefined), false,
'undefined is recognized as not a promise');

assert.strictEqual(test_promise.isPromise(null), false,
'null is recognized as not a promise');

assert.strictEqual(test_promise.isPromise({}), false,
'an object is recognized as not a promise');
assert.strictEqual(test_promise.isPromise(promise), true);
assert.strictEqual(test_promise.isPromise(Promise.reject(-1)), true);
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);