Skip to content

Commit

Permalink
Update: Use inspect symbol on node 11+ (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
BridgeAR authored and phated committed Jun 22, 2018
1 parent a1c2e82 commit 2e5d7af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions index.js
@@ -1,6 +1,7 @@
'use strict';

var path = require('path');
var util = require('util');
var isBuffer = require('buffer').Buffer.isBuffer;

var clone = require('clone');
Expand Down Expand Up @@ -157,6 +158,11 @@ File.prototype.inspect = function() {
return '<File ' + inspect.join(' ') + '>';
};

// Newer Node.js versions use this symbol for custom inspection.
if (util.inspect.custom) {
File.prototype[util.inspect.custom] = File.prototype.inspect;
}

File.isCustomProp = function(key) {
return builtInFields.indexOf(key) === -1;
};
Expand Down
8 changes: 7 additions & 1 deletion test/file.js
Expand Up @@ -2,6 +2,7 @@

var fs = require('fs');
var path = require('path');
var util = require('util');
var expect = require('expect');
var miss = require('mississippi');
var cloneable = require('cloneable-readable');
Expand Down Expand Up @@ -746,7 +747,12 @@ describe('File', function() {

it('returns correct format when no contents and no path', function(done) {
var file = new File();
expect(file.inspect()).toEqual('<File >');
var expectation = '<File >';
expect(file.inspect()).toEqual(expectation);
expect(util.inspect(file)).toEqual(expectation);
if (util.inspect.custom) {
expect(file[util.inspect.custom]()).toEqual(expectation);
}
done();
});

Expand Down

0 comments on commit 2e5d7af

Please sign in to comment.