Skip to content

Commit

Permalink
[Tests] handle a broken error cause in node 16.9/16.10
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 24, 2022
1 parent 9dbe9ad commit 53d9e18
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion test/error.js
Expand Up @@ -20,7 +20,7 @@ tap.test('failures', function (tt) {
' expected: |-',
' undefined',
' actual: |-',
' [Error: this is a message]',
' ' + ('cause' in Error.prototype ? '{ [Error: this is a message] [cause]: undefined }' : '[Error: this is a message]'),
' at: Test.<anonymous> ($TEST/error.js:$LINE:$COL)',
' stack: |-',
' Error: this is a message',
Expand Down
8 changes: 5 additions & 3 deletions test/stackTrace.js
Expand Up @@ -14,6 +14,8 @@ tap.test('preserves stack trace with newlines', function (tt) {
var parser = stream.pipe(tapParser());
var stackTrace = 'foo\n bar';

var inspected = 'cause' in Error.prototype ? '{ [Error: Preserve stack] [cause]: undefined }' : '[Error: Preserve stack]';

parser.once('assert', function (data) {
delete data.diag.at;
tt.deepEqual(data, {
Expand All @@ -24,7 +26,7 @@ tap.test('preserves stack trace with newlines', function (tt) {
stack: stackTrace,
operator: 'error',
expected: 'undefined',
actual: '[Error: Preserve stack]'
actual: inspected
}
});
});
Expand All @@ -41,7 +43,7 @@ tap.test('preserves stack trace with newlines', function (tt) {
+ ' expected: |-\n'
+ ' undefined\n'
+ ' actual: |-\n'
+ ' [Error: Preserve stack]\n'
+ ' ' + inspected + '\n'
+ ' stack: |-\n'
+ ' foo\n'
+ ' bar\n'
Expand All @@ -57,7 +59,7 @@ tap.test('preserves stack trace with newlines', function (tt) {
stack: stackTrace,
operator: 'error',
expected: 'undefined',
actual: '[Error: Preserve stack]'
actual: inspected
});
}));

Expand Down
20 changes: 11 additions & 9 deletions test/throws.js
Expand Up @@ -26,6 +26,8 @@ var thrower = function () { throw messageGetterError; };
tap.test('failures', function (tt) {
tt.plan(1);

var maybeCause = 'cause' in Error.prototype ? '[cause]: undefined, ' : '';

var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
Expand All @@ -37,7 +39,7 @@ tap.test('failures', function (tt) {
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }",
' { [TypeError: ' + getNonFunctionMessage() + '] ' + maybeCause + "message: '" + getNonFunctionMessage() + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(undefined)),
Expand All @@ -51,7 +53,7 @@ tap.test('failures', function (tt) {
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }",
' { [TypeError: ' + getNonFunctionMessage(null) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(null) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(null)),
Expand All @@ -65,7 +67,7 @@ tap.test('failures', function (tt) {
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }",
' { [TypeError: ' + getNonFunctionMessage(true) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(true) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(true)),
Expand All @@ -79,7 +81,7 @@ tap.test('failures', function (tt) {
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }",
' { [TypeError: ' + getNonFunctionMessage(false) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(false) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(false)),
Expand All @@ -93,7 +95,7 @@ tap.test('failures', function (tt) {
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }",
' { [TypeError: ' + getNonFunctionMessage('abc') + '] ' + maybeCause + "message: '" + getNonFunctionMessage('abc') + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage('abc')),
Expand All @@ -107,7 +109,7 @@ tap.test('failures', function (tt) {
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }",
' { [TypeError: ' + getNonFunctionMessage(/a/g) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(/a/g) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(/a/g)),
Expand All @@ -121,7 +123,7 @@ tap.test('failures', function (tt) {
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }",
' { [TypeError: ' + getNonFunctionMessage([]) + '] ' + maybeCause + "message: '" + getNonFunctionMessage([]) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage([])),
Expand All @@ -135,7 +137,7 @@ tap.test('failures', function (tt) {
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }",
' { [TypeError: ' + getNonFunctionMessage({}) + '] ' + maybeCause + "message: '" + getNonFunctionMessage({}) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage({})),
Expand Down Expand Up @@ -169,7 +171,7 @@ tap.test('failures', function (tt) {
' expected: |-',
' [Function: TypeError]',
' actual: |-',
' { [RangeError: actual!] ' + ('cause' in Error.prototype ? '[cause]: undefined, ' : '') + "message: 'actual!' }",
' { [RangeError: actual!] ' + maybeCause + "message: 'actual!' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
' RangeError: actual!',
Expand Down

0 comments on commit 53d9e18

Please sign in to comment.