Skip to content

Commit

Permalink
Remove util.inspect.custom API
Browse files Browse the repository at this point in the history
  • Loading branch information
Dayzen committed Dec 14, 2019
1 parent d5a0e73 commit 25793dd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
5 changes: 1 addition & 4 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
var tty = require('tty');
var diff = require('diff');
var milliseconds = require('ms');
var util = require('util');
var utils = require('../utils');
var supportsColor = process.browser ? null : require('supports-color');
var constants = require('../runner').constants;
Expand Down Expand Up @@ -220,9 +219,7 @@ exports.list = function(failures) {
err = test.err;
}
var message;
if (typeof err[util.inspect.custom] === 'function') {
message = util.inspect(err) + '';
} else if (typeof err.inspect === 'function') {
if (typeof err.inspect === 'function') {
message = err.inspect() + '';
} else if (err.message && typeof err.message.toString === 'function') {
message = err.message + '';
Expand Down
20 changes: 2 additions & 18 deletions test/reporters/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var assert = require('assert');
var chai = require('chai');
var util = require('util');
var sinon = require('sinon');
var helpers = require('./helpers');
var reporters = require('../../').reporters;
Expand Down Expand Up @@ -377,22 +376,7 @@ describe('Base reporter', function() {
expect(errOut, 'to be', '1) test title:\n Error\n foo\n bar');
});

it("should use 'util.inspect.custom' if err is including util.inspect.custom parameter", function() {
var err = new Error('test');
err.showDiff = false;
err[util.inspect.custom] = function() {
return 'Custom Formatted Error';
};

var test = makeTest(err);

list([test]);

var errOut = stdout.join('\n').trim();
expect(errOut, 'to contain', 'Custom Formatted Error');
});

it("should use 'inspect' if 'util.inspect.custom' is not set", function() {
it("should use 'inspect' if err include 'inspect' parameter", function() {
var err = new Error('test');
err.showDiff = false;
err.inspect = function() {
Expand All @@ -408,7 +392,7 @@ describe('Base reporter', function() {
expect(errOut, 'to contain', 'Inspect Error');
});

it("should set an empty message if 'util.inspect.custom' and 'inspect' and 'message' is not set", function() {
it("should set an empty message if neither 'inspect' nor 'message' is set", function() {
var err = {
showDiff: false
};
Expand Down

0 comments on commit 25793dd

Please sign in to comment.