@putout/plugin-tape 21.8.1 → 21.9.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 +20 -0
- package/lib/apply-stringify/index.js +18 -0
- package/lib/index.js +2 -0
- package/lib/move-out-result-from-assertion/index.js +1 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ npm i @putout/plugin-tape -D
|
|
|
22
22
|
- ✅ [apply-assertions-order](#apply-assertions-order);
|
|
23
23
|
- ✅ [apply-destructuring](#apply-destructuring);
|
|
24
24
|
- ✅ [apply-stub](#apply-stub);
|
|
25
|
+
- ✅ [apply-stringify](#apply-stringify);
|
|
25
26
|
- ✅ [apply-with-name](#apply-with-name);
|
|
26
27
|
- ✅ [convert-called-with-args](#convert-called-with-args);
|
|
27
28
|
- ✅ [convert-called-with-no-args-to-called-with](#convert-called-with-no-args-to-called-with);
|
|
@@ -59,6 +60,7 @@ npm i @putout/plugin-tape -D
|
|
|
59
60
|
"rules": {
|
|
60
61
|
"tape/jest": "on",
|
|
61
62
|
"tape/apply-stub": "on",
|
|
63
|
+
"tape/apply-stringify": "on",
|
|
62
64
|
"tape/apply-assertions-order": "on",
|
|
63
65
|
"tape/apply-destructuring": "on",
|
|
64
66
|
"tape/apply-with-name": "on",
|
|
@@ -463,6 +465,24 @@ const c = stub().rejects(Error('hello'));
|
|
|
463
465
|
const d = stub().rejects(Error('hello'));
|
|
464
466
|
```
|
|
465
467
|
|
|
468
|
+
## apply-stringify
|
|
469
|
+
|
|
470
|
+
Checkout in 🐊[**Putout Editor**](https://putout.vercel.app/#/gist/6791411046ac930e7d53a8954ec1ac90/e3735554f156221a8f2661a447a9b4f7db8994e9)
|
|
471
|
+
|
|
472
|
+
### ❌ Example of incorrect code
|
|
473
|
+
|
|
474
|
+
```js
|
|
475
|
+
const read = stub().returns('{"checkCoverage": true}');
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### ✅ Example of correct code
|
|
479
|
+
|
|
480
|
+
```js
|
|
481
|
+
const read = stub().returns(stringify({
|
|
482
|
+
checkCoverage: true,
|
|
483
|
+
}));
|
|
484
|
+
```
|
|
485
|
+
|
|
466
486
|
## apply-with-name
|
|
467
487
|
|
|
468
488
|
### ❌ Example of incorrect code
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {tryCatch} from 'try-catch';
|
|
2
|
+
|
|
3
|
+
const {parse} = JSON;
|
|
4
|
+
|
|
5
|
+
export const report = () => `Use 'stringify' instead of passing JSON string`;
|
|
6
|
+
|
|
7
|
+
export const match = () => ({
|
|
8
|
+
'const __a = stub().returns("__b");': ({__b}) => {
|
|
9
|
+
const [error] = tryCatch(parse, __b.value);
|
|
10
|
+
return !error;
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const replace = () => ({
|
|
15
|
+
'const __a = stub().returns("__b");': ({__b}) => {
|
|
16
|
+
return `const __a = stub().returns(stringify(${__b.value}))`;
|
|
17
|
+
},
|
|
18
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as applyStringify from './apply-stringify/index.js';
|
|
1
2
|
import * as movOutResultFromAssertion from './move-out-result-from-assertion/index.js';
|
|
2
3
|
import * as applyAssertionsOrder from './apply-assertions-order/index.js';
|
|
3
4
|
import * as removeUselessUndefined from './remove-useless-undefined/index.js';
|
|
@@ -70,4 +71,5 @@ export const rules = {
|
|
|
70
71
|
'remove-useless-undefined': removeUselessUndefined,
|
|
71
72
|
'apply-assertions-order': applyAssertionsOrder,
|
|
72
73
|
'move-out-result-from-assertion': movOutResultFromAssertion,
|
|
74
|
+
'apply-stringify': applyStringify,
|
|
73
75
|
};
|
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
|
|
12
12
|
export const report = () => `Move out result from assertion`;
|
|
13
13
|
export const match = () => ({
|
|
14
|
+
't.__(__a(__b))': (vars, path) => !getBinding(path, 'result'),
|
|
14
15
|
't.__a(__b, __c)': ({__a, __b, __c}, path) => {
|
|
15
16
|
if (!/equal/i.test(__a.name))
|
|
16
17
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-tape",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.9.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",
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
"coverage": "madrun coverage",
|
|
24
24
|
"report": "madrun report"
|
|
25
25
|
},
|
|
26
|
-
"dependencies": {
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"try-catch": "^4.0.9"
|
|
28
|
+
},
|
|
27
29
|
"keywords": [
|
|
28
30
|
"putout",
|
|
29
31
|
"putout-plugin",
|