You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every pull request that you submit to webpack (besides README and spelling corrections in comments) requires tests that are created.
3
4
4
5
But don't give up hope!!! Although our tests may appear complex and overwhelming, once you become familiar with the test suite and structure, adding and creating tests will be fun and beneficial as you work inside the codebase! ❤
5
6
6
7
## tl;dr
8
+
7
9
Run all tests (this automatically runs the setup):
10
+
8
11
```sh
9
12
yarn test
10
13
```
11
14
12
15
Run an individual suite:
16
+
13
17
```sh
14
18
yarn jest ConfigTestCases
15
19
```
16
20
17
21
Watch mode:
22
+
18
23
```sh
19
24
yarn jest --watch ConfigTestCases
20
25
```
21
26
22
27
See also: [Jest CLI docs](https://jestjs.io/docs/cli)
23
28
24
29
## Test suite overview
30
+
25
31
We use Jest for our tests. For more information on Jest you can visit their [homepage](https://jestjs.io/)!
26
32
27
33
### Class Tests
28
-
All test files can be found in *.test.js. There are many tests that simply test APIs of a specific class/file (such as `Compiler`, `Errors`, Integration, `Parser`, `RuleSet`, Validation).
34
+
35
+
All test files can be found in \*.test.js. There are many tests that simply test APIs of a specific class/file (such as `Compiler`, `Errors`, Integration, `Parser`, `RuleSet`, Validation).
29
36
If the feature you are contributing involves one of those classes, then best to start there to understand the structure.
30
37
31
38
### xCases
32
-
In addition to Class specific tests, there are also directories that end in "Cases". The suites for these cases also have corresponding *.test.js files.
39
+
40
+
In addition to Class specific tests, there are also directories that end in "Cases". The suites for these cases also have corresponding \*.test.js files.
33
41
34
42
#### cases (`TestCases.test.js`) <sup>1</sup>
43
+
35
44
Cases are a set of general purpose tests that will run against a variety of permutations of webpack configurations. When you are making a general purpose change that doesn't require you to have a special configuration, you would likely add your tests here. Inside of the `./test/cases` directory you will find tests are broken into thematic sub directories. Take a moment to explore the different options.
36
45
37
46
To add a new case, create a new directory inside of the top level test groups, and then add an `index.js` file (and any other supporting files).
38
47
39
48
By default this file will be the entry point for the test suite and you can add your `it()`'s there. This will also become bundled so that node env support happens as well.
If you are trying to solve a bug which is reproducible when x and y properties are used together in a config, then configCases is the place to be!!!!
43
53
44
54
In addition to an `index.js`, these configCases require a `webpack.config.js` is located inside of your test suite. This will run this specific config through `webpack` just as you were building individually. They will use the same loading/bundling technique of your `it()` tests, however you now have a more specific config use cases that you can write even before you start coding.
45
55
46
56
#### statsCases (`StatsTestCases.basictest.js`)
57
+
47
58
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.
48
59
49
60
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.
@@ -52,21 +63,23 @@ Basically you don't need to write any expected behaviors yourself. The assumptio
52
63
53
64
Please follow the approach described below:
54
65
55
-
* write your test code in `statsCases/` folder by creating a separate folder for it, for example `statsCases/some-file-import-stats/index.js`
66
+
- write your test code in `statsCases/` folder by creating a separate folder for it, for example `statsCases/some-file-import-stats/index.js`
56
67
57
68
```javascript
58
69
import("./someModule");
59
70
```
60
-
* don't 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
71
+
72
+
- don't forget the `webpack.config.js`
73
+
- run the test
74
+
- jest will automatically add the output from your test code to `StatsTestCases.test.js.snap` and you can always check your results there
75
+
- Next time test will run -> runner will compare results against your output written to snapshot previously
64
76
65
77
You can read more about SnapShot testing [right here](https://jestjs.io/docs/snapshot-testing)
66
78
67
79
## Questions? Comments?
68
-
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!
69
80
81
+
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!
70
82
71
83
## Footnotes
84
+
72
85
<sup>1</sup> webpack's parser supports the use of ES2015 features like arrow functions, harmony exports, etc. However as a library we follow Node.js' timeline for dropping older versions of node. Because of this we expect your tests on GitHub Actions to pass all the way back to NodeJS v10; Therefore if you would like specific tests that use these features to be ignored if they are not supported, then you should add a `test.filter.js` file. This allows you to import the syntax needed for that test, meanwhile ignoring it on node versions (during CI) that don't support it. webpack has a variety of helpful examples you can refer to if you are just starting out. See the `./helpers` folder to find a list of the versions.
0 commit comments