summaryrefslogtreecommitdiff
path: root/test/parallel/test-util-decorate-error-stack.js
blob: 24fee56df7b655edb79229f8cc8631b2033f5c29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 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);