Skip to content

Commit

Permalink
used more primordials
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkit-30 committed Feb 13, 2023
1 parent f0e5658 commit dbd4563
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 33 deletions.
12 changes: 7 additions & 5 deletions lib/internal/test_runner/reporter/tap.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
'use strict';
const {
ArrayPrototypeFilter,
ArrayPrototypeForEach,
ArrayPrototypeJoin,
ArrayPrototypePush,
ArrayPrototypeSlice,
NumberPrototypeToFixed,
ObjectEntries,
RegExpPrototypeSymbolReplace,
SafeMap,
StringPrototypeRepeat,
StringPrototypeReplaceAll,
StringPrototypeSplit,
StringPrototypeRepeat,
StringPrototypeStartsWith
} = primordials;
const { inspectWithNoCustomRetry } = require('internal/errors');
const { isError, kEmptyObject } = require('internal/util');
const { relative } = require('path');
const util = require('util');
const { inspect } = require('internal/util/inspect');
const kDefaultIndent = ' '; // 4 spaces
const kFrameStartRegExp = /^ {4}at /;
const kLineBreakRegExp = /\n|\r\n/;
Expand Down Expand Up @@ -239,9 +241,9 @@ function jsToYaml(indent, name, value) {
const frames = [];

if (cause?.cause) {
const errCause = util.inspect(cause).split('\n').slice(1)
.filter((line) => !StringPrototypeStartsWith(line.trim(), '...') && line)
.join('\n');
const errCause = ArrayPrototypeJoin(
ArrayPrototypeFilter(ArrayPrototypeSlice(StringPrototypeSplit(inspect(cause), '\n'), 1), (line) =>
line && typeof line === 'string' && !StringPrototypeStartsWith(line.trim(), '...')), '\n');
ArrayPrototypeForEach(
StringPrototypeSplit(errCause, kLineBreakRegExp),
(frame) => {
Expand Down
8 changes: 5 additions & 3 deletions test/message/test_runner_output.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,16 @@ test('unfinished test with unhandledRejection', async () => {
});

test('should print error cause', () => {
throw new Error('foo', {cause: new Error('bar')});
Error.stackTraceLimit = 4;
throw new Error('foo', { cause: new Error('bar') });
});

test('should print error cause for nested errors', () => {
throw new Error('a', { cause: new Error('b', { cause: new Error('c', { cause: new Error('d', { cause: new Error('e') }) }) }) })
throw new Error('a', { cause: new Error('b', { cause:
new Error('c', { cause: new Error('d', { cause: new Error('e') }) }) }) });
});

test("should handle cycles in error", () => {
test('should handle cycles in error', () => {
const outer = new Error('b', { cause: null });
outer.cause = new Error('c', { cause: new Error('d', { cause: outer }) });
throw outer;
Expand Down
9 changes: 6 additions & 3 deletions test/message/test_runner_output.out
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,6 @@ not ok 65 - should print error cause
*
*
*
*
*
*
...
# Subtest: should print error cause for nested errors
not ok 66 - should print error cause for nested errors
Expand All @@ -669,6 +666,9 @@ not ok 66 - should print error cause for nested errors
*
*
*
*
*
*
...
# Subtest: should handle cycles in error
not ok 67 - should handle cycles in error
Expand All @@ -693,6 +693,9 @@ not ok 67 - should handle cycles in error
*
*
*
*
*
*
...
# Subtest: invalid subtest fail
not ok 68 - invalid subtest fail
Expand Down
39 changes: 21 additions & 18 deletions test/message/test_runner_output_cli.out
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,6 @@ TAP version 13
*
*
*
*
*
*
...
# Subtest: should print error cause for nested errors
not ok 66 - should print error cause for nested errors
Expand All @@ -670,6 +667,9 @@ TAP version 13
*
*
*
*
*
*
...
# Subtest: should handle cycles in error
not ok 67 - should handle cycles in error
Expand All @@ -679,21 +679,24 @@ TAP version 13
error: 'b'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
...
# Subtest: invalid subtest fail
not ok 68 - invalid subtest fail
Expand Down
4 changes: 0 additions & 4 deletions test/message/test_runner_output_spec_reporter.out
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,6 @@
*
*
*
*
*
*
*

should print error cause for nested errors (*ms)
Error: a
Expand Down

0 comments on commit dbd4563

Please sign in to comment.