@putout/plugin-tape 11.1.0 → 12.0.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.
Files changed (32) hide show
  1. package/README.md +54 -16
  2. package/lib/add-args/index.js +1 -4
  3. package/lib/add-await-to-re-import/index.js +1 -5
  4. package/lib/add-stop-all/index.js +2 -3
  5. package/lib/add-t-end/index.js +3 -0
  6. package/lib/apply-destructuring/index.js +4 -2
  7. package/lib/apply-stub/index.js +1 -5
  8. package/lib/apply-with-name/index.js +3 -9
  9. package/lib/convert-called-with-args/index.js +1 -5
  10. package/lib/convert-called-with-no-args-to-called-with/index.js +0 -2
  11. package/lib/convert-called-with-to-called-with-no-args/index.js +0 -1
  12. package/lib/convert-deep-equal-to-equal/index.js +3 -15
  13. package/lib/convert-does-not-throw-to-try-catch/index.js +4 -2
  14. package/lib/convert-emitter-to-promise/index.js +7 -21
  15. package/lib/convert-equal-to-called-once/index.js +0 -1
  16. package/lib/convert-equal-to-deep-equal/index.js +0 -1
  17. package/lib/convert-equal-to-not-ok/index.js +1 -9
  18. package/lib/convert-equal-to-ok/index.js +1 -8
  19. package/lib/convert-match-regexp-to-string/index.js +0 -4
  20. package/lib/convert-mock-require-to-mock-import/index.js +50 -0
  21. package/lib/convert-ok-to-match/index.js +0 -1
  22. package/lib/convert-throws-to-try-catch/index.js +4 -3
  23. package/lib/declare/index.js +0 -1
  24. package/lib/index.js +68 -37
  25. package/lib/jest/index.js +0 -1
  26. package/lib/remove-default-messages/index.js +0 -1
  27. package/lib/remove-only/index.js +0 -1
  28. package/lib/remove-skip/index.js +0 -1
  29. package/lib/remove-stop-all/index.js +1 -6
  30. package/lib/remove-useless-not-called-args/index.js +0 -1
  31. package/lib/remove-useless-t-end/index.js +1 -5
  32. package/package.json +7 -7
package/README.md CHANGED
@@ -44,6 +44,7 @@ npm i @putout/plugin-tape -D
44
44
  "tape/convert-ok-to-match": "on",
45
45
  "tape/convert-ok-to-called-with": "on",
46
46
  "tape/convert-match-regexp-to-string": "on",
47
+ "tape/convert-mock-require-to-mock-import": "on",
47
48
  "tape/add-args": "on",
48
49
  "tape/declare": "on",
49
50
  "tape/remove-default-messages": "on",
@@ -183,7 +184,6 @@ const {stub} = test;
183
184
 
