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: increase coverage of internal/util #10964

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
12 changes: 12 additions & 0 deletions test/parallel/test-internal-util-assertCrypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Flags: --expose-internals
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, this test won't actually increase test coverage reported at coverage.nodejs.org unless it is run with Node without crypto. And then, it would lose coverage on the else condition.

'use strict';
require('../common');
const assert = require('assert');
const util = require('internal/util');

if (!process.versions.openssl) {
assert.throws(() => util.assertCrypto(),
/^Node.js is not compiled with openssl crypto support$/);
} else {
assert.doesNotThrow(() => util.assertCrypto());
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
const common = require('../common');
const assert = require('assert');
const internalUtil = require('internal/util');
const binding = process.binding('util');
const spawnSync = require('child_process').spawnSync;
const path = require('path');

const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];

assert.doesNotThrow(function() {
internalUtil.decorateErrorStack();
internalUtil.decorateErrorStack(null);
Expand Down Expand Up @@ -53,6 +57,19 @@ checkStack(result.stderr);

// Verify that the stack is unchanged when there is no arrow message
err = new Error('foo');
const originalStack = err.stack;
let originalStack = err.stack;
internalUtil.decorateErrorStack(err);
assert.strictEqual(originalStack, err.stack);

// Verify that the arrow message is added to the start of the stack when it
// exists
const arrowMessage = 'arrow_message';
err = new Error('foo');
originalStack = err.stack;

internalUtil.setHiddenValue(err, kArrowMessagePrivateSymbolIndex, arrowMessage);
internalUtil.decorateErrorStack(err);

assert.strictEqual(err.stack, `${arrowMessage}${originalStack}`);
assert.strictEqual(internalUtil
.getHiddenValue(err, kDecoratedPrivateSymbolIndex), true);