power-assert icon indicating copy to clipboard operation
power-assert copied to clipboard

Using power-assert in jest prints the output twice

Open jmquigley opened this issue 8 years ago • 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

jmquigley avatar Aug 03 '17 16:08 jmquigley

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

twada avatar Aug 04 '17 02:08 twada

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

jmquigley avatar Aug 04 '17 17:08 jmquigley

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

twada avatar Aug 05 '17 07:08 twada

https://github.com/jmquigley/power-assert-jest-test

jmquigley avatar Aug 05 '17 21:08 jmquigley

@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 avatar Aug 10 '17 08:08 twada

@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.

twada avatar Aug 10 '17 14:08 twada