Skip to content

Commit

Permalink
Issue #7424: test/README update with jest snapshot flow
Browse files Browse the repository at this point in the history
  • Loading branch information
keblodev committed May 29, 2018
1 parent 2f3e7d4 commit 5705713
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
20 changes: 16 additions & 4 deletions test/README.md
Expand Up @@ -46,11 +46,23 @@ In addition to an `index.js`, these configCases require a `webpack.config.js` is
#### statsCases (`StatsTestCases.test.js`)
Stats cases are similar to configCases except specifically focusing on the `expected` output of your stats. Instead of writing to the console, however the output of stats will be written to disk.

By default, the "expected" outcome is a pain to write by hand so instead when statsCases are run the following happens:
By default, the "expected" outcome is a pain to write by hand so instead when statsCases are run, runner is checking output using jest's awesome snapshot functionality.

* Checks for `expected.txt` file containing expected results.
* If the `expected.txt` doesn't match what is output, then an `actual.txt` stats output file will be created and the test will fail. (A typical workflow for stats cases is to fail the test and copy the results from `actual.txt` to `expected.txt`.)
* If the actual output matches `expected.txt`, the tests passes and you are free to submit that PR with pride!!!
Basically you don't need to write any expected behaviors your self. The assumption is that the stats output from your test code is what you expect.

Please follow the approach described bellow:

* write your test code in ```statsCases/``` folder by creating a separate folder for it, for example
```statsCases/some-file-import-stats/index.js```
```
import(./someModule);
```
** dont's forget the ```webpack.config.js```
* run the test
* jest will automatically add the output from your test code to ```StatsTestCases.test.js.snap``` and you can always check your results there
* Next time test will run -> runner will compare results against your output written to snapshot previously

You can read more about SnapShot testing [right here](https://facebook.github.io/jest/docs/en/snapshot-testing.html)

## Questions? Comments?
If you are still nervous or don't quite understand, please submit an issue and tag us in it, and provide a relevant PR while working on!
Expand Down
15 changes: 0 additions & 15 deletions test/statsCases/accept-stats.js

This file was deleted.

0 comments on commit 5705713

Please sign in to comment.