Description
Copied from #44429 (comment):
-
I guess that the made-up serialization format was supposed to be human readable, but it really does not seem appropriate for assertions. I don't expect it to be reliable in the presence of things such as
{ [util.inspect.custom]() { return '#*#*#*#*#*#*#*#*#*#*#*#'; } }
-
util.inspect()
potentially omits information, leading to false negatives:const a = new ArrayBuffer(101); const snapshot1 = util.inspect(a); new Uint8Array(a)[a.byteLength - 1] = 1; const snapshot2 = util.inspect(a); assert.strictEqual(snapshot1, snapshot2); // passes even though the inspected value changed!
-
util.inspect()
is affected byutil.inspect.defaultOptions
, which means that two snapshots of the same value can be different, leading to false positives. -
Looking at the change history for
util.inspect()
, it seems that the default options changed between versions. This would potentially also break existing.snapshot
files, leading to false positives. -
The documentation of
util.inspect()
literally says:The
util.inspect()
method returns a string representation of object that is intended for debugging. The output ofutil.inspect
may change at any time and should not be depended upon programmatically. -
Reading and potentially writing a file at some opinionated location during a call to an
assert
API seems very unusual to me, especially because it causes the API to become async. It also seems like this could easily lead to unexpected conflicts.This is particularly problematic when the main module is not the actual test file (e.g., when using
mocha
or other test runners). -
I understand its purpose, but the addition of a CLI option to "refresh" snapshots (during API calls within
assert
) seems unusual to me (but maybe that's common practice somewhere).
Because this is an experimental feature, we can still revert it or modify it to at least address some of these issues.