From 74ddde4c76b2934da1aa036281d351c19273d852 Mon Sep 17 00:00:00 2001 From: DavidCai Date: Mon, 23 Jan 2017 22:11:13 +0800 Subject: [PATCH] test: increase coverage of internal/util --- .../test-internal-util-assertCrypto.js | 12 ++++++++++++ ...est-internal-util-decorate-error-stack.js} | 19 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-internal-util-assertCrypto.js rename test/parallel/{test-util-decorate-error-stack.js => test-internal-util-decorate-error-stack.js} (70%) diff --git a/test/parallel/test-internal-util-assertCrypto.js b/test/parallel/test-internal-util-assertCrypto.js new file mode 100644 index 00000000000000..f3003a2fee04e9 --- /dev/null +++ b/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()); +} diff --git a/test/parallel/test-util-decorate-error-stack.js b/test/parallel/test-internal-util-decorate-error-stack.js similarity index 70% rename from test/parallel/test-util-decorate-error-stack.js rename to test/parallel/test-internal-util-decorate-error-stack.js index 5e4a2bd3b7842d..caf31cb2650f17 100644 --- a/test/parallel/test-util-decorate-error-stack.js +++ b/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);