ava icon indicating copy to clipboard operation
ava copied to clipboard

An option to disable enhanced assertion messages

Open szmarczak opened this issue 6 years ago • 14 comments

The object can have a property with data\n x 1000.

szmarczak avatar Nov 05 '19 17:11 szmarczak

https://pastebin.com/raw/3wg5nyab

szmarczak avatar Nov 05 '19 17:11 szmarczak

I think a better solution is some kind of smart limits for the formatted. Maybe check out how Jest formats such a thing.

sindresorhus avatar Nov 06 '19 06:11 sindresorhus

Friendly ping :)

szmarczak avatar Feb 24 '20 17:02 szmarczak

Which assertions are you seeing this with?

novemberborn avatar Feb 24 '20 20:02 novemberborn

deepEqual 100% and maybe is (don't remember but I think it would give that wall of text too).

szmarczak avatar Feb 24 '20 20:02 szmarczak

It'd be useful to know how each assertion behaves. I must admit I've forgotten by now.

novemberborn avatar Feb 25 '20 09:02 novemberborn

No worries :) I'll send a PR when I have more time.

szmarczak avatar Feb 25 '20 10:02 szmarczak

I'm still seeing this and this is extremely annoying.

test.only('blah blah blah', t => {
	const a = {};
	const b = {};

	for (let i = 0; i < 1000; i++) {
		a[i] = Math.random();
		b[i] = Math.random();
	}

	t.is(a, b); // t.deepEqual works too
});
test.only('blah blah blah 2', t => {
	let string = '';

	for (let i = 0; i < 2000; i++) {
		string += 'data\n';
	}

	const a = {
		string: ''
	};

	const b = {
		string
	};

	t.is(a, b); // t.deepEqual works too
});

szmarczak avatar Jul 09 '20 19:07 szmarczak

https://pastebin.com/raw/jWLk7NHR

szmarczak avatar Jul 09 '20 19:07 szmarczak

Yes that's a lot of output!

Specifically in your case a lot of what's being shown is enumerable internals, but it's not really AVA's place to decide not to show enumerable properties.

What would you prefer here? I suppose we could stop printing the diff after N lines? But that would depend on whether we've shown any difference yet. Maybe it's OK as long as there's some sort of option to override. One might say --verbose but that currently changes a lot of reporter behavior.

This seems related to https://github.com/concordancejs/concordance/issues/12.

novemberborn avatar Jul 12 '20 13:07 novemberborn

One solution would be to an add option to always truncate symbols like in the very end of the paste above:

...
  +   [Symbol(local-settings)]: Object { … },
...

The other solution is almost the same you've proposed. Instead of stopping printing, just truncate the main object like in the example above if it's diff exceeds N lines.

szmarczak avatar Jul 12 '20 15:07 szmarczak

This seems related to concordancejs/concordance#12.

It is, but in this example I don't care about the number of the properties. If it tells me that the exact 2 properties among the 1000 are different then I can easily perform debugging.

szmarczak avatar Jul 12 '20 15:07 szmarczak

Instead of stopping printing, just truncate the main object like in the example above if it's diff exceeds N lines.

If this would be very CPU expensive and/or very slow, we can go with the number of properties. In that case, there should be an option to limit the depth.

szmarczak avatar Jul 12 '20 15:07 szmarczak

I think https://github.com/concordancejs/concordance/issues/12 should "collapse" equal properties / items over a certain threshold.

Then in AVA, eventually, --verbose could undo that. But we could have some other flag or environment variable to disable the collapsing.

This really needs to be dealt with in Concordance first, though.

If this would be very CPU expensive and/or very slow, we can go with the number of properties. In that case, there should be an option to limit the depth.

Performance is less relevant for failing tests. Tests tend to pass.

novemberborn avatar Jul 12 '20 18:07 novemberborn