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
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,70 @@ No matter what `package` you are interested in, you always have 4 little friends
24
24
25
25
You can call them from each package with `npm run` and they will always come 🤙.
26
26
27
+
## 🤷 How to write tests?
28
+
29
+
🐊**Putout** is one of projects that have 100% code coverage, it helps a lot, since when code not covered with tests, you have two choices:
30
+
31
+
- ✅ cover with tests;
32
+
- ✅ remove;
33
+
34
+
That's it! Writing tests is very simple tasks since we have own framework based on 📼[`supertape`](https://github.com/coderaiser/supertape): [`@putout/test`](https://github.com/coderaiser/putout/tree/master/packages/test#putouttest-). We have also [`@putout/plugin-putout`](https://github.com/coderaiser/putout/tree/master/packages/plugin-putout#putoutplugin-putout-) with test-based rules, that help you write as little code as possible. So how adding tests looks like?
35
+
36
+
Let's suppose you want to add test for [`@putout/plugin-remove-unreachable-code`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-unreachable-code), you open [`test/remove-unreachable-code.js`](https://github.com/coderaiser/putout/blob/master/packages/plugin-remove-unreachable-code/test/remove-unreachable-code.js) and see a lot of lines that ends up with:
37
+
38
+
```js
39
+
test('plugin-remove-unreachable-code: no report: return-no-arg', (t) => {
40
+
t.noReport('return-no-arg');
41
+
t.end();
42
+
});
43
+
```
44
+
45
+
What you need to do is copy this 4 lines, so you have:
46
+
47
+
```diff
48
+
test('plugin-remove-unreachable-code: no report: return-no-arg', (t) => {
49
+
t.noReport('return-no-arg');
50
+
t.end();
51
+
});
52
+
53
+
+test('plugin-remove-unreachable-code: no report: return-no-arg', (t) => {
54
+
+ t.noReport('return-no-arg');
55
+
+ t.end();
56
+
+});
57
+
```
58
+
59
+
Then you add `fixture` named `fixture/return-with-some-of-your-case` (try to add name that mirrors the problem) and change argument of `noReport`:
60
+
61
+
```diff
62
+
test('plugin-remove-unreachable-code: no report: return-no-arg', (t) => {
63
+
t.noReport('return-no-arg');
64
+
t.end();
65
+
});
66
+
67
+
test('plugin-remove-unreachable-code: no report: return-no-arg', (t) => {
68
+
- t.noReport('return-no-arg');
69
+
+ t.noReport('return-with-some-of-your-case');
70
+
t.end();
71
+
});
72
+
```
73
+
74
+
Then you write in terminal:
75
+
76
+
```sh
77
+
$ cat > fixture/return-with-some-of-your-case.js
78
+
if (a) {
79
+
return'some of your case';
80
+
}
81
+
^c
82
+
$ UPDATE=1 npm run fix:lint && npm test
83
+
```
84
+
85
+
This command will fix testfor you and generate fixture. Most likely you will need two types of tests:
86
+
- ✅[`noReport()`](https://github.com/coderaiser/putout/tree/master/packages/test#noreportfilename) - when rule has false possitive;
87
+
- ✅[`transform()`](https://github.com/coderaiser/putout/tree/master/packages/test#transformfilename--output-plugins) - when new case added;
88
+
89
+
The command`UPDATE=1 npm run test` will generate `fixture`for you, so you need not to worry about it, also `@putout/plugin-putout` will fix test message and other things, so you can also warry not about it 😏. Always remember that all things should be simple and automated: 🐊**Putout** fixes everything, including itself.
90
+
27
91
## 🤷 How to check if my changes do not break anything?
28
92
29
93
When your made changes, added coverage and your package is ready for publishing 📦 , run: `npm run fresh`,
0 commit comments