@putout/plugin-tape 9.0.0 → 9.2.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 +5 -31
- package/lib/apply-with-name/index.js +5 -8
- package/lib/convert-does-not-throw-to-try-catch/index.js +0 -4
- package/lib/convert-emitter-to-promise/index.js +1 -0
- package/lib/convert-throws-to-try-catch/index.js +0 -3
- package/lib/index.js +0 -1
- package/lib/remove-skip/index.js +8 -4
- package/package.json +2 -2
- package/lib/expand-try-catch-arguments/index.js +0 -43
- package/lib/insert-require-try-catch.js +0 -15
package/README.md
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
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
|
+
> Tape-inspired TAP-compatible simplest high speed test runner with superpowers.
|
|
7
|
+
>
|
|
8
|
+
> (c) 📼[**Supertape**](https://github.com/coderaiser/supertape)
|
|
9
|
+
|
|
10
|
+
🐊[**Putout**](https://github.com/coderaiser/putout) plugin helps to apply best parctises for tests written with 📼[**Supertape**](https://github.com/coderaiser/supertape).
|
|
7
11
|
|
|
8
12
|
## Install
|
|
9
13
|
|
|
@@ -33,7 +37,6 @@ npm i @putout/plugin-tape -D
|
|
|
33
37
|
"tape/convert-equal-to-called-once": "on",
|
|
34
38
|
"tape/convert-equal-to-deep-equal": "on",
|
|
35
39
|
"tape/convert-deep-equal-to-equal": "on",
|
|
36
|
-
"tape/expand-try-catch-arguments": "on",
|
|
37
40
|
"tape/convert-emitter-to-promise": "on",
|
|
38
41
|
"tape/convert-ok-to-match": "on",
|
|
39
42
|
"tape/convert-ok-to-called-with": "on",
|
|
@@ -330,35 +333,6 @@ test('copymitter', async (t) => {
|
|
|
330
333
|
});
|
|
331
334
|
```
|
|
332
335
|
|
|
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
336
|
## apply-stub-operator
|
|
363
337
|
|
|
364
338
|
### ❌ Example of incorrect code
|
|
@@ -57,13 +57,7 @@ function checkStub(node, path) {
|
|
|
57
57
|
const {name} = node;
|
|
58
58
|
const binding = bindings[name];
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
return false;
|
|
62
|
-
|
|
63
|
-
const initPath = binding.path.get('init');
|
|
64
|
-
const calleePath = initPath.get('callee');
|
|
65
|
-
|
|
66
|
-
return !calleePath.isMemberExpression();
|
|
60
|
+
return binding;
|
|
67
61
|
}
|
|
68
62
|
|
|
69
63
|
function applyWithNameToNode(node, path) {
|
|
@@ -76,9 +70,12 @@ function applyWithNameToNode(node, path) {
|
|
|
76
70
|
|
|
77
71
|
const initPath = binding.path.get('init');
|
|
78
72
|
const calleePath = initPath.get('callee');
|
|
73
|
+
const str = initPath.toString();
|
|
79
74
|
|
|
80
|
-
if (calleePath.isMemberExpression())
|
|
75
|
+
if (calleePath.isMemberExpression() && !str.includes('withName')) {
|
|
76
|
+
replaceWith(initPath, template.ast(`${initPath}.withName('${name}')`));
|
|
81
77
|
return;
|
|
78
|
+
}
|
|
82
79
|
|
|
83
80
|
replaceWith(initPath, template.ast(`stub().withName('${name}')`));
|
|
84
81
|
}
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const {template} = require('putout');
|
|
4
4
|
|
|
5
|
-
const insertRequireTryCatch = require('../insert-require-try-catch');
|
|
6
|
-
|
|
7
5
|
module.exports.report = () => 'try-catch should be used instead of t.doesNotThrow';
|
|
8
6
|
|
|
9
7
|
module.exports.replace = () => ({
|
|
@@ -13,9 +11,7 @@ module.exports.replace = () => ({
|
|
|
13
11
|
`);
|
|
14
12
|
|
|
15
13
|
tryCatchNode.declarations[0].init.arguments[0] = __a;
|
|
16
|
-
|
|
17
14
|
path.insertBefore(tryCatchNode);
|
|
18
|
-
insertRequireTryCatch(path);
|
|
19
15
|
|
|
20
16
|
return `t.notOk(error, __b)`;
|
|
21
17
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {template} = require('putout');
|
|
4
|
-
const insertRequireTryCatch = require('../insert-require-try-catch');
|
|
5
4
|
|
|
6
5
|
module.exports.report = () => 'try-catch should be used instead of t.throws';
|
|
7
6
|
|
|
@@ -22,8 +21,6 @@ function putTryCatch(__a, path) {
|
|
|
22
21
|
`);
|
|
23
22
|
|
|
24
23
|
tryCatchNode.declarations[0].init.arguments[0] = __a;
|
|
25
|
-
|
|
26
24
|
path.insertBefore(tryCatchNode);
|
|
27
|
-
insertRequireTryCatch(path);
|
|
28
25
|
}
|
|
29
26
|
|
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/lib/remove-skip/index.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
|
|
5
|
+
const {isIdentifier} = types;
|
|
6
|
+
|
|
7
|
+
module.exports.report = () => 'Remove "test.skip"';
|
|
4
8
|
|
|
5
9
|
module.exports.replace = () => ({
|
|
6
10
|
'__a.skip(__b, __c)': '__a(__b, __c)',
|
|
7
11
|
'__a.skip(__b, __c, __d)': '__a(__b, __c, __d)',
|
|
8
|
-
'__a["skip"](__b, __c)': '__a(__b, __c)',
|
|
9
12
|
});
|
|
10
13
|
|
|
11
14
|
module.exports.filter = (path) => {
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
return isIdentifier(path.node.callee.object, {
|
|
16
|
+
name: 'test',
|
|
17
|
+
});
|
|
14
18
|
};
|
|
15
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-tape",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "putout plugin helps with tests",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"c8": "^7.5.0",
|
|
36
36
|
"eslint": "^8.0.1",
|
|
37
37
|
"eslint-plugin-node": "^11.0.0",
|
|
38
|
-
"eslint-plugin-putout": "^
|
|
38
|
+
"eslint-plugin-putout": "^14.0.0",
|
|
39
39
|
"lerna": "^4.0.0",
|
|
40
40
|
"madrun": "^9.0.0",
|
|
41
41
|
"montag": "^1.2.1",
|
|
@@ -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
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {template} = require('putout');
|
|
4
|
-
|
|
5
|
-
const requireTryCatch = template.ast(`const tryCatch = require('try-catch')`);
|
|
6
|
-
|
|
7
|
-
module.exports = (path) => {
|
|
8
|
-
const parentScope = path.scope.getProgramParent();
|
|
9
|
-
|
|
10
|
-
if (parentScope.bindings.tryCatch)
|
|
11
|
-
return;
|
|
12
|
-
|
|
13
|
-
parentScope.block.body.unshift(requireTryCatch);
|
|
14
|
-
};
|
|
15
|
-
|