nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
105.15k stars 28.49k forks source link

test_runner: full diff option #51902

Open malthe opened 4 months ago

malthe commented 4 months ago

What is the problem this feature will solve?

The constructor method for AssertionError currently uses hardcoded limits for showing expected vs actual output. For example, this is how the truncating logic is implemented for the case when the values are not equal:

if (res.length > 512) {
  res = `${StringPrototypeSlice(res, 0, 509)}...`;
}
if (other.length > 512) {
  other = `${StringPrototypeSlice(other, 0, 509)}...`;
}

These limits are not configurable and there are situations where it would be useful to be able to change or entirely remove the limits.

What is the feature you are proposing to solve the problem?

The Jest testing framework has an --expand option that lets you see a full diff which can be useful at times.

The Node CLI could have a similar flag which would remove the default limits, e.g. --assert-expand (which would target the assert library directly).

What alternatives have you considered?

This could be more related to the test runner, but the way it's currently set up, the truncating logic happens when an assertion error is created.

RedYetiDev commented 1 month ago

I'll take this on :-). Currently, I'm implementing this as --full-assert-diff, but the name can be changed.