@putout/plugin-tape 21.6.0 → 21.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ npm i @putout/plugin-tape -D
|
|
|
50
50
|
- ✅ [remove-useless-undefined](#remove-useless-undefined);
|
|
51
51
|
- ✅ [switch-expected-with-result](#switch-expected-with-result);
|
|
52
52
|
- ✅ [sync-with-name](#sync-with-name);
|
|
53
|
+
- ✅ [move-out-result-from-assertion](#move-out-result-from-assertion);
|
|
53
54
|
|
|
54
55
|
## Config
|
|
55
56
|
|
|
@@ -90,7 +91,8 @@ npm i @putout/plugin-tape -D
|
|
|
90
91
|
}],
|
|
91
92
|
"tape/remove-skip": ["on", {
|
|
92
93
|
"allowed": ["test"]
|
|
93
|
-
}]
|
|
94
|
+
}],
|
|
95
|
+
"tape/move-out-result-from-assertion": "on"
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
```
|
|
@@ -418,7 +420,7 @@ cleanup();
|
|
|
418
420
|
|
|
419
421
|
t.equal(result, expected);
|
|
420
422
|
t.end();
|
|
421
|
-
|
|
423
|
+
```
|
|
422
424
|
|
|
423
425
|
## apply-destructuring
|
|
424
426
|
|
|
@@ -819,6 +821,39 @@ test('some test', (t) => {
|
|
|
819
821
|
});
|
|
820
822
|
```
|
|
821
823
|
|
|
824
|
+
## move-out-result-from-assertion
|
|
825
|
+
|
|
826
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/264bc87f56eae9aa2b2884ff64fe7a06/94836a115a072a18fd717d5454792c1895ab0476).
|
|
827
|
+
|
|
828
|
+
### ❌ Example of incorrect code
|
|
829
|
+
|
|
830
|
+
```js
|
|
831
|
+
t.notOk(screen.getByRole('button').disabled);
|
|
832
|
+
|
|
833
|
+
t.deepEqual(readState({
|
|
834
|
+
getItem,
|
|
835
|
+
}), {
|
|
836
|
+
a: 1,
|
|
837
|
+
});
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
### ✅ Example of correct code
|
|
841
|
+
|
|
842
|
+
```js
|
|
843
|
+
const {disabled} = screen.getByRole('button');
|
|
844
|
+
t.notOk(disabled);
|
|
845
|
+
|
|
846
|
+
const result = readState({
|
|
847
|
+
getItem,
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
const expected = {
|
|
851
|
+
a: 1,
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
t.deepEqual(result, expected);
|
|
855
|
+
```
|
|
856
|
+
|
|
822
857
|
## License
|
|
823
858
|
|
|
824
859
|
MIT
|
|
@@ -28,11 +28,15 @@ export const fix = ({prev, prevPrev}) => {
|
|
|
28
28
|
export const traverse = ({push}) => ({
|
|
29
29
|
't.end()': (path) => {
|
|
30
30
|
const prev = path.parentPath.getPrevSibling();
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
if (!prev.node)
|
|
33
|
+
return;
|
|
32
34
|
|
|
33
35
|
if (compare(prev, 't.__a(__args)'))
|
|
34
36
|
return;
|
|
35
37
|
|
|
38
|
+
const prevPrev = prev.getPrevSibling();
|
|
39
|
+
|
|
36
40
|
push({
|
|
37
41
|
path,
|
|
38
42
|
prev,
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as movOutResultFromAssertion from './move-out-result-from-assertion/index.js';
|
|
1
2
|
import * as applyAssertionsOrder from './apply-assertions-order/index.js';
|
|
2
3
|
import * as removeUselessUndefined from './remove-useless-undefined/index.js';
|
|
3
4
|
import * as extractArgsFromCalledWith from './extract-args-from-called-with/index.js';
|
|
@@ -68,4 +69,5 @@ export const rules = {
|
|
|
68
69
|
'extract-args-from-called-with': extractArgsFromCalledWith,
|
|
69
70
|
'remove-useless-undefined': removeUselessUndefined,
|
|
70
71
|
'apply-assertions-order': applyAssertionsOrder,
|
|
72
|
+
'move-out-result-from-assertion': movOutResultFromAssertion,
|
|
71
73
|
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {getBinding} = operator;
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
isIdentifier,
|
|
7
|
+
isMemberExpression,
|
|
8
|
+
isOptionalMemberExpression,
|
|
9
|
+
isObjectExpression,
|
|
10
|
+
} = types;
|
|
11
|
+
|
|
12
|
+
export const report = () => `Move out result from assertion`;
|
|
13
|
+
export const match = () => ({
|
|
14
|
+
't.__a(__b, __c)': ({__a, __b, __c}, path) => {
|
|
15
|
+
if (!/equal/i.test(__a.name))
|
|
16
|
+
return false;
|
|
17
|
+
|
|
18
|
+
if (isMemberExpression(__b) && __b.property.name === 'callCount')
|
|
19
|
+
return false;
|
|
20
|
+
|
|
21
|
+
if (isMemberExpression(__b))
|
|
22
|
+
return false;
|
|
23
|
+
|
|
24
|
+
if (isOptionalMemberExpression(__b))
|
|
25
|
+
return false;
|
|
26
|
+
|
|
27
|
+
const resultBinding = getBinding(path, 'result');
|
|
28
|
+
const expectedBinding = getBinding(path, 'expected');
|
|
29
|
+
|
|
30
|
+
if (resultBinding && expectedBinding)
|
|
31
|
+
return false;
|
|
32
|
+
|
|
33
|
+
if (!resultBinding && !isIdentifier(__b))
|
|
34
|
+
return true;
|
|
35
|
+
|
|
36
|
+
if (expectedBinding)
|
|
37
|
+
return false;
|
|
38
|
+
|
|
39
|
+
return isObjectExpression(__c);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const replace = () => ({
|
|
44
|
+
't.__(__a.__b(__args).__c)': `{
|
|
45
|
+
const {__c} = __a.__b(__args);
|
|
46
|
+
t.__(__c);
|
|
47
|
+
}`,
|
|
48
|
+
't.__(__a(__b))': `{
|
|
49
|
+
const result = __a(__b);
|
|
50
|
+
t.__(result);
|
|
51
|
+
}`,
|
|
52
|
+
't.__a(__b, __c)': ({__b, __c}, path) => {
|
|
53
|
+
const resultBinding = getBinding(path, 'result');
|
|
54
|
+
const expectedBinding = getBinding(path, 'expected');
|
|
55
|
+
|
|
56
|
+
if (!resultBinding && !expectedBinding)
|
|
57
|
+
return `{
|
|
58
|
+
const result = __b;
|
|
59
|
+
const expected= __c;
|
|
60
|
+
|
|
61
|
+
t.__a(result, expected);
|
|
62
|
+
}`;
|
|
63
|
+
|
|
64
|
+
if (!expectedBinding && !isIdentifier(__c))
|
|
65
|
+
return `{
|
|
66
|
+
const expected = __c;
|
|
67
|
+
|
|
68
|
+
t.__a(__b, expected);
|
|
69
|
+
}`;
|
|
70
|
+
|
|
71
|
+
if (!resultBinding && !isIdentifier(__b))
|
|
72
|
+
return `{
|
|
73
|
+
const result = __b;
|
|
74
|
+
|
|
75
|
+
t.__a(result, __c);
|
|
76
|
+
}`;
|
|
77
|
+
},
|
|
78
|
+
});
|