@putout/plugin-tape 21.5.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
@@ -19,6 +19,7 @@ npm i @putout/plugin-tape -D
19
19
 
20
20
  - ✅ [add-args](#add-args);
21
21
  - ✅ [add-t-end](#add-t-end);
22
+ - ✅ [apply-assertions-order](#apply-assertions-order);
22
23
  - ✅ [apply-destructuring](#apply-destructuring);
23
24
  - ✅ [apply-stub](#apply-stub);
24
25
  - ✅ [apply-with-name](#apply-with-name);
@@ -49,6 +50,7 @@ npm i @putout/plugin-tape -D
49
50
  - ✅ [remove-useless-undefined](#remove-useless-undefined);
50
51
  - ✅ [switch-expected-with-result](#switch-expected-with-result);
51
52
  - ✅ [sync-with-name](#sync-with-name);
53
+ - ✅ [move-out-result-from-assertion](#move-out-result-from-assertion);
52
54
 
53
55
  ## Config
54
56
 
@@ -57,6 +59,7 @@ npm i @putout/plugin-tape -D
57
59
  "rules": {
58
60
  "tape/jest": "on",
59
61
  "tape/apply-stub": "on",
62
+ "tape/apply-assertions-order": "on",
60
63
  "tape/apply-destructuring": "on",
61
64
  "tape/apply-with-name": "on",
62
65
  "tape/add-t-end": "on",
@@ -88,7 +91,8 @@ npm i @putout/plugin-tape -D
88
91
  }],
89
92
  "tape/remove-skip": ["on", {
90
93
  "allowed": ["test"]
91
- }]
94
+ }],
95
+ "tape/move-out-result-from-assertion": "on"
92
96
  }
93
97
  }
94
98
  ```
@@ -397,6 +401,27 @@ test('copymitter', async (t) => {
397
401
  });
398
402
  ```
399
403
 
404
+ ## apply-assertions-order
405
+
406
+ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/0c0adae586448bd0921129275fb08891/c2f031920a3f1eb119c71b5ac3ba3c27ce1710ea).
407
+
408
+ ### ❌ Example of incorrect code
409
+
410
+ ```js
411
+ t.equal(result, expected);
412
+ cleanup();
413
+ t.end();
414
+ ```
415
+
416
+ ### ✅ Example of correct code
417
+
418
+ ```js
419
+ cleanup();
420
+
421
+ t.equal(result, expected);
422
+ t.end();
423
+ ```
424
+
400
425
  ## apply-destructuring
401
426
 
402
427
  Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/adf238850271c0a4ad917e71bab8757c/4ff416c3d9f3de0930339c7a4929eb4b62461d1a).
@@ -796,6 +821,37 @@ test('some test', (t) => {
796
821
  });
797
822
  ```
798
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
+
799
855
  ## License
800
856
 
801
857
  MIT
@@ -0,0 +1,46 @@
1
+ import {operator, print} from 'putout';
2
+
3
+ const {
4
+ compare,
5
+ insertBefore,
6
+ remove,
7
+ } = operator;
8
+
9
+ const printNode = (a) => print(a, {
10
+ printer: ['putout', {
11
+ format: {
12
+ newline: '',
13
+ },
14
+ }],
15
+ });
16
+
17
+ export const report = ({prev, prevPrev}) => {
18
+ return `Use '${printNode(prev)}' before '${printNode(prevPrev)}'`;
19
+ };
20
+
21
+ export const fix = ({prev, prevPrev}) => {
22
+ const prevNode = prev.node;
23
+
24
+ remove(prev);
25
+ insertBefore(prevPrev, prevNode);
26
+ };
27
+
28
+ export const traverse = ({push}) => ({
29
+ 't.end()': (path) => {
30
+ const prev = path.parentPath.getPrevSibling();
31
+
32
+ if (!prev.node)
33
+ return;
34
+
35
+ if (compare(prev, 't.__a(__args)'))
36
+ return;
37
+
38
+ const prevPrev = prev.getPrevSibling();
39
+
40
+ push({
41
+ path,
42
+ prev,
43
+ prevPrev,
44
+ });
45
+ },
46
+ });
package/lib/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import * as movOutResultFromAssertion from './move-out-result-from-assertion/index.js';
2
+ import * as applyAssertionsOrder from './apply-assertions-order/index.js';
1
3
  import * as removeUselessUndefined from './remove-useless-undefined/index.js';
2
4
  import * as extractArgsFromCalledWith from './extract-args-from-called-with/index.js';
3
5
  import * as applyStub from './apply-stub/index.js';
@@ -66,4 +68,6 @@ export const rules = {
66
68
  'remove-skip': removeSkip,
67
69
  'extract-args-from-called-with': extractArgsFromCalledWith,
68
70
  'remove-useless-undefined': removeUselessUndefined,
71
+ 'apply-assertions-order': applyAssertionsOrder,
72
+ 'move-out-result-from-assertion': movOutResultFromAssertion,
69
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.5.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",