184
185
  test('some message', (t) => {
185
186
  const fn = stub();
186
-
187
187
  fn();
188
188
 
189
189
  t.calledWith(fn, 'hello');
@@ -199,7 +199,6 @@ const {stub} = test;
199
199
 
200
200
  test('some message', (t) => {
201
201
  const fn = stub();
202
-
203
202
  fn();
204
203
 
205
204
  t.calledWith(fn, ['hello']);
@@ -219,7 +218,6 @@ const {stub} = test;
219
218
 
220
219
  test('some message', (t) => {
221
220
  const fn = stub();
222
-
223
221
  fn();
224
222
 
225
223
  t.equal(fn.callCount, 1);
@@ -235,7 +233,6 @@ const {stub} = test;
235
233
 
236
234
  test('some message', (t) => {
237
235
  const fn = stub();
238
-
239
236
  fn();
240
237
 
241
238
  t.calledOnce(fn);
@@ -281,7 +278,6 @@ const {stub} = test;
281
278
 
282
279
  test('some message', (t) => {
283
280
  const fn = stub();
284
-
285
281
  fn();
286
282
 
287
283
  t.calledWith(fn);
@@ -297,7 +293,6 @@ const {stub} = test;
297
293
 
298
294
  test('some message', (t) => {
299
295
  const fn = stub();
300
-
301
296
  fn();
302
297
 
303
298
  t.calledWithNoArgs(fn);
@@ -315,7 +310,6 @@ const {stub} = test;
315
310
 
316
311
  test('some message', (t) => {
317
312
  const fn = stub();
318
-
319
313
  fn();
320
314
 
321
315
  t.calledWithNoArgs(fn, [1, 2]);
@@ -331,7 +325,6 @@ const {stub} = test;
331
325
 
332
326
  test('some message', (t) => {
333
327
  const fn = stub();
334
-
335
328
  fn();
336
329
 
337
330
  t.calledWith(fn, [1, 2]);
@@ -362,6 +355,7 @@ test('copymitter', async (t) => {
362
355
  const cp = copymitter(from, to, ['1']);
363
356
 
364
357
  await once(cp, 'end');
358
+
365
359
  t.end();
366
360
  });
367
361
  ```
@@ -380,10 +374,7 @@ const {stub} = test;
380
374
  ### ✅ Example of correct code
381
375
 
382
376
  ```js
383
- const {
384
- test,
385
- stub,
386
- } = require('supertape');
377
+ const {test, stub} = require('supertape');
387
378
  ```
388
379
 
389
380
  ## apply-stub
@@ -395,8 +386,8 @@ Apply [stub](https://github.com/cloudcmd/stub) functions created. Look how it wo
395
386
  ```js
396
387
  const a = async () => true;
397
388
  const b = async () => {};
389
+ const c = async () => throwError('hello');
398
390
 
399
- const c = async () => throw Error('hello');
400
391
  const d = async () => {
401
392
  throw Error('hello');
402
393
  };
@@ -407,7 +398,6 @@ const d = async () => {
407
398
  ```js
408
399
  const a = stub().resolves(true);
409
400
  const b = stub().resolves();
410
-
411
401
  const c = stub().rejects(Error('hello'));
412
402
  const d = stub().rejects(Error('hello'));
413
403
  ```
@@ -563,8 +553,7 @@ test('xxx', (t) => {
563
553
  ### ❌ Example of incorrect code
564
554
 
565
555
  ```js
566
- test('xxx', () => {
567
- });
556
+ test('xxx', () => {});
568
557
  ```
569
558
 
570
559
  ### ✅ Example of correct code
@@ -606,6 +595,7 @@ test('stop-all: should be called', (t) => {
606
595
  mockImport('fs/promises', {
607
596
  readFile: stub(),
608
597
  });
598
+
609
599
  t.end();
610
600
  });
611
601
  ```
@@ -824,6 +814,54 @@ test('some test', (t) => {
824
814
  });
825
815
  ```
826
816
 
817
+ ## convert-mock-import-to-require
818
+
819
+ Convert [mockRequire](https://github.com/boblauer/mock-require) to [mockImport](https://github.com/coderaiser/mock-import).
820
+
821
+ ### ❌ Example of incorrect code
822
+
823
+ ```js
824
+ const mockRequire = require('mock-require');
825
+
826
+ const {reRequire, stopAll} = mockRequire;
827
+
828
+ test('', (t) => {
829
+ mockRequire('fs/promises', {
830
+ unlink: stub(),
831
+ });
832
+
833
+ const fn = reRequire('..');
834
+ fn();
835
+
836
+ stopAll();
837
+ t.end();
838
+ });
839
+ ```
840
+
841
+ ### ✅ Example of correct code
842
+
843
+ ```js
844
+ import {createMockImport} from 'mock-import';
845
+
846
+ const {
847
+ mockImport,
848
+ reImport,
849
+ stopAll,
850
+ } = createMockImport(import.meta.url);
851
+
852
+ test('', async (t) => {
853
+ mockImport('fs/promises', {
854
+ unlink: stub(),
855
+ });
856
+
857
+ const fn = await reImport('..');
858
+ fn();
859
+
860
+ stopAll();
861
+ t.end();
862
+ });
863
+ ```
864
+
827
865
  ## License
828
866
 
829
867
  MIT
@@ -7,12 +7,9 @@ module.exports = addArgs({
7
7
  t: ['t', [
8
8
  'test("__a", (__args) => __body)',
9
9
  'test("__a", async (__args) => __body)',
10
-
11
10
  'test.only("__a", (__args) => __body)',
12
11
  'test.only("__a", async (__args) => __body)',
13
-
14
12
  'test.skip("__a", (__args) => __body)',
15
13
  'test.skip("__a", async (__args) => __body)',
16
- ],
17
- ],
14
+ ]],
18
15
  });
@@ -9,10 +9,7 @@ module.exports.match = () => ({
9
9
  'reImport(__a)': (vars, path) => {
10
10
  const {parentPath} = path;
11
11
 
12
- if (parentPath.isAwaitExpression())
13
- return false;
14
-
15
- return true;
12
+ return !parentPath.isAwaitExpression();
16
13
  },
17
14
  });
18
15
 
@@ -26,4 +23,3 @@ module.exports.replace = () => ({
26
23
  return 'await reImport(__a)';
27
24
  },
28
25
  });
29
-
@@ -18,6 +18,7 @@ const {
18
18
  const {
19
19
  traverse,
20
20
  compare,
21
+ insertBefore,
21
22
  } = operator;
22
23
 
23
24
  const {ExpressionStatement} = types;
@@ -28,14 +29,13 @@ module.exports.fix = (path) => {
28
29
  const assertionPath = getAssertionsPath(path);
29
30
  const stopAllNode = template.ast('stopAll()');
30
31
 
31
- assertionPath.insertBefore(ExpressionStatement(stopAllNode));
32
+ insertBefore(assertionPath, ExpressionStatement(stopAllNode));
32
33
  };
33
34
 
34
35
  module.exports.traverse = ({push}) => ({
35
36
  [TEST]: createTraverse(push),
36
37
  [TEST_ONLY]: createTraverse(push),
37
38
  [TEST_SKIP]: createTraverse(push),
38
-
39
39
  [TEST_ASYNC]: createTraverse(push),
40
40
  [TEST_ASYNC_ONLY]: createTraverse(push),
41
41
  [TEST_ASYNC_SKIP]: createTraverse(push),
@@ -100,4 +100,3 @@ function getAssertionsPath(path) {
100
100
 
101
101
  return resultPath;
102
102
  }
103
-
@@ -5,7 +5,9 @@ const {
5
5
  template,
6
6
  operator,
7
7
  } = require('putout');
8
+
8
9
  const {compare, traverse} = operator;
10
+
9
11
  const {ExpressionStatement} = types;
10
12
 
11
13
  module.exports.report = () => `'t.end()' is missing at the end of the test`;
@@ -33,6 +35,7 @@ function match({__body}, path) {
33
35
  }
34
36
 
35
37
  let found = false;
38
+
36
39
  traverse(path, {
37
40
  't.end()': () => {
38
41
  found = true;
@@ -1,5 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ const {operator} = require('putout');
4
+ const {remove} = operator;
5
+
3
6
  module.exports.report = () => `Use destructuring when using 'stub()' in 'test()'`;
4
7
 
5
8
  module.exports.match = () => ({
@@ -8,8 +11,7 @@ module.exports.match = () => ({
8
11
 
9
12
  module.exports.replace = () => ({
10
13
  'const test = require("supertape")': (vars, path) => {
11
- path.scope.bindings.stub.path.remove();
14
+ remove(path.scope.bindings.stub.path);
12
15
  return 'const {test, stub} = require("supertape")';
13
16
  },
14
17
  });
15
-
@@ -1,9 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- template,
5
- types,
6
- } = require('putout');
3
+ const {template, types} = require('putout');
7
4
 
8
5
  const {
9
6
  isUnaryExpression,
@@ -51,4 +48,3 @@ module.exports.replace = () => ({
51
48
  return 'stub().resolves(__a)';
52
49
  },
53
50
  });
54
-
@@ -1,9 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- template,
5
- operator,
6
- } = require('putout');
3
+ const {template, operator} = require('putout');
7
4
 
8
5
  const {replaceWith} = operator;
9
6
 
@@ -23,6 +20,7 @@ module.exports.replace = () => ({
23
20
 
24
21
  function checkStubs({__a, __b}, path) {
25
22
  const elements = [__a, __b];
23
+
26
24
  const __array = {
27
25
  elements,
28
26
  };
@@ -66,10 +64,7 @@ function checkStub(node, path) {
66
64
  const calleePath = initPath.get('callee');
67
65
  const str = initPath.toString();
68
66
 
69
- if (calleePath.isMemberExpression() && str.includes('withName'))
70
- return false;
71
-
72
- return true;
67
+ return !(calleePath.isMemberExpression() && str.includes('withName'));
73
68
  }
74
69
 
75
70
  function applyWithNameToNode(node, path) {
@@ -91,4 +86,3 @@ function applyWithNameToNode(node, path) {
91
86
 
92
87
  replaceWith(initPath, template.ast(`stub().withName('${name}')`));
93
88
  }
94
-
@@ -13,14 +13,10 @@ module.exports.match = () => ({
13
13
  if (isIdentifier(__b))
14
14
  return false;
15
15
 
16
- if (isArrayExpression(__b))
17
- return false;
18
-
19
- return true;
16
+ return !isArrayExpression(__b);
20
17
  },
21
18
  });
22
19
 
23
20
  module.exports.replace = () => ({
24
21
  't.calledWith(__a, __b)': 't.calledWith(__a, [__b])',
25
22
  });
26
-
@@ -5,8 +5,6 @@ module.exports.report = () => '"calledWithArgs" should be used when arguments ar
5
5
  module.exports.replace = () => ({
6
6
  't.calledWithNoArgs(__a, __array)': 't.calledWith(__a, __array)',
7
7
  't.calledWithNoArgs(__a, __array, __b)': 't.calledWith(__a, __array, __b)',
8
-
9
8
  't.calledWithNoArgs(__a, __identifier)': 't.calledWith(__a, __identifier)',
10
9
  't.calledWithNoArgs(__a, __identifier, __b)': 't.calledWith(__a, __identifier, __b)',
11
10
  });
12
-
@@ -7,4 +7,3 @@ module.exports.replace = () => ({
7
7
  't.calledWith(__a, [])': 't.calledWithNoArgs(__a)',
8
8
  't.calledWith(__a, [], __b)': 't.calledWithNoArgs(__a, __b)',
9
9
  });
10
-
@@ -1,19 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- types,
5
- operator,
6
- } = require('putout');
3
+ const {types, operator} = require('putout');
7
4
 
8
5
  const isNull = (a) => !a && typeof a === 'object';
9
-
10
6
  const isUndefined = (a) => typeof a === 'undefined';
11
7
  const isBool = (a) => typeof a === 'boolean';
12
-
13
8
  const isNumber = (a) => typeof a === 'number';
14
9
  const isString = (a) => typeof a === 'string';
15
10
  const isPrimitive = (a) => isString(a) || isNumber(a) || isBool(a) || isNull(a) || isUndefined(a);
16
-
17
11
  const {compute} = operator;
18
12
 
19
13
  const {
@@ -48,10 +42,7 @@ const check = ({__b}, path) => {
48
42
 
49
43
  const [is, value] = compute(expectedPath);
50
44
 
51
- if (is && isPrimitive(value))
52
- return true;
53
-
54
- return false;
45
+ return is && isPrimitive(value);
55
46
  };
56
47
 
57
48
  module.exports.match = () => ({
@@ -79,8 +70,5 @@ function checkExpected(path) {
79
70
 
80
71
  const initPath = binding.path.get('init');
81
72
 
82
- if (initPath.isTaggedTemplateExpression())
83
- return true;
84
-
85
- return false;
73
+ return initPath.isTaggedTemplateExpression();
86
74
  }
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const {template} = require('putout');
3
+ const {template, operator} = require('putout');
4
+ const {insertBefore} = operator;
4
5
 
5
6
  module.exports.report = () => 'try-catch should be used instead of t.doesNotThrow';
6
7
 
@@ -11,7 +12,8 @@ module.exports.replace = () => ({
11
12
  `);
12
13
 
13
14
  tryCatchNode.declarations[0].init.arguments[0] = __a;
14
- path.insertBefore(tryCatchNode);
15
+
16
+ insertBefore(path, tryCatchNode);
15
17
 
16
18
  return `t.notOk(error, __b)`;
17
19
  },
@@ -13,12 +13,10 @@ const {
13
13
  } = operator;
14
14
 
15
15
  const {isProgram} = types;
16
-
17
16
  const ON_ANY = `__e.on(__o, (__r) => __body)`;
18
17
  const ON_ANY_NO_RESULT = `__e.on(__o, () => __body)`;
19
18
  const ON_END = `__e.on('end', () => __body)`;
20
19
  const ON_ERROR = `__e.on('error', (__r) => __body)`;
21
-
22
20
  const once = template(`const [%%result%%] = await once(%%emitter%%, %%event%%)`);
23
21
  const onceEnd = template(`await once(%%emitter%%, 'end')`);
24
22
  const onceError = template(`const [%%error%%] = await once(%%emitter%%, 'error')`);
@@ -27,8 +25,8 @@ const onceAnyNoResult = template(`await once(%%emitter%%, %%event%%)`);
27
25
  module.exports.report = () => '"await once" should be used';
28
26
 
29
27
  module.exports.match = () => ({
30
- 'test(__a, (__args) => __body )': match,
31
- 'test(__a, async (__args) => __body )': match,
28
+ 'test(__a, (__args) => __body)': match,
29
+ 'test(__a, async (__args) => __body)': match,
32
30
  });
33
31
 
34
32
  module.exports.replace = () => ({
@@ -38,9 +36,7 @@ module.exports.replace = () => ({
38
36
 
39
37
  function match({__body}) {
40
38
  for (const codeLine of __body.body) {
41
- const {
42
- expression = codeLine,
43
- } = codeLine;
39
+ const {expression = codeLine} = codeLine;
44
40
 
45
41
  if (compare(expression, ON_END))
46
42
  return true;
@@ -59,6 +55,7 @@ function replace({__a}, path) {
59
55
  declareOnce(path);
60
56
 
61
57
  const arg = path.get('arguments.1').node;
58
+
62
59
  arg.async = true;
63
60
 
64
61
  const {body} = arg.body;
@@ -66,28 +63,21 @@ function replace({__a}, path) {
66
63
 
67
64
  for (let i = 0; i < n; i++) {
68
65
  let nodes = [];
69
-
70
66
  const current = body[i];
71
- const {
72
- expression = current,
73
- } = current;
67
+ const {expression = current} = current;
74
68
 
75
69
  if (compare(expression, ON_ERROR))
76
70
  nodes = getErrorNodes(expression);
77
-
78
71
  else if (compare(expression, ON_END))
79
72
  nodes = getEndNodes(expression);
80
-
81
73
  else if (compare(expression, ON_ANY))
82
74
  nodes = getAnyNodes(expression);
83
-
84
75
  else if (compare(expression, ON_ANY_NO_RESULT))
85
76
  nodes = getAnyNoResultNodes(expression);
86
-
87
77
  else
88
78
  continue;
89
79
 
90
- body.splice(i, 1, ...nodes) ;
80
+ body.splice(i, 1, ...nodes);
91
81
  }
92
82
 
93
83
  const {code} = generate(arg.body);
@@ -113,10 +103,7 @@ function getErrorNodes(expression) {
113
103
  __e,
114
104
  __r,
115
105
  __body,
116
- } = getTemplateValues(
117
- expression,
118
- ON_ERROR,
119
- );
106
+ } = getTemplateValues(expression, ON_ERROR);
120
107
 
121
108
  const nodes = [
122
109
  onceError({
@@ -176,4 +163,3 @@ const declareOnce = (path) => {
176
163
 
177
164
  body.unshift(template.ast(`const {once} = require('events')`));
178
165
  };
179
-
@@ -9,4 +9,3 @@ module.exports.replace = () => ({
9
9
  't.equal(__a.callCount, 1)': 't.calledOnce(__a)',
10
10
  't.equal(__a.callCount, 1, __b)': 't.calledOnce(__a, __b)',
11
11
  });
12
-
@@ -41,4 +41,3 @@ function check({__b}, path) {
41
41
 
42
42
  return isObjectExpression(init) || isArrayExpression(init);
43
43
  }
44
-
@@ -1,14 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- operator,
5
- types,
6
- } = require('putout');
3
+ const {operator, types} = require('putout');
7
4
 
8
5
  const isNumber = (a) => typeof a === 'number';
9
-
10
6
  const isString = (a) => typeof a === 'string';
11
-
12
7
  const {compute} = operator;
13
8
 
14
9
  const {
@@ -57,15 +52,12 @@ module.exports.replace = () => ({
57
52
  't.equal(__a, null, __b)': 't.notOk(__a, __b)',
58
53
  't.equal(__a, false, __b)': 't.notOk(__a, __b)',
59
54
  't.equal(__a, undefined, __b)': 't.notOk(__a, __b)',
60
-
61
55
  't.deepEqual(__a, null)': 't.notOk(__a)',
62
56
  't.deepEqual(__a, null, __b)': 't.notOk(__a, __b)',
63
57
  't.deepEqual(__a, undefined)': 't.notOk(__a)',
64
58
  't.deepEqual(__a, undefined, __b)': 't.notOk(__a, __b)',
65
59
  't.deepEqual(__a, false)': 't.notOk(__a)',
66
60
  't.deepEqual(__a, false, __b)': 't.notOk(__a, __b)',
67
-
68
61
  't.equal(__a)': 't.notOk(__a)',
69
62
  't.notEqual(__a)': 't.ok(__a)',
70
63
  });
71
-
@@ -1,14 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- operator,
5
- types,
6
- } = require('putout');
3
+ const {operator, types} = require('putout');
7
4
 
8
5
  const isBool = (a) => typeof a === 'boolean';
9
-
10
6
  const {compute} = operator;
11
-
12
7
  const {isBooleanLiteral} = types;
13
8
 
14
9
  module.exports.report = (path) => {
@@ -33,8 +28,6 @@ module.exports.match = () => ({
33
28
  module.exports.replace = () => ({
34
29
  't.equal(__a, __b)': 't.ok(__a)',
35
30
  't.equal(__a, true, __b)': 't.ok(__a, __b)',
36
-
37
31
  't.deepEqual(__a, true)': 't.ok(__a)',
38
32
  't.deepEqual(__a, true, __b)': 't.ok(__a, __b)',
39
33
  });
40
-
@@ -2,7 +2,6 @@
2
2
 
3
3
  const {operator} = require('putout');
4
4
  const {isSimpleRegExp} = operator;
5
-
6
5
  const checkRegExp = ({__b}) => isSimpleRegExp(RegExp(__b.pattern));
7
6
  const checkStr = ({__b}) => isSimpleRegExp(RegExp(__b.value));
8
7
 
@@ -13,7 +12,6 @@ module.exports.match = () => ({
13
12
  't.match(__a, RegExp(__b), __c)': checkStr,
14
13
  't.match(__a, /__b/)': checkRegExp,
15
14
  't.match(__a, /__b/, __c)': checkRegExp,
16
-
17
15
  't.notMatch(__a, RegExp(__b))': checkStr,
18
16
  't.notMatch(__a, RegExp(__b), __c)': checkStr,
19
17
  't.notMatch(__a, /__b/)': checkRegExp,
@@ -25,10 +23,8 @@ module.exports.replace = () => ({
25
23
  't.match(__a, RegExp(__b), __c)': 't.match(__a, __b, __c)',
26
24
  't.match(__a, /__b/)': ({__b}) => `t.match(__a, '${__b.pattern}')`,
27
25
  't.match(__a, /__b/, __c)': ({__b}) => `t.match(__a, '${__b.pattern}', __c)`,
28
-
29
26
  't.notMatch(__a, RegExp(__b))': 't.notMatch(__a, __b)',
30
27
  't.notMatch(__a, RegExp(__b), __c)': 't.notMatch(__a, __b, __c)',
31
28
  't.notMatch(__a, /__b/)': ({__b}) => `t.notMatch(__a, '${__b.pattern}')`,
32
29
  't.notMatch(__a, /__b/, __c)': ({__b}) => `t.notMatch(__a, '${__b.pattern}', __c)`,
33
30
  });
34
-
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ const {operator, template} = require('putout');
4
+
5
+ const {
6
+ remove,
7
+ getPathAfterImports,
8
+ insertBefore,
9
+ } = operator;
10
+
11
+ const initStopAll = template.ast(`const {stopAll} = createMockImport(import.meta.url)`);
12
+
13
+ module.exports.report = () => '"mockImport" should be used instead of "mockRequire"';
14
+
15
+ module.exports.replace = () => ({
16
+ 'mockRequire(__a, __b)': 'mockImport(__a, __b)',
17
+ 'reRequire(__a)': (vars, path) => {
18
+ const {scope} = path;
19
+ const {block} = scope;
20
+
21
+ if (!block.async)
22
+ block.async = true;
23
+
24
+ if (!scope.hasBinding('createMockImport')) {
25
+ const programScope = scope.getProgramParent();
26
+ const programPath = programScope.path;
27
+
28
+ maybeRemoveOldStopAll(scope);
29
+
30
+ const endOfImportPath = getPathAfterImports(programPath.get('body'));
31
+ insertBefore(endOfImportPath, initStopAll);
32
+ }
33
+
34
+ return 'await reImport(__a)';
35
+ },
36
+ });
37
+
38
+ function maybeRemoveOldStopAll(scope) {
39
+ const binding = scope.getBinding('stopAll');
40
+
41
+ if (!binding)
42
+ return;
43
+
44
+ const {path} = binding;
45
+
46
+ if (path) {
47
+ remove(path);
48
+ path.scope.crawl();
49
+ }
50
+ }
@@ -12,4 +12,3 @@ module.exports.replace = () => ({
12
12
  't.ok(__a.test(__b))': 't.match(__b, __a)',
13
13
  't.ok(__a.test(__b), __c)': 't.match(__b, __a, __c)',
14
14
  });
15
-
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const {template} = require('putout');
3
+ const {template, operator} = require('putout');
4
+ const {insertBefore} = operator;
4
5
 
5
6
  module.exports.report = () => 'try-catch should be used instead of t.throws';
6
7
 
@@ -21,6 +22,6 @@ function putTryCatch(__a, path) {
21
22
  `);
22
23
 
23
24
  tryCatchNode.declarations[0].init.arguments[0] = __a;
24
- path.insertBefore(tryCatchNode);
25
+
26
+ insertBefore(path, tryCatchNode);
25
27
  }
26
-
@@ -5,7 +5,6 @@ module.exports.declare = () => ({
5
5
  stub: 'import {stub} from "supertape"',
6
6
  Test: 'import {Test} from "supertape"',
7
7
  Stub: 'import {Stub} from "supertape"',
8
-
9
8
  mockImport: `const {mockImport} = createMockImport(import.meta.url)`,
10
9
  reImport: `const {reImport} = createMockImport(import.meta.url)`,
11
10
  mockRequire: `import mockRequire from 'mock-require'`,
package/lib/index.js CHANGED
@@ -1,42 +1,73 @@
1
1
  'use strict';
2
2
 
3
- const getRule = (a) => ({
4
- [a]: require(`./${a}`),
5
- });
3
+ const applyStub = require('./apply-stub');
4
+ const applyDestructuring = require('./apply-destructuring');
5
+ const applyWithName = require('./apply-with-name');
6
+ const addAwaitToReImport = require('./add-await-to-re-import');
7
+ const jest = require('./jest');
8
+ const syncWithName = require('./sync-with-name');
9
+ const convertTapeToSupertape = require('./convert-tape-to-supertape');
10
+ const convertThrowsToTryCatch = require('./convert-throws-to-try-catch');
11
+ const convertDoesNotThrowToTryCatch = require('./convert-does-not-throw-to-try-catch');
12
+ const convertCalledWithToCalledWithNoArgs = require('./convert-called-with-to-called-with-no-args');
13
+ const convertCalledWithArgs = require('./convert-called-with-args');
14
+ const convertCalledWithNoArgsToCalledWith = require('./convert-called-with-no-args-to-called-with');
15
+ const convertEmitterToPromise = require('./convert-emitter-to-promise');
16
+ const convertOkToMatch = require('./convert-ok-to-match');
17
+ const convertOkToCalledWith = require('./convert-ok-to-called-with');
18
+ const convertMatchRegexpToString = require('./convert-match-regexp-to-string');
19
+ const convertEqualToNotOk = require('./convert-equal-to-not-ok');
20
+ const convertEqualToDeepEqual = require('./convert-equal-to-deep-equal');
21
+ const convertEqualToOk = require('./convert-equal-to-ok');
22
+ const convertEqualToCalledOnce = require('./convert-equal-to-called-once');
23
+ const convertDeepEqualToEqual = require('./convert-deep-equal-to-equal');
24
+ const convertMockRequireToMockImport = require('./convert-mock-require-to-mock-import');
25
+ const addArgs = require('./add-args');
26
+ const declare = require('./declare');
27
+ const removeDefaultMessages = require('./remove-default-messages');
28
+ const removeUselessNotCalledArgs = require('./remove-useless-not-called-args');
29
+ const switchExpectedWithResult = require('./switch-expected-with-result');
30
+ const applyStubOperator = require('./apply-stub-operator');
31
+ const addTEnd = require('./add-t-end');
32
+ const addStopAll = require('./add-stop-all');
33
+ const removeStopAll = require('./remove-stop-all');
34
+ const removeUselessTEnd = require('./remove-useless-t-end');
35
+ const removeOnly = require('./remove-only');
36
+ const removeSkip = require('./remove-skip');
6
37
 
7
38
  module.exports.rules = {
8
- ...getRule('apply-stub'),
9
- ...getRule('apply-destructuring'),
10
- ...getRule('apply-with-name'),
11
- ...getRule('add-await-to-re-import'),
12
- ...getRule('jest'),
13
- ...getRule('sync-with-name'),
14
- ...getRule('convert-tape-to-supertape'),
15
- ...getRule('convert-throws-to-try-catch'),
16
- ...getRule('convert-does-not-throw-to-try-catch'),
17
- ...getRule('convert-called-with-to-called-with-no-args'),
18
- ...getRule('convert-called-with-args'),
19
- ...getRule('convert-called-with-no-args-to-called-with'),
20
- ...getRule('convert-emitter-to-promise'),
21
- ...getRule('convert-ok-to-match'),
22
- ...getRule('convert-ok-to-called-with'),
23
- ...getRule('convert-match-regexp-to-string'),
24
- ...getRule('convert-equal-to-not-ok'),
25
- ...getRule('convert-equal-to-deep-equal'),
26
- ...getRule('convert-equal-to-ok'),
27
- ...getRule('convert-equal-to-called-once'),
28
- ...getRule('convert-deep-equal-to-equal'),
29
- ...getRule('add-args'),
30
- ...getRule('declare'),
31
- ...getRule('remove-default-messages'),
32
- ...getRule('remove-useless-not-called-args'),
33
- ...getRule('switch-expected-with-result'),
34
- ...getRule('apply-stub-operator'),
35
- ...getRule('add-t-end'),
36
- ...getRule('add-stop-all'),
37
- ...getRule('remove-stop-all'),
38
- ...getRule('remove-useless-t-end'),
39
- ...getRule('remove-only'),
40
- ...getRule('remove-skip'),
39
+ 'apply-stub': applyStub,
40
+ 'apply-destructuring': applyDestructuring,
41
+ 'apply-with-name': applyWithName,
42
+ 'add-await-to-re-import': addAwaitToReImport,
43
+ jest,
44
+ 'sync-with-name': syncWithName,
45
+ 'convert-tape-to-supertape': convertTapeToSupertape,
46
+ 'convert-throws-to-try-catch': convertThrowsToTryCatch,
47
+ 'convert-does-not-throw-to-try-catch': convertDoesNotThrowToTryCatch,
48
+ 'convert-called-with-to-called-with-no-args': convertCalledWithToCalledWithNoArgs,
49
+ 'convert-called-with-args': convertCalledWithArgs,
50
+ 'convert-called-with-no-args-to-called-with': convertCalledWithNoArgsToCalledWith,
51
+ 'convert-emitter-to-promise': convertEmitterToPromise,
52
+ 'convert-ok-to-match': convertOkToMatch,
53
+ 'convert-ok-to-called-with': convertOkToCalledWith,
54
+ 'convert-match-regexp-to-string': convertMatchRegexpToString,
55
+ 'convert-equal-to-not-ok': convertEqualToNotOk,
56
+ 'convert-equal-to-deep-equal': convertEqualToDeepEqual,
57
+ 'convert-equal-to-ok': convertEqualToOk,
58
+ 'convert-equal-to-called-once': convertEqualToCalledOnce,
59
+ 'convert-deep-equal-to-equal': convertDeepEqualToEqual,
60
+ 'convert-mock-require-to-mock-import': convertMockRequireToMockImport,
61
+ 'add-args': addArgs,
62
+ declare,
63
+ 'remove-default-messages': removeDefaultMessages,
64
+ 'remove-useless-not-called-args': removeUselessNotCalledArgs,
65
+ 'switch-expected-with-result': switchExpectedWithResult,
66
+ 'apply-stub-operator': applyStubOperator,
67
+ 'add-t-end': addTEnd,
68
+ 'add-stop-all': addStopAll,
69
+ 'remove-stop-all': removeStopAll,
70
+ 'remove-useless-t-end': removeUselessTEnd,
71
+ 'remove-only': removeOnly,
72
+ 'remove-skip': removeSkip,
41
73
  };
42
-
package/lib/jest/index.js CHANGED
@@ -6,4 +6,3 @@ module.exports.replace = () => ({
6
6
  'it': 'test',
7
7
  'expect(__a).toEqual(__b)': 't.equal(__a, __b)',
8
8
  });
9
-
@@ -13,4 +13,3 @@ module.exports.replace = () => ({
13
13
  't.deepEqual(__a, __b, "should equal")': 't.deepEqual(__a, __b)',
14
14
  't.notDeepEqual(__a, __b, "should not deep equal")': 't.notDeepEqual(__a, __b)',
15
15
  });
16
-
@@ -15,4 +15,3 @@ module.exports.filter = (path) => {
15
15
  name: 'test',
16
16
  });
17
17
  };
18
-
@@ -15,4 +15,3 @@ module.exports.filter = (path) => {
15
15
  name: 'test',
16
16
  });
17
17
  };
18
-
@@ -11,10 +11,7 @@ const {
11
11
  TEST_ASYNC_SKIP,
12
12
  } = require('../test-signatures');
13
13
 
14
- const {
15
- traverse,
16
- remove,
17
- } = operator;
14
+ const {traverse, remove} = operator;
18
15
 
19
16
  module.exports.report = () => `Remove 'stopAll()' when you not calling 'reImport()'`;
20
17
 
@@ -26,7 +23,6 @@ module.exports.traverse = ({push}) => ({
26
23
  [TEST]: createTraverse(push),
27
24
  [TEST_ONLY]: createTraverse(push),
28
25
  [TEST_SKIP]: createTraverse(push),
29
-
30
26
  [TEST_ASYNC]: createTraverse(push),
31
27
  [TEST_ASYNC_ONLY]: createTraverse(push),
32
28
  [TEST_ASYNC_SKIP]: createTraverse(push),
@@ -83,4 +79,3 @@ function check(path) {
83
79
  stopAllPath,
84
80
  };
85
81
  }
86
-
@@ -5,4 +5,3 @@ module.exports.report = () => 'Remove useless "notCalled" args';
5
5
  module.exports.replace = () => ({
6
6
  't.notCalled(__a, __array)': 't.notCalled(__a)',
7
7
  });
8
-
@@ -1,10 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {operator} = require('putout');
4
- const {
5
- traverse,
6
- remove,
7
- } = operator;
4
+ const {traverse, remove} = operator;
8
5
 
9
6
  module.exports.report = () => `Avoid useless 't.end()'`;
10
7
 
@@ -28,4 +25,3 @@ module.exports.traverse = ({push}) => ({
28
25
  push(paths.pop());
29
26
  },
30
27
  });
31
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "11.1.0",
3
+ "version": "12.0.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",
@@ -31,18 +31,18 @@
31
31
  "putout"
32
32
  ],
33
33
  "devDependencies": {
34
- "@putout/test": "^6.0.0",
35
- "c8": "^7.5.0",
34
+ "@putout/test": "^7.0.0",
35
+ "c8": "^8.0.0",
36
36
  "eslint": "^8.0.1",
37
- "eslint-plugin-n": "^15.2.4",
38
- "eslint-plugin-putout": "^17.0.0",
37
+ "eslint-plugin-n": "^16.0.0",
38
+ "eslint-plugin-putout": "^21.0.0",
39
39
  "lerna": "^6.0.1",
40
40
  "madrun": "^9.0.0",
41
41
  "montag": "^1.2.1",
42
- "nodemon": "^2.0.1"
42
+ "nodemon": "^3.0.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "putout": ">=29"
45
+ "putout": ">=33"
46
46
  },
47
47
  "license": "MIT",
48
48
  "engines": {