@putout/plugin-tape 21.6.0 → 21.7.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,37 @@ test('some test', (t) => {
819
821
  });
820
822
  ```
821
823
 
824
+ ## move-out-result-from-assertion
825
+
826
+ ### ❌ Example of incorrect code
827
+
828
+ ```js
829
+ t.notOk(screen.getByRole('button').disabled);
830
+
831
+ t.deepEqual(readState({
832
+ getItem,
833
+ }), {
834
+ a: 1,
835
+ });
836
+ ```
837
+
838
+ ### ✅ Example of correct code
839
+
840
+ ```js
841
+ const {disabled} = screen.getByRole('button');
842
+ t.notOk(disabled);
843
+
844
+ const result = readState({
845
+ getItem,
846
+ });
847
+
848
+ const expected = {
849
+ a: 1,
850
+ };
851
+
852
+ t.deepEqual(result, expected);
853
+ ```
854
+
822
855
  ## License
823
856
 
824
857
  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
- const prevPrev = prev.getPrevSibling();
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,17 @@
1
+ export const report = () => `Move out result from asssertion`;
2
+
3
+ export const replace = () => ({
4
+ 't.__(__a.__b(__args).__c)': `{
5
+ const {__c} = __a.__b(__args);
6
+ t.__(__c);
7
+ }`,
8
+ 't.__(__a(__b), __c)': `{
9
+ const result = __a(__b);
10
+ const expected = __c;
11
+ t.__(result, expected);
12
+ }`,
13
+ 't.__(__a(__b))': `{
14
+ const result = __a(__b);
15
+ t.__(result);
16
+ }`,
17
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "21.6.0",
3
+ "version": "21.7.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with tests",