Skip to content

Commit 5705713

Browse files
committed
Issue webpack#7424: test/README update with jest snapshot flow
1 parent 2f3e7d4 commit 5705713

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

test/README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,23 @@ In addition to an `index.js`, these configCases require a `webpack.config.js` is
4646
#### statsCases (`StatsTestCases.test.js`)
4747
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.
4848

49-
By default, the "expected" outcome is a pain to write by hand so instead when statsCases are run the following happens:
49+
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.
5050

51-
* Checks for `expected.txt` file containing expected results.
52-
* 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`.)
53-
* If the actual output matches `expected.txt`, the tests passes and you are free to submit that PR with pride!!!
51+
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.
52+
53+
Please follow the approach described bellow:
54+
55+
* write your test code in ```statsCases/``` folder by creating a separate folder for it, for example
56+
```statsCases/some-file-import-stats/index.js```
57+
```
58+
import(./someModule);
59+
```
60+
** dont's forget the ```webpack.config.js```
61+
* run the test
62+
* jest will automatically add the output from your test code to ```StatsTestCases.test.js.snap``` and you can always check your results there
63+
* Next time test will run -> runner will compare results against your output written to snapshot previously
64+
65+
You can read more about SnapShot testing [right here](https://facebook.github.io/jest/docs/en/snapshot-testing.html)
5466

5567
## Questions? Comments?
5668
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!

test/statsCases/accept-stats.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)