Skip to content

Commit dbd4563

Browse files
committed
used more primordials
1 parent f0e5658 commit dbd4563

File tree

5 files changed

+39
-33
lines changed

5 files changed

+39
-33
lines changed

lib/internal/test_runner/reporter/tap.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
'use strict';
22
const {
3+
ArrayPrototypeFilter,
34
ArrayPrototypeForEach,
45
ArrayPrototypeJoin,
56
ArrayPrototypePush,
7+
ArrayPrototypeSlice,
68
NumberPrototypeToFixed,
79
ObjectEntries,
810
RegExpPrototypeSymbolReplace,
911
SafeMap,
12+
StringPrototypeRepeat,
1013
StringPrototypeReplaceAll,
1114
StringPrototypeSplit,
12-
StringPrototypeRepeat,
1315
StringPrototypeStartsWith
1416
} = primordials;
1517
const { inspectWithNoCustomRetry } = require('internal/errors');
1618
const { isError, kEmptyObject } = require('internal/util');
1719
const { relative } = require('path');
18-
const util = require('util');
20+
const { inspect } = require('internal/util/inspect');
1921
const kDefaultIndent = ' '; // 4 spaces
2022
const kFrameStartRegExp = /^ {4}at /;
2123
const kLineBreakRegExp = /\n|\r\n/;
@@ -239,9 +241,9 @@ function jsToYaml(indent, name, value) {
239241
const frames = [];
240242

241243
if (cause?.cause) {
242-
const errCause = util.inspect(cause).split('\n').slice(1)
243-
.filter((line) => !StringPrototypeStartsWith(line.trim(), '...') && line)
244-
.join('\n');
244+
const errCause = ArrayPrototypeJoin(
245+
ArrayPrototypeFilter(ArrayPrototypeSlice(StringPrototypeSplit(inspect(cause), '\n'), 1), (line) =>
246+
line && typeof line === 'string' && !StringPrototypeStartsWith(line.trim(), '...')), '\n');
245247
ArrayPrototypeForEach(
246248
StringPrototypeSplit(errCause, kLineBreakRegExp),
247249
(frame) => {

test/message/test_runner_output.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,16 @@ test('unfinished test with unhandledRejection', async () => {
385385
});
386386

387387
test('should print error cause', () => {
388-
throw new Error('foo', {cause: new Error('bar')});
388+
Error.stackTraceLimit = 4;
389+
throw new Error('foo', { cause: new Error('bar') });
389390
});
390391

391392
test('should print error cause for nested errors', () => {
392-
throw new Error('a', { cause: new Error('b', { cause: new Error('c', { cause: new Error('d', { cause: new Error('e') }) }) }) })
393+
throw new Error('a', { cause: new Error('b', { cause:
394+
new Error('c', { cause: new Error('d', { cause: new Error('e') }) }) }) });
393395
});
394396

395-
test("should handle cycles in error", () => {
397+
test('should handle cycles in error', () => {
396398
const outer = new Error('b', { cause: null });
397399
outer.cause = new Error('c', { cause: new Error('d', { cause: outer }) });
398400
throw outer;

test/message/test_runner_output.out

+6-3
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,6 @@ not ok 65 - should print error cause
642642
*
643643
*
644644
*
645-
*
646-
*
647-
*
648645
...
649646
# Subtest: should print error cause for nested errors
650647
not ok 66 - should print error cause for nested errors
@@ -669,6 +666,9 @@ not ok 66 - should print error cause for nested errors
669666
*
670667
*
671668
*
669+
*
670+
*
671+
*
672672
...
673673
# Subtest: should handle cycles in error
674674
not ok 67 - should handle cycles in error
@@ -693,6 +693,9 @@ not ok 67 - should handle cycles in error
693693
*
694694
*
695695
*
696+
*
697+
*
698+
*
696699
...
697700
# Subtest: invalid subtest fail
698701
not ok 68 - invalid subtest fail

test/message/test_runner_output_cli.out

+21-18
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,6 @@ TAP version 13
643643
*
644644
*
645645
*
646-
*
647-
*
648-
*
649646
...
650647
# Subtest: should print error cause for nested errors
651648
not ok 66 - should print error cause for nested errors
@@ -670,6 +667,9 @@ TAP version 13
670667
*
671668
*
672669
*
670+
*
671+
*
672+
*
673673
...
674674
# Subtest: should handle cycles in error
675675
not ok 67 - should handle cycles in error
@@ -679,21 +679,24 @@ TAP version 13
679679
error: 'b'
680680
code: 'ERR_TEST_FAILURE'
681681
stack: |-
682-
*
683-
*
684-
*
685-
*
686-
*
687-
*
688-
*
689-
*
690-
*
691-
*
692-
*
693-
*
694-
*
695-
*
696-
*
682+
*
683+
*
684+
*
685+
*
686+
*
687+
*
688+
*
689+
*
690+
*
691+
*
692+
*
693+
*
694+
*
695+
*
696+
*
697+
*
698+
*
699+
*
697700
...
698701
# Subtest: invalid subtest fail
699702
not ok 68 - invalid subtest fail

test/message/test_runner_output_spec_reporter.out

-4
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,6 @@
274274
*
275275
*
276276
*
277-
*
278-
*
279-
*
280-
*
281277

282278
should print error cause for nested errors (*ms)
283279
Error: a

0 commit comments

Comments
 (0)