question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using power-assert in jest prints the output twice

See original GitHub issue
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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
twadacommented, 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.

0reactions
twadacommented, 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.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using power-assert in jest prints the output twice - - Bountysource
This is the test case demonstrating the issue above (contrived test to show duplicate output): test('Test retrieval of TagList props object', ...
Read more >
Why Groovy's power assert prints failure messages twice?
Using a method like the ok() below verifies this "theory" as well as giving a possible solution to the double message issue:
Read more >
Multiple assertions are fine in a unit test - Hacker News
I like to use Jest's toMatchObject to combine multiple assertions in a single assertion. If the assertion fails, the full object on both ......
Read more >
Power-assert: Power Assert in JavaScript - Morioh
is an implementation of "Power Assert" concept in JavaScript. provides descriptive assertion messages through standard assert interface. No API is the best API....
Read more >
ava - npm.io
Only works with test.cb() . t.log(...values). Log values contextually alongside the test result instead of immediately printing them ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found