@putout/plugin-tape 9.0.1 → 9.2.1

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
@@ -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
- 🐊[`Putout`](https://github.com/coderaiser/putout) plugin helps to apply best parctises for tests written with 📼[`Supertape`](https://github.com/coderaiser/supertape).
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
@@ -62,8 +62,12 @@ function checkStub(node, path) {
62
62
 
63
63
  const initPath = binding.path.get('init');
64
64
  const calleePath = initPath.get('callee');
65
+ const str = initPath.toString();
65
66
 
66
- return !calleePath.isMemberExpression();
67
+ if (calleePath.isMemberExpression() && str.includes('withName'))
68
+ return false;
69
+
70
+ return true;
67
71
  }
68
72
 
69
73
  function applyWithNameToNode(node, path) {
@@ -76,9 +80,12 @@ function applyWithNameToNode(node, path) {
76
80
 
77
81
  const initPath = binding.path.get('init');
78
82
  const calleePath = initPath.get('callee');
83
+ const str = initPath.toString();
79
84
 
80
- if (calleePath.isMemberExpression())
85
+ if (calleePath.isMemberExpression() && !str.includes('withName')) {
86
+ replaceWith(initPath, template.ast(`${initPath}.withName('${name}')`));
81
87
  return;
88
+ }
82
89
 
83
90
  replaceWith(initPath, template.ast(`stub().withName('${name}')`));
84
91
  }
@@ -54,6 +54,7 @@ function match({__body}) {
54
54
 
55
55
  return false;
56
56
  }
57
+
57
58
  function replace({__a}, path) {
58
59
  declareOnce(path);
59
60
 
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "9.0.1",
3
+ "version": "9.2.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "putout plugin helps with tests",
@@ -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
- });