-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Add fuzzing based tests in Jest #8012
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my eyes this looks great. Thank you so much for putting it together!
Could you show an example (screenshot) of how a failure looks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks @dubzzz! I found some errors in the comments. Please go over them to make sure they accurately describe what the test cases do so people unfamiliar with property-based testing do not get confused 😄
Thank you for bringing explicit property-based assertions to improve the quality of matchers. /cc @grosto your thoughts are welcome in this discussion I will let Simen and Tim brainstorm options (like seed and search depth) for CI versus local run. To learn
@dubzzz Your thoughts also welcome about tests for P.S. The effort to find broken edge cases in |
This sounds really interesting, @dubzzz seen something like that been done before? |
Forgot to say that |
@pedrottimark, @jeysal here are some of my answers:
✅ I am updating the review accordingly. Indeed it seems easier to write a regex for
✅ IMO it would be a great idea. Today the file gathering tests for matchers is quite huge. Splitting it into smaller entities would make it more readable and easier to find - just need to look for a file whose name is
It's important to see that sometimes, the property would not be as accurate as a real unit test. For instance, in the test Documentation of the feature: https://github.com/dubzzz/fast-check/blob/master/documentation/Tips.md#add-custom-examples-next-to-generated-ones. See the initial feature request: dubzzz/fast-check#141. ✅ I added
In my wrapper for ava [here], Choice A: peer dependency Users would need to explicitely install Choice B: dependency on 1.x.x Users would directly benefit from
I will have a look to this one to see how I would have tested it with property based. |
Side note (better discussed in the RFC), but if we include
Yeah, that should be fine. We'll have a semver range, so unless you release a new major it'll be within reach |
@pedrottimark If I understand well what is the purpose of I think we can adapt tests I did on
Full code: dubzzz/javascript-algorithms@67102e4 |
@SimenB I will try to open the RFC later this week to discuss those points ;) |
@pedrottimark @SimenB Let's discuss direct integration within Jest here: #8035 |
For the moment I will remove the property called
Meanwhile those properties are still a good starting point :) |
This mostly LGTM in its current form and I'm excited to see what other bugs we may find with further property tests for other matchers. |
@jeysal I just updated the review based on your last comment. I divided the spec into four distinct specs. Common settings have been moved into a file shared accross those files called |
Some checks failed, but I don't if they are related to the review. Can you help me? #!/bin/bash -eo pipefail
yarn test-ci
yarn run v1.13.0
$ yarn jest-coverage -i --config jest.config.ci.js && yarn test-leak && node scripts/mapCoverage.js && codecov
$ yarn jest --coverage -i --config jest.config.ci.js
$ node ./packages/jest-cli/bin/jest.js --coverage -i --config jest.config.ci.js
........(node:335) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added. Use emitter.setMaxListeners() to increase limit
......................................................................................................................................................................................................................................
● Test suite failed to run
Your test suite must contain at least one test.
at packages/jest-core/build/TestScheduler.js:221:24
..............................................................................
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I divided the spec into four distinct specs.
Great, thanks! The set issue is not close to being fixed, so I guess we can merge this now and enable the Set tests / add further tests later.
@thymikee @pedrottimark Do you approve the review on your side too? |
packages/expect/src/__tests__/matchers-toStrictEqual.property.test.ts
Outdated
Show resolved
Hide resolved
packages/expect/src/__tests__/matchers-toContain.property.test.ts
Outdated
Show resolved
Hide resolved
@dubzzz I apologize for delay to finish the review. I will look with fresh eyes tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Just rebased all the commits due to a conflict in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for building a beautiful foundation! Now we know who will test the testers :)
We can clean up existing tests while moving them into new files as examples, when possible.
Thank you so much @dubzzz! |
Hmm, I merged this thinking the CI failure was transient. But it failed twice on master with the same error as well. @dubzzz mind checking out why the node process aborts using circus? To run with circus locally, do |
@SimenB Please revert for the moment :'(, if it breaks your CI. I will spend some time to investigate the issue next week (I'll not be able to make it today) |
What's strange is that it passed before my rebase. Like you I thought it was just transient :/ Last week, I started to investigate whether it can be related to the size of the instances generated by I'll re-run the circus test suite locally to have a better understanding of what is going wrong. Sorry for the inconvenience :( |
No worries! If it hadn't been for the fact we're gonna be working on this quite a lot the coming week there'd have been no rush. So just fix it whenever you find the time! |
This reverts commit 609932e.
@SimenB I do not reproduce the crash on my machine. Did you reproduce it locally? Investigation On my side I started to investigate what could have led The issue seems to come from the fact, that
In addition to the generated object, fast-check provides a shrinker. The shrinker will be used internally in case of failure to reduce an object to a smaller one (easier to debug). Unfortunately it takes lots of memory for large In order to confirm my say and reduce the memory footprint of Next Maybe the best choice to check if my coming soon fix works properly will be to open a new PR to try it against the CI. We can confirm its stability by relaunching the CI multiple times on the next PR if needed. Still confirming the explanation above on my side |
I was unable to reproduce this locally as well... Opening up a PR seems reasonable to me! |
* upstream/master: (391 commits) more precise circus asyncError types (jestjs#8150) Add typeahead watch plugin (jestjs#6449) fix: getTimerCount not taking immediates and ticks into account (jestjs#8139) website: add an additional filter predicate to backers (jestjs#7286) [🔥] Revised README (jestjs#8076) [jest-each] Fix test function type (jestjs#8145) chore: improve bug template labels for easier maintenance (jestjs#8141) Add documentation related to auto-mocking (jestjs#8099) Add support for bigint to pretty-format (jestjs#8138) Revert "Add fuzzing based tests in Jest (jestjs#8012)" chore: remove console.log chore: Improve description of optional arguments in ExpectAPI.md (jestjs#8126) Add fuzzing based tests in Jest (jestjs#8012) Move @types/node to the root package.json (jestjs#8129) chore: use property initializer syntax (jestjs#8117) chore: delete flow types from the repo (jestjs#8061) Move changelog entry to the proper version (jestjs#8115) Release 24.5.0 Expose throwOnModuleCollision (jestjs#8113) add matchers to expect type (jestjs#8093) ...
This reverts commit 13b4412.
@SimenB Let's retry with PR #8164 Before merging it, we should definitely confirm we will not encounter the out-of-memory issue with it. The fix: I basically decreased the size of the generated instances (and also the memory consumed to store the shrinker). Instances go from 10 (this PR) to 5 (the new PR) keys per object with a maximal depth of 2 (already the case before). When I tested it manually, it reduced by a factor of 2-3 the size required to store value+shrinker in memory. |
This reverts commit 13b4412.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Following discussions with @jeysal and @SimenB in the PR #7938, I open a PR to add property based tests into the CI of Jest.
In a nutshell what it property based testing:
Property based can be classified as being some kind of fuzzing technic. The need for such technic comes from the fact that it is difficult and barely impossible to cover all the edge cases a code can have with classical unit-tests (so called example based tests).
Property based framework relies on assessing whether a property stays true for any valid inputs. It can be summarized by the following mathematical statement:
In case of failure, it is able to reduce the randomly generated
x
,y
to smaller entries to be more human readable.@SimenB I will try to work on the RFC next week