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: stricter validation and more verbose output for some tests #18498

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions test/addons-napi/test_general/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,25 @@ let w = {};
test_general.wrap(w);
w = null;
global.gc();
assert.strictEqual(test_general.derefItemWasCalled(), true,
const derefItemWasCalled = test_general.derefItemWasCalled();
assert.strictEqual(derefItemWasCalled, true,
'deref_item() was called upon garbage collecting a ' +
'wrapped object');
'wrapped object. test_general.derefItemWasCalled() ' +
`returned ${derefItemWasCalled}`);


// Assert that wrapping twice fails.
const x = {};
test_general.wrap(x);
assert.throws(() => test_general.wrap(x), Error);
common.expectsError(() => test_general.wrap(x),
{ type: Error, message: 'Invalid argument' });

// Ensure that wrapping, removing the wrap, and then wrapping again works.
const y = {};
test_general.wrap(y);
test_general.removeWrap(y);
assert.doesNotThrow(() => test_general.wrap(y), Error,
'Wrapping twice succeeds if a remove_wrap()' +
' separates the instances');
// Wrapping twice succeeds if a remove_wrap() separates the instances
assert.doesNotThrow(() => test_general.wrap(y));

// Ensure that removing a wrap and garbage collecting does not fire the
// finalize callback.
Expand All @@ -87,8 +90,11 @@ test_general.testFinalizeWrap(z);
test_general.removeWrap(z);
z = null;
global.gc();
assert.strictEqual(test_general.finalizeWasCalled(), false,
'finalize callback was not called upon garbage collection');
const finalizeWasCalled = test_general.finalizeWasCalled();
assert.strictEqual(finalizeWasCalled, false,
'finalize callback was not called upon garbage collection' +
'test_general.finalizeWasCalled() ' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has awkward spacing (no space between line 1 & 2). Maybe better as:

Finalize callback was not called upon garbage collection. test_general.finalizeWasCalled() returned ${finalizeWasCalled}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apapirovski
Thanks for pointing this out. I added a space betwen the two lines

`returned ${finalizeWasCalled}`);

// test napi_adjust_external_memory
const adjustedValue = test_general.testAdjustExternalMemory();
Expand Down