@putout/plugin-tape 9.0.1 → 9.1.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 +1 -31
- package/lib/index.js +0 -1
- package/package.json +1 -1
- package/lib/expand-try-catch-arguments/index.js +0 -43
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-tape.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/plugin-tape"npm"
|
|
5
5
|
|
|
6
|
-
🐊[
|
|
6
|
+
🐊[**Putout**](https://github.com/coderaiser/putout) plugin helps to apply best parctises for tests written with 📼[`Supertape`](https://github.com/coderaiser/supertape).
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -33,7 +33,6 @@ npm i @putout/plugin-tape -D
|
|
|
33
33
|
"tape/convert-equal-to-called-once": "on",
|
|
34
34
|
"tape/convert-equal-to-deep-equal": "on",
|
|
35
35
|
"tape/convert-deep-equal-to-equal": "on",
|
|
36
|
-
"tape/expand-try-catch-arguments": "on",
|
|
37
36
|
"tape/convert-emitter-to-promise": "on",
|
|
38
37
|
"tape/convert-ok-to-match": "on",
|
|
39
38
|
"tape/convert-ok-to-called-with": "on",
|
|
@@ -330,35 +329,6 @@ test('copymitter', async (t) => {
|
|
|
330
329
|
});
|
|
331
330
|
```
|
|
332
331
|
|
|
333
|
-
## expand-try-catch-arguments
|
|
334
|
-
|
|
335
|
-
### ❌ Example of incorrect code
|
|
336
|
-
|
|
337
|
-
```js
|
|
338
|
-
import tryCatch from 'try-catch';
|
|
339
|
-
|
|
340
|
-
test('some message', (t) => {
|
|
341
|
-
const fn = () => copymitter('/hello');
|
|
342
|
-
const [error] = tryCatch(fn);
|
|
343
|
-
|
|
344
|
-
t.equal(error.message, 'to should be a string!');
|
|
345
|
-
t.end();
|
|
346
|
-
});
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
### ✅ Example of correct code
|
|
350
|
-
|
|
351
|
-
```js
|
|
352
|
-
import tryCatch from 'try-catch';
|
|
353
|
-
|
|
354
|
-
test('some message', (t) => {
|
|
355
|
-
const [error] = tryCatch(copymitter, '/hello');
|
|
356
|
-
|
|
357
|
-
t.equal(error.message, 'to should be a string!');
|
|
358
|
-
t.end();
|
|
359
|
-
});
|
|
360
|
-
```
|
|
361
|
-
|
|
362
332
|
## apply-stub-operator
|
|
363
333
|
|
|
364
334
|
### ❌ Example of incorrect code
|
package/lib/index.js
CHANGED
|
@@ -23,7 +23,6 @@ module.exports.rules = {
|
|
|
23
23
|
...getRule('convert-equal-to-ok'),
|
|
24
24
|
...getRule('convert-equal-to-called-once'),
|
|
25
25
|
...getRule('convert-deep-equal-to-equal'),
|
|
26
|
-
...getRule('expand-try-catch-arguments'),
|
|
27
26
|
...getRule('add-args'),
|
|
28
27
|
...getRule('declare'),
|
|
29
28
|
...getRule('remove-default-messages'),
|
package/package.json
CHANGED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports.report = () => 'try-catch arguments should be expanded';
|
|
4
|
-
|
|
5
|
-
module.exports.match = () => ({
|
|
6
|
-
'tryCatch(__args)': ({__args}, path) => {
|
|
7
|
-
const [fn] = __args;
|
|
8
|
-
const {name} = fn;
|
|
9
|
-
const {bindings} = path.scope;
|
|
10
|
-
|
|
11
|
-
if (!bindings[name])
|
|
12
|
-
return false;
|
|
13
|
-
|
|
14
|
-
const initPath = bindings[name].path.get('init');
|
|
15
|
-
|
|
16
|
-
if (!initPath.isFunction())
|
|
17
|
-
return false;
|
|
18
|
-
|
|
19
|
-
const bodyPath = initPath.get('body');
|
|
20
|
-
|
|
21
|
-
return bodyPath.isCallExpression();
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
module.exports.replace = () => ({
|
|
26
|
-
'tryCatch(__args)': ({__args}, path) => {
|
|
27
|
-
const [fn] = __args;
|
|
28
|
-
const {name} = fn;
|
|
29
|
-
const {bindings} = path.scope;
|
|
30
|
-
|
|
31
|
-
const fnPath = bindings[name].path;
|
|
32
|
-
const {node} = fnPath.get('init.body');
|
|
33
|
-
const newArgs = [
|
|
34
|
-
node.callee,
|
|
35
|
-
...node.arguments,
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
path.node.arguments = newArgs;
|
|
39
|
-
fnPath.remove();
|
|
40
|
-
|
|
41
|
-
return path;
|
|
42
|
-
},
|
|
43
|
-
});
|