@putout/plugin-tape 9.2.1 → 9.5.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
|
@@ -20,6 +20,7 @@ npm i @putout/plugin-tape -D
|
|
|
20
20
|
```json
|
|
21
21
|
{
|
|
22
22
|
"rules": {
|
|
23
|
+
"tape/apply-stub": "on",
|
|
23
24
|
"tape/apply-stub-operator": "on",
|
|
24
25
|
"tape/apply-with-name": "on",
|
|
25
26
|
"tape/add-t-end": "on",
|
|
@@ -333,6 +334,32 @@ test('copymitter', async (t) => {
|
|
|
333
334
|
});
|
|
334
335
|
```
|
|
335
336
|
|
|
337
|
+
## apply-stub
|
|
338
|
+
|
|
339
|
+
Apply [stub](https://github.com/cloudcmd/stub) functions created. Look how it works in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d098a8c8d03a072a7f3981e3cfb1d7af/f1542bfa39513ac625b2a9cd9243cc06dee286c0).
|
|
340
|
+
|
|
341
|
+
### ❌ Example of incorrect code
|
|
342
|
+
|
|
343
|
+
```js
|
|
344
|
+
const a = async () => true;
|
|
345
|
+
const b = async () => {};
|
|
346
|
+
|
|
347
|
+
const c = async () => throw Error('hello');
|
|
348
|
+
const d = async () => {
|
|
349
|
+
throw Error('hello');
|
|
350
|
+
};
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### ✅ Example of correct code
|
|
354
|
+
|
|
355
|
+
```js
|
|
356
|
+
const a = stub().resolves(true);
|
|
357
|
+
const b = stub().resolves();
|
|
358
|
+
|
|
359
|
+
const c = stub().rejects(Error('hello'));
|
|
360
|
+
const d = stub().rejects(Error('hello'));
|
|
361
|
+
```
|
|
362
|
+
|
|
336
363
|
## apply-stub-operator
|
|
337
364
|
|
|
338
365
|
### ❌ Example of incorrect code
|
package/lib/add-args/index.js
CHANGED
|
@@ -7,6 +7,12 @@ module.exports = addArgs({
|
|
|
7
7
|
t: ['t', [
|
|
8
8
|
'test("__a", (__args) => __body)',
|
|
9
9
|
'test("__a", async (__args) => __body)',
|
|
10
|
+
|
|
11
|
+
'test.only("__a", (__args) => __body)',
|
|
12
|
+
'test.only("__a", async (__args) => __body)',
|
|
13
|
+
|
|
14
|
+
'test.skip("__a", (__args) => __body)',
|
|
15
|
+
'test.skip("__a", async (__args) => __body)',
|
|
10
16
|
],
|
|
11
17
|
],
|
|
12
18
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
template,
|
|
5
|
+
types,
|
|
6
|
+
} = require('putout');
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
isUnaryExpression,
|
|
10
|
+
isThrowStatement,
|
|
11
|
+
isBlockStatement,
|
|
12
|
+
} = types;
|
|
13
|
+
|
|
14
|
+
const REJECTS = template('stub().rejects(A)');
|
|
15
|
+
|
|
16
|
+
module.exports.report = () => `Use 'stub()' instead of creating a function`;
|
|
17
|
+
|
|
18
|
+
module.exports.match = () => ({
|
|
19
|
+
'async () => __a': ({__a}, path) => {
|
|
20
|
+
if (!path.parentPath.isVariableDeclarator())
|
|
21
|
+
return false;
|
|
22
|
+
|
|
23
|
+
if (!isBlockStatement(__a))
|
|
24
|
+
return true;
|
|
25
|
+
|
|
26
|
+
if (!__a.body.length)
|
|
27
|
+
return true;
|
|
28
|
+
|
|
29
|
+
return isThrowStatement(__a.body[0]);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
module.exports.replace = () => ({
|
|
34
|
+
'async () => __a': ({__a}) => {
|
|
35
|
+
if (isUnaryExpression(__a, {operator: 'throw'})) {
|
|
36
|
+
return REJECTS({
|
|
37
|
+
A: __a.argument,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (isBlockStatement(__a) && !__a.body.length) {
|
|
42
|
+
return 'stub().resolves()';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isBlockStatement(__a) && isThrowStatement(__a.body[0])) {
|
|
46
|
+
return REJECTS({
|
|
47
|
+
A: __a.body[0].argument,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return 'stub().resolves(__a)';
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
package/lib/index.js
CHANGED
|
@@ -11,12 +11,15 @@ const {
|
|
|
11
11
|
TEST_ASYNC_SKIP,
|
|
12
12
|
} = require('../test-signatures');
|
|
13
13
|
|
|
14
|
-
const {
|
|
14
|
+
const {
|
|
15
|
+
traverse,
|
|
16
|
+
remove,
|
|
17
|
+
} = operator;
|
|
15
18
|
|
|
16
19
|
module.exports.report = () => `Remove 'stopAll()' when you not calling 'reImport()'`;
|
|
17
20
|
|
|
18
21
|
module.exports.fix = (path) => {
|
|
19
|
-
|
|
22
|
+
remove(path);
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
module.exports.traverse = ({push}) => ({
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
const {operator} = require('putout');
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const {
|
|
6
|
+
traverse,
|
|
7
|
+
remove,
|
|
8
|
+
} = operator;
|
|
6
9
|
|
|
7
10
|
module.exports.report = () => `Avoid useless 't.end()'`;
|
|
8
11
|
|
|
9
12
|
module.exports.fix = (path) => {
|
|
10
|
-
|
|
13
|
+
remove(path);
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
const TEST = 'test("__a", (t) => __body)';
|