Skip to content

Commit

Permalink
test: increase coverage of internal/util
Browse files Browse the repository at this point in the history
PR-URL: #10964
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
DavidCai1111 authored and evanlucas committed Jan 31, 2017
1 parent ccdc922 commit 65691d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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
'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);

0 comments on commit 65691d6

Please sign in to comment.