node/test/parallel/test-util-decorate-error-stack.js
Ben Noordhuis 04b1a2f756 util: move .decorateErrorStack to internal/util
Move the method that was added in commit 8ca412b from earlier this month
from lib/util.js to lib/internal/util.js.

Avoids exposing a method that we may not wish to expose just yet, seeing
how it relies on implementation details.

PR-URL: https://github.com/nodejs/node/pull/4026
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-11-30 23:58:32 +01:00

37 lines
987 B
JavaScript

// Flags: --expose_internals
'use strict';
const common = require('../common');
const assert = require('assert');
const internalUtil = require('internal/util');
assert.doesNotThrow(function() {
internalUtil.decorateErrorStack();
internalUtil.decorateErrorStack(null);
internalUtil.decorateErrorStack(1);
internalUtil.decorateErrorStack(true);
});
// Verify that a stack property is not added to non-Errors
const obj = {};
internalUtil.decorateErrorStack(obj);
assert.strictEqual(obj.stack, undefined);
// Verify that the stack is decorated when possible
let err;
try {
require('../fixtures/syntax/bad_syntax');
} catch (e) {
err = e;
assert(!/var foo bar;/.test(err.stack));
internalUtil.decorateErrorStack(err);
}
assert(/var foo bar;/.test(err.stack));
// Verify that the stack is unchanged when there is no arrow message
err = new Error('foo');
const originalStack = err.stack;
internalUtil.decorateErrorStack(err);
assert.strictEqual(originalStack, err.stack);