power-assert-js/power-assert

Using power-assert in jest prints the output twice

jmquigley opened this issue · 6 comments

power-assert

This is the test case demonstrating the issue above (contrived test to show duplicate output):

test('Test retrieval of TagList props object', () => {
	const props = getDefaultTagListProps();

	assert(props);
	expect(props).toMatchSnapshot();

	let x = 'abc';
	let y = 'zyz';

	assert(x === y);
});

jest: 20.0.4
babel: 6.24.1
babel-preset-power-assert: 1.0.0
power-assert: 1.4.4

twada commented

@jmquigley Thank you for reporting.
Seems that your link to image is broken.
Would you fix the link, or create small repository for reproduction?

I updated the image link. Didn't realize I could just drag/drop it instead of linking it.

twada commented

@jmquigley Thank you for updating image.
Would you create small reproduction repo?
I want to reproduce the case to investigate sooner.

twada commented

@jmquigley Thank you for creating repro case repository!

While I'm investigating the issue, I found that stack recreation introduced in #85 is the cause of showing same diagram twice. Reporter output from Node6 and Node8 differs.

In #85, I added power-assert diagram to err.stack too. Therefore AssertionError thrown by power-assert have same diagram in err.message and err.stack, since most reporters (e.g. Mocha) use err.message but vanilla Node8 uses err.stack for reporting.

It seems that Jest reports both err.message and err.stack so you saw the same diagram twice.

A possible solution here is to create custom reporter for Jest.
I'm going to create the one.

twada commented

@jmquigley As digging deeper, I've found some hints.

  • Jest does not use AssertionError#message but extract messages from Error#stack.
  • Something is wrong with message/stack extraction logic in Jest that cannot extract complicated stack from Node8 since Node8 has slightly changed Error message and stack format. Custom reporter doesn't work well since Jest doesn't handle stack properly. I'm going to file an issue if I can reproduce small case.
  • Jest + power-assert works well under Node6.