From d57267afc2c761bca4cad99e81d99d895f0b7537 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 28 May 2018 20:36:29 +0200 Subject: [PATCH] Fix: update custom inspection to use a symbol Node.js 11 removed support for the `inspect` property on objects as custom inspect functions. Instead, this can be done by using the util.inspect.custom symbol that is used here instead. To keep it backwarts compatible the old function stays in place. --- index.js | 6 ++++++ test/file.js | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index beaba3b..d99094e 100644 --- a/index.js +++ b/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'); @@ -157,6 +158,11 @@ File.prototype.inspect = function() { return ''; }; +// 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; }; diff --git a/test/file.js b/test/file.js index c424bfd..5b09ecc 100644 --- a/test/file.js +++ b/test/file.js @@ -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'); @@ -746,7 +747,10 @@ describe('File', function() { it('returns correct format when no contents and no path', function(done) { var file = new File(); - expect(file.inspect()).toEqual(''); + var expectation = ''; + expect(file.inspect()).toEqual(expectation); + expect(file[util.inspect.custom]()).toEqual(expectation); + expect(util.inspect(file)).toEqual(expectation); done(); });