fc.assert displays failure log 2 times with mocha (even when changing the logger)
See original GitHub issueš Bug Report
When the assertion function throw, the output is displayed 2 times under mocha
To Reproduce
const fc = require('fast-check')
function throwSomething (smth) {
throw new Error(smth)
}
describe.only('test fast-check', function () {
it('displaying 2 times', function () {
fc.assert(
fc.property(
fc.integer(), num => throwSomething(num)
),
{ logger: function () { console.info('logger called') } }
)
})
it('displaying only 1 time', function () {
throwSomething('hello world')
})
})
Then run this file with mocha
The result will be
test fast-check
1) displaying 2 times
2) displaying only 1 time
0 passing (21ms)
2 failing
1) test fast-check
displaying 2 times:
Property failed after 1 tests
{ seed: 408091181, path: "0:0", endOnFailure: true }
Counterexample: [0]
Shrunk 1 time(s)
Got error: Error: 0
Stack trace: Error: 0
at throwSomething (/home/tmp/test.js:4:9)
at fc.assert.fc.property.num (/home/tmp/test.js:11:30)
at Property.predicate (/home/tmp/node_modules/fast-check/lib/check/property/Property.generated.js:15:105)
at Property.run (/home/tmp/node_modules/fast-check/lib/check/property/Property.generic.js:19:31)
at runIt (/home/tmp/node_modules/fast-check/lib/check/runner/Runner.js:19:32)
at check (/home/tmp/node_modules/fast-check/lib/check/runner/Runner.js:107:11)
at Object.assert (/home/tmp/node_modules/fast-check/lib/check/runner/Runner.js:111:15)
at Context.<anonymous> (/home/tmp/test.js:9:8)
at callFn (/home/tmp/node_modules/mocha/lib/runnable.js:387:21)
at Test.Runnable.run (/home/tmp/node_modules/mocha/lib/runnable.js:379:7)
at Runner.runTest (/home/tmp/node_modules/mocha/lib/runner.js:525:10)
at /home/tmp/node_modules/mocha/lib/runner.js:643:12
at next (/home/tmp/node_modules/mocha/lib/runner.js:437:14)
at /home/tmp/node_modules/mocha/lib/runner.js:447:7
at next (/home/tmp/node_modules/mocha/lib/runner.js:362:14)
at Immediate.<anonymous> (/home/tmp/node_modules/mocha/lib/runner.js:415:5)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
at processImmediate [as _immediateCallback] (timers.js:745:5)
Hint: Enable verbose mode in order to have the list of all failing values encountered during the run
Error: Property failed after 1 tests
{ seed: 408091181, path: "0:0", endOnFailure: true }
Counterexample: [0]
Shrunk 1 time(s)
Got error: Error: 0
Stack trace: Error: 0
at throwSomething (test.js:4:9)
at fc.assert.fc.property.num (test.js:11:30)
at Property.predicate (node_modules/fast-check/lib/check/property/Property.generated.js:15:105)
at Property.run (node_modules/fast-check/lib/check/property/Property.generic.js:19:31)
at runIt (node_modules/fast-check/lib/check/runner/Runner.js:19:32)
at check (node_modules/fast-check/lib/check/runner/Runner.js:107:11)
at Object.assert (node_modules/fast-check/lib/check/runner/Runner.js:111:15)
at Context.<anonymous> (test.js:9:8)
Hint: Enable verbose mode in order to have the list of all failing values encountered during the run
at Object.throwIfFailed (node_modules/fast-check/lib/check/runner/utils/RunDetailsFormatter.js:99:11)
at Object.assert (node_modules/fast-check/lib/check/runner/Runner.js:115:31)
at Context.<anonymous> (test.js:9:8)
2) test fast-check
displaying only 1 time:
Error: hello world
at throwSomething (test.js:4:9)
at Context.<anonymous> (test.js:18:5)
Expected behavior
There should be only 1 output, like for the 2nd. Also with Mocha, on the 2nd test, the Error
line is printed in red and the stack trace is in grey, but with fc.assert
one output is in red and the other is in grey.
I tried defining a logger but the function is not called.
A solution I tried is to put fc.assert
in a try catch block and then output with console.log but itās not a good way to do it and the output doesnāt get the mocha formatting, and same if I use fc.check
to output the result I wonāt have the mocha formatting.
Your environment
Packages / Softwares | Version(s) |
---|---|
fast-check | 1.16.0 |
node | v8.16.0 |
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Fail a Mocha test when logger.error is called - Stack Overflow
I want my tests to fail whenever there an error logged, and I do not want to repeat an expect clause for that...
Read more >fast-check - npm
Whenever fc.assert encounters a failure, it displays an error log featuring both the seed and the path to replay it. For instance, in...
Read more >Double Output with Mocha and Assert - Anti-pattern
The error message/diff is displayed twice Ā· One of the messages is weirdly outdented Ā· The ordering and color of āactualā and āexpectedā...
Read more >Best Practices - Cypress Documentation
Organizing Tests, Logging In, Controlling State; Selecting Elements; Assigning Return ... Changing the text to Save would then not cause a test failure....
Read more >TypeScript errors and how to fix them
Add an import, export, or an empty 'export {}' statement to make it a module. Broken Code ā. tsconfig.json. 1 2 3
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Iāve made a workaround
This will print the output below:
This way I can separate the stack trace and the error message.
I was thinking, it could be nice to have access to the error message and stack trace separately instead of having the field
error
containing everything, there could be a fielderrorMessage
and a fielderrorStack
containing the raw stack trace.And also there could be some kind of
formatter
orreporter
function in parameter forfc.assert
to format the output so we donāt have to callfc.check
and then call a function on the resultClosing this issue as the recent merge of https://github.com/dubzzz/fast-check/pull/2965 which makes āError with causeā something possible is probably the way to go. Not having to copy the original error within the message of the new one will probably drop many problems including this one. But so far, only one test framework really handle āError with causeā properly all others (including Mocha) only drop that part.
Feature will be part of 3.2.0.