Browse Source

test: increase coverage of internal/util

PR-URL: https://github.com/nodejs/node/pull/10964
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v7.x
DavidCai 8 years ago
committed by Evan Lucas
parent
commit
65691d68d5
  1. 12
      test/parallel/test-internal-util-assertCrypto.js
  2. 19
      test/parallel/test-internal-util-decorate-error-stack.js

12
test/parallel/test-internal-util-assertCrypto.js

@ -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());
}

19
test/parallel/test-util-decorate-error-stack.js → test/parallel/test-internal-util-decorate-error-stack.js

@ -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);
@ -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);
Loading…
Cancel
Save