Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using power-assert in jest prints the output twice #93

Open
jmquigley opened this issue Aug 3, 2017 · 6 comments
Open

Using power-assert in jest prints the output twice #93

jmquigley opened this issue Aug 3, 2017 · 6 comments

Comments

@jmquigley
Copy link

jmquigley commented Aug 3, 2017

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
Copy link
Member

twada commented Aug 4, 2017

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

@jmquigley
Copy link
Author

jmquigley commented Aug 4, 2017

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

@twada
Copy link
Member

twada commented Aug 5, 2017

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

@jmquigley
Copy link
Author

@twada
Copy link
Member

twada commented Aug 10, 2017

@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
Copy link
Member

twada commented Aug 10, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants