Skip to content

Commit 65691d6

Browse files
DavidCai1111evanlucas
authored andcommitted
test: increase coverage of internal/util
PR-URL: #10964 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent ccdc922 commit 65691d6

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
const util = require('internal/util');
6+
7+
if (!process.versions.openssl) {
8+
assert.throws(() => util.assertCrypto(),
9+
/^Node.js is not compiled with openssl crypto support$/);
10+
} else {
11+
assert.doesNotThrow(() => util.assertCrypto());
12+
}

test/parallel/test-util-decorate-error-stack.js renamed to test/parallel/test-internal-util-decorate-error-stack.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
const common = require('../common');
44
const assert = require('assert');
55
const internalUtil = require('internal/util');
6+
const binding = process.binding('util');
67
const spawnSync = require('child_process').spawnSync;
78
const path = require('path');
89

10+
const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
11+
const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];
12+
913
assert.doesNotThrow(function() {
1014
internalUtil.decorateErrorStack();
1115
internalUtil.decorateErrorStack(null);
@@ -53,6 +57,19 @@ checkStack(result.stderr);
5357

5458
// Verify that the stack is unchanged when there is no arrow message
5559
err = new Error('foo');
56-
const originalStack = err.stack;
60+
let originalStack = err.stack;
5761
internalUtil.decorateErrorStack(err);
5862
assert.strictEqual(originalStack, err.stack);
63+
64+
// Verify that the arrow message is added to the start of the stack when it
65+
// exists
66+
const arrowMessage = 'arrow_message';
67+
err = new Error('foo');
68+
originalStack = err.stack;
69+
70+
internalUtil.setHiddenValue(err, kArrowMessagePrivateSymbolIndex, arrowMessage);
71+
internalUtil.decorateErrorStack(err);
72+
73+
assert.strictEqual(err.stack, `${arrowMessage}${originalStack}`);
74+
assert.strictEqual(internalUtil
75+
.getHiddenValue(err, kDecoratedPrivateSymbolIndex), true);

0 commit comments

Comments
 (0)