Skip to content

Commit

Permalink
Fix test suite failure in node v14 due to util.inspect change with ci…
Browse files Browse the repository at this point in the history
…rcular refs

In nodejs/node#27685 (part of node v14), how
objects with circular references are stringified with `util.inspect` changed.
  • Loading branch information
trentm committed Jun 27, 2020
1 parent ab8e5c6 commit 4e33c84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions test/cycles.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Trent Mick. All rights reserved.
* Copyright 2020 Trent Mick.
*
* Make sure cycles are safe.
*/
Expand Down Expand Up @@ -27,7 +27,6 @@ outstr.end = function (c) {
this.emit('end');
};

// these are lacking a few fields that will probably never match
var expect =
[
{
Expand Down Expand Up @@ -67,24 +66,39 @@ var log = new Logger({
});

test('cycles', function (t) {
var rec;

outstr.on('end', function () {
output.forEach(function (o, i) {
// Drop variable parts for comparison.
delete o.hostname;
delete o.pid;
delete o.time;
// Hack object/dict comparison: JSONify.

// In change https://github.com/nodejs/node/pull/27685 (part of
// node v14), how objects with circular references are stringified
// with `util.inspect` changed.
if (Number(process.versions.node.split('.')[0]) >= 14) {
expect[i].msg = expect[i].msg.replace(
// JSSTYLED
/{ bang: 'boom', KABOOM: \[Circular\] }/,
'<ref *1> { bang: \'boom\', KABOOM: [Circular *1] }'
);
}

t.equal(JSON.stringify(o), JSON.stringify(expect[i]),
'log item ' + i + ' matches');
'log record ' + i + ' matches');
});
t.end();
});

var obj = { bang: 'boom' };
obj.KABOOM = obj;
obj.KABOOM = obj; // This creates a circular reference.

log.info('bango', obj);
log.info('kaboom', obj.KABOOM);
log.info(obj);

outstr.end();
t.ok('did not throw');
});
2 changes: 1 addition & 1 deletion test/log.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Trent Mick. All rights reserved.
* Copyright 2020 Trent Mick.
*
* Test the `log.trace(...)`, `log.debug(...)`, ..., `log.fatal(...)` API.
*/
Expand Down

0 comments on commit 4e33c84

Please sign in to comment.