Skip to content

Commit 53d9e18

Browse files
committed
[Tests] handle a broken error cause in node 16.9/16.10
1 parent 9dbe9ad commit 53d9e18

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

test/error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tap.test('failures', function (tt) {
2020
' expected: |-',
2121
' undefined',
2222
' actual: |-',
23-
' [Error: this is a message]',
23+
' ' + ('cause' in Error.prototype ? '{ [Error: this is a message] [cause]: undefined }' : '[Error: this is a message]'),
2424
' at: Test.<anonymous> ($TEST/error.js:$LINE:$COL)',
2525
' stack: |-',
2626
' Error: this is a message',

test/stackTrace.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ tap.test('preserves stack trace with newlines', function (tt) {
1414
var parser = stream.pipe(tapParser());
1515
var stackTrace = 'foo\n bar';
1616

17+
var inspected = 'cause' in Error.prototype ? '{ [Error: Preserve stack] [cause]: undefined }' : '[Error: Preserve stack]';
18+
1719
parser.once('assert', function (data) {
1820
delete data.diag.at;
1921
tt.deepEqual(data, {
@@ -24,7 +26,7 @@ tap.test('preserves stack trace with newlines', function (tt) {
2426
stack: stackTrace,
2527
operator: 'error',
2628
expected: 'undefined',
27-
actual: '[Error: Preserve stack]'
29+
actual: inspected
2830
}
2931
});
3032
});
@@ -41,7 +43,7 @@ tap.test('preserves stack trace with newlines', function (tt) {
4143
+ ' expected: |-\n'
4244
+ ' undefined\n'
4345
+ ' actual: |-\n'
44-
+ ' [Error: Preserve stack]\n'
46+
+ ' ' + inspected + '\n'
4547
+ ' stack: |-\n'
4648
+ ' foo\n'
4749
+ ' bar\n'
@@ -57,7 +59,7 @@ tap.test('preserves stack trace with newlines', function (tt) {
5759
stack: stackTrace,
5860
operator: 'error',
5961
expected: 'undefined',
60-
actual: '[Error: Preserve stack]'
62+
actual: inspected
6163
});
6264
}));
6365

test/throws.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var thrower = function () { throw messageGetterError; };
2626
tap.test('failures', function (tt) {
2727
tt.plan(1);
2828

29+
var maybeCause = 'cause' in Error.prototype ? '[cause]: undefined, ' : '';
30+
2931
var test = tape.createHarness();
3032
test.createStream().pipe(concat(function (body) {
3133
tt.same(stripFullStack(body.toString('utf8')), [
@@ -37,7 +39,7 @@ tap.test('failures', function (tt) {
3739
' expected: |-',
3840
' undefined',
3941
' actual: |-',
40-
' { [TypeError: ' + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }",
42+
' { [TypeError: ' + getNonFunctionMessage() + '] ' + maybeCause + "message: '" + getNonFunctionMessage() + "' }",
4143
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
4244
' stack: |-',
4345
String(' TypeError: ' + getNonFunctionMessage(undefined)),
@@ -51,7 +53,7 @@ tap.test('failures', function (tt) {
5153
' expected: |-',
5254
' undefined',
5355
' actual: |-',
54-
' { [TypeError: ' + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }",
56+
' { [TypeError: ' + getNonFunctionMessage(null) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(null) + "' }",
5557
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
5658
' stack: |-',
5759
String(' TypeError: ' + getNonFunctionMessage(null)),
@@ -65,7 +67,7 @@ tap.test('failures', function (tt) {
6567
' expected: |-',
6668
' undefined',
6769
' actual: |-',
68-
' { [TypeError: ' + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }",
70+
' { [TypeError: ' + getNonFunctionMessage(true) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(true) + "' }",
6971
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
7072
' stack: |-',
7173
String(' TypeError: ' + getNonFunctionMessage(true)),
@@ -79,7 +81,7 @@ tap.test('failures', function (tt) {
7981
' expected: |-',
8082
' undefined',
8183
' actual: |-',
82-
' { [TypeError: ' + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }",
84+
' { [TypeError: ' + getNonFunctionMessage(false) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(false) + "' }",
8385
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
8486
' stack: |-',
8587
String(' TypeError: ' + getNonFunctionMessage(false)),
@@ -93,7 +95,7 @@ tap.test('failures', function (tt) {
9395
' expected: |-',
9496
' undefined',
9597
' actual: |-',
96-
' { [TypeError: ' + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }",
98+
' { [TypeError: ' + getNonFunctionMessage('abc') + '] ' + maybeCause + "message: '" + getNonFunctionMessage('abc') + "' }",
9799
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
98100
' stack: |-',
99101
String(' TypeError: ' + getNonFunctionMessage('abc')),
@@ -107,7 +109,7 @@ tap.test('failures', function (tt) {
107109
' expected: |-',
108110
' undefined',
109111
' actual: |-',
110-
' { [TypeError: ' + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }",
112+
' { [TypeError: ' + getNonFunctionMessage(/a/g) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(/a/g) + "' }",
111113
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
112114
' stack: |-',
113115
String(' TypeError: ' + getNonFunctionMessage(/a/g)),
@@ -121,7 +123,7 @@ tap.test('failures', function (tt) {
121123
' expected: |-',
122124
' undefined',
123125
' actual: |-',
124-
' { [TypeError: ' + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }",
126+
' { [TypeError: ' + getNonFunctionMessage([]) + '] ' + maybeCause + "message: '" + getNonFunctionMessage([]) + "' }",
125127
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
126128
' stack: |-',
127129
String(' TypeError: ' + getNonFunctionMessage([])),
@@ -135,7 +137,7 @@ tap.test('failures', function (tt) {
135137
' expected: |-',
136138
' undefined',
137139
' actual: |-',
138-
' { [TypeError: ' + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }",
140+
' { [TypeError: ' + getNonFunctionMessage({}) + '] ' + maybeCause + "message: '" + getNonFunctionMessage({}) + "' }",
139141
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
140142
' stack: |-',
141143
String(' TypeError: ' + getNonFunctionMessage({})),
@@ -169,7 +171,7 @@ tap.test('failures', function (tt) {
169171
' expected: |-',
170172
' [Function: TypeError]',
171173
' actual: |-',
172-
' { [RangeError: actual!] ' + ('cause' in Error.prototype ? '[cause]: undefined, ' : '') + "message: 'actual!' }",
174+
' { [RangeError: actual!] ' + maybeCause + "message: 'actual!' }",
173175
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
174176
' stack: |-',
175177
' RangeError: actual!',

0 commit comments

Comments
 (0)