@putout/plugin-tape 7.7.0 → 9.0.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,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
- [`Putout`](https://github.com/coderaiser/putout) plugin helps to apply best parctises for tests written with [supertape](https://github.com/coderaiser/supertape).
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
 
@@ -51,7 +51,7 @@ npm i @putout/plugin-tape -D
51
51
 
52
52
  ## switch-expected-with-result
53
53
 
54
- ### ❌ Incorrect code example
54
+ ### ❌ Example of incorrect code
55
55
 
56
56
  ```js
57
57
  test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
@@ -60,7 +60,7 @@ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
60
60
  });
61
61
  ```
62
62
 
63
- ### ✅ Correct code example
63
+ ### ✅ Example of correct code
64
64
 
65
65
  ```js
66
66
  test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
@@ -71,13 +71,13 @@ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
71
71
 
72
72
  ## convert-tape-to-supertape
73
73
 
74
- ### ❌ Incorrect code example
74
+ ### ❌ Example of incorrect code
75
75
 
76
76
  ```js
77
77
  const test = require('tape');
78
78
  ```
79
79
 
80
- ### ✅ Correct code example
80
+ ### ✅ Example of correct code
81
81
 
82
82
  ```js
83
83
  const test = require('supertape');
@@ -85,7 +85,7 @@ const test = require('supertape');
85
85
 
86
86
  ## convert-throws-to-try-catch
87
87
 
88
- ### ❌ Incorrect code example
88
+ ### ❌ Example of incorrect code
89
89
 
90
90
  ```js
91
91
  const test = require('supertape');
@@ -96,7 +96,7 @@ test('some message', (t) => {
96
96
  });
97
97
  ```
98
98
 
99
- ### ✅ Correct code example
99
+ ### ✅ Example of correct code
100
100
 
101
101
  ```js
102
102
  const tryCatch = require('try-catch');
@@ -112,7 +112,7 @@ test('some message', (t) => {
112
112
 
113
113
  ## convert-does-not-throw-to-try-catch
114
114
 
115
- ### ❌ Incorrect code example
115
+ ### ❌ Example of incorrect code
116
116
 
117
117
  ```js
118
118
  const test = require('supertape');
@@ -123,7 +123,7 @@ test('some message', (t) => {
123
123
  });
124
124
  ```
125
125
 
126
- ### ✅ Correct code example
126
+ ### ✅ Example of correct code
127
127
 
128
128
  ```js
129
129
  const test = require('supertape');
@@ -139,7 +139,7 @@ test('some test', (t) => {
139
139
 
140
140
  ## convert-called-with-args
141
141
 
142
- ### ❌ Incorrect code example
142
+ ### ❌ Example of incorrect code
143
143
 
144
144
  ```js
145
145
  const test = require('supertape');
@@ -155,7 +155,7 @@ test('some message', (t) => {
155
155
  });
156
156
  ```
157
157
 
158
- ### ✅ Correct code example
158
+ ### ✅ Example of correct code
159
159
 
160
160
  ```js
161
161
  const test = require('supertape');
@@ -175,7 +175,7 @@ test('some message', (t) => {
175
175
 
176
176
  No need to use [`equal`](https://github.com/coderaiser/supertape#tequalactual-expected-msg), [`supertape`](https://github.com/coderaiser/supertape) supports [`calledOnce`](https://github.com/coderaiser/supertape/tree/master/packages/operator-stub#tcalledoncefn--message).
177
177
 
178
- ### ❌ Incorrect code example
178
+ ### ❌ Example of incorrect code
179
179
 
180
180
  ```js
181
181
  const test = require('supertape');
@@ -191,7 +191,7 @@ test('some message', (t) => {
191
191
  });
192
192
  ```
193
193
 
194
- ### ✅ Correct code example
194
+ ### ✅ Example of correct code
195
195
 
196
196
  ```js
197
197
  const test = require('supertape');
@@ -211,7 +211,7 @@ test('some message', (t) => {
211
211
 
212
212
  Use [`equal`](https://github.com/coderaiser/supertape#tequalactual-expected-msg) when comparing with primitives, [`deepEqual`](https://github.com/coderaiser/supertape#tdeepequalactual-expected-msg) for [`Objects`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) and [`Arrays`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array);
213
213
 
214
- ### ❌ Incorrect code example
214
+ ### ❌ Example of incorrect code
215
215
 
216
216
  ```js
217
217
  const test = require('supertape');
@@ -223,7 +223,7 @@ test('some message', (t) => {
223
223
  });
224
224
  ```
225
225
 
226
- ### ✅ Correct code example
226
+ ### ✅ Example of correct code
227
227
 
228
228
  ```js
229
229
  const test = require('supertape');
@@ -237,7 +237,7 @@ test('some message', (t) => {
237
237
 
238
238
  ## convert-called-with-to-called-with-no-args
239
239
 
240
- ### ❌ Incorrect code example
240
+ ### ❌ Example of incorrect code
241
241
 
242
242
  ```js
243
243
  const test = require('supertape');
@@ -253,7 +253,7 @@ test('some message', (t) => {
253
253
  });
254
254
  ```
255
255
 
256
- ### ✅ Correct code example
256
+ ### ✅ Example of correct code
257
257
 
258
258
  ```js
259
259
  const test = require('supertape');
@@ -271,7 +271,7 @@ test('some message', (t) => {
271
271
 
272
272
  ## convert-called-with-no-args-to-called-with
273
273
 
274
- ### ❌ Incorrect code example
274
+ ### ❌ Example of incorrect code
275
275
 
276
276
  ```js
277
277
  const test = require('supertape');
@@ -287,7 +287,7 @@ test('some message', (t) => {
287
287
  });
288
288
  ```
289
289
 
290
- ### ✅ Correct code example
290
+ ### ✅ Example of correct code
291
291
 
292
292
  ```js
293
293
  const test = require('supertape');
@@ -305,7 +305,7 @@ test('some message', (t) => {
305
305
 
306
306
  ## convert-emitter-to-promise
307
307
 
308
- ### ❌ Incorrect code example
308
+ ### ❌ Example of incorrect code
309
309
 
310
310
  ```js
311
311
  test('copymitter', (t) => {
@@ -317,7 +317,7 @@ test('copymitter', (t) => {
317
317
  });
318
318
  ```
319
319
 
320
- ### ✅ Correct code example
320
+ ### ✅ Example of correct code
321
321
 
322
322
  ```js
323
323
  const {once} = require('events');
@@ -332,7 +332,7 @@ test('copymitter', async (t) => {
332
332
 
333
333
  ## expand-try-catch-arguments
334
334
 
335
- ### ❌ Incorrect code example
335
+ ### ❌ Example of incorrect code
336
336
 
337
337
  ```js
338
338
  import tryCatch from 'try-catch';
@@ -346,7 +346,7 @@ test('some message', (t) => {
346
346
  });
347
347
  ```
348
348
 
349
- ### ✅ Correct code example
349
+ ### ✅ Example of correct code
350
350
 
351
351
  ```js
352
352
  import tryCatch from 'try-catch';
@@ -361,7 +361,7 @@ test('some message', (t) => {
361
361
 
362
362
  ## apply-stub-operator
363
363
 
364
- ### ❌ Incorrect code example
364
+ ### ❌ Example of incorrect code
365
365
 
366
366
  ```js
367
367
  test('some message', (t) => {
@@ -370,7 +370,7 @@ test('some message', (t) => {
370
370
  });
371
371
  ```
372
372
 
373
- ### ✅ Correct code example
373
+ ### ✅ Example of correct code
374
374
 
375
375
  ```js
376
376
  test('some message', (t) => {
@@ -381,7 +381,7 @@ test('some message', (t) => {
381
381
 
382
382
  ## apply-with-name
383
383
 
384
- ### ❌ Incorrect code example
384
+ ### ❌ Example of incorrect code
385
385
 
386
386
  ```js
387
387
  test('should call init before show', (t) => {
@@ -393,7 +393,7 @@ test('should call init before show', (t) => {
393
393
  });
394
394
  ```
395
395
 
396
- ### ✅ Correct code example
396
+ ### ✅ Example of correct code
397
397
 
398
398
  ```js
399
399
  test('should call init before show', (t) => {
@@ -407,7 +407,7 @@ test('should call init before show', (t) => {
407
407
 
408
408
  ## sync-with-name
409
409
 
410
- ### ❌ Incorrect code example
410
+ ### ❌ Example of incorrect code
411
411
 
412
412
  ```js
413
413
  test('should call init before show', (t) => {
@@ -419,7 +419,7 @@ test('should call init before show', (t) => {
419
419
  });
420
420
  ```
421
421
 
422
- ### ✅ Correct code example
422
+ ### ✅ Example of correct code
423
423
 
424
424
  ```js
425
425
  test('should call init before show', (t) => {
@@ -435,7 +435,7 @@ test('should call init before show', (t) => {
435
435
 
436
436
  ### `mockImport`
437
437
 
438
- #### ❌ Incorrect code example
438
+ #### ❌ Example of incorrect code
439
439
 
440
440
  ```js
441
441
  import {stub} from 'supertape';
@@ -445,7 +445,7 @@ mockImport('fs/promises', {
445
445
  });
446
446
  ```
447
447
 
448
- ##### ✅ Correct code Example
448
+ ##### ✅ Example of correct code
449
449
 
450
450
  ```js
451
451
  import {stub} from 'supertape';
@@ -464,7 +464,7 @@ mockImport('fs/promises', {
464
464
 
465
465
  ### `tape`
466
466
 
467
- #### ❌ Incorrect code example
467
+ #### ❌ Example of incorrect code
468
468
 
469
469
  ```js
470
470
  test('xxx', (t) => {
@@ -473,7 +473,7 @@ test('xxx', (t) => {
473
473
  });
474
474
  ```
475
475
 
476
- #### ✅ Correct code example
476
+ #### ✅ Example of correct code
477
477
 
478
478
  ```js
479
479
  import {
@@ -489,7 +489,7 @@ test('xxx', (t) => {
489
489
 
490
490
  ## add-args
491
491
 
492
- ### ❌ Incorrect code example
492
+ ### ❌ Example of incorrect code
493
493
 
494
494
  ```js
495
495
  test('xxx', () => {
@@ -497,7 +497,7 @@ test('xxx', () => {
497
497
  });
498
498
  ```
499
499
 
500
- ### ✅ Correct code example
500
+ ### ✅ Example of correct code
501
501
 
502
502
  ```js
503
503
  test('xxx', (t) => {
@@ -507,14 +507,14 @@ test('xxx', (t) => {
507
507
 
508
508
  ## add-t-end
509
509
 
510
- ### ❌ Incorrect code example
510
+ ### ❌ Example of incorrect code
511
511
 
512
512
  ```js
513
513
  test('xxx', () => {
514
514
  });
515
515
  ```
516
516
 
517
- ### ✅ Correct code example
517
+ ### ✅ Example of correct code
518
518
 
519
519
  ```js
520
520
  test('xxx', (t) => {
@@ -524,7 +524,7 @@ test('xxx', (t) => {
524
524
 
525
525
  ## add-await-to-re-import
526
526
 
527
- ### ❌ Incorrect code example
527
+ ### ❌ Example of incorrect code
528
528
 
529
529
  ```js
530
530
  test('stop-all: should be called', (t) => {
@@ -533,7 +533,7 @@ test('stop-all: should be called', (t) => {
533
533
  });
534
534
  ```
535
535
 
536
- ### ✅ Correct code example
536
+ ### ✅ Example of correct code
537
537
 
538
538
  ```js
539
539
  test('stop-all: should be called', async (t) => {
@@ -546,7 +546,7 @@ test('stop-all: should be called', async (t) => {
546
546
 
547
547
  When you write test mocking `ESM` with [`mockImport()`](https://github.com/coderaiser/mock-import#mockimportname-mock) never forget to call [`stopAll()`](https://github.com/coderaiser/mock-import#stopall) when you no longer need it. This leads to bugs in tests which are hard to find, each test should be checked with the one which pass when called alone but fail when called with others.
548
548
 
549
- ### ❌ Incorrect code example
549
+ ### ❌ Example of incorrect code
550
550
 
551
551
  ```js
552
552
  test('stop-all: should be called', (t) => {
@@ -557,7 +557,7 @@ test('stop-all: should be called', (t) => {
557
557
  });
558
558
  ```
559
559
 
560
- ### ✅ Correct code example
560
+ ### ✅ Example of correct code
561
561
 
562
562
  ```js
563
563
  test('stop-all: should be called', (t) => {
@@ -572,7 +572,7 @@ test('stop-all: should be called', (t) => {
572
572
 
573
573
  ## remove-useless-t-end
574
574
 
575
- ### ❌ Incorrect code example
575
+ ### ❌ Example of incorrect code
576
576
 
577
577
  ```js
578
578
  test('test: remove me', () => {
@@ -581,7 +581,7 @@ test('test: remove me', () => {
581
581
  });
582
582
  ```
583
583
 
584
- ### ✅ Correct code example
584
+ ### ✅ Example of correct code
585
585
 
586
586
  ```js
587
587
  test('test: remove me', () => {
@@ -591,13 +591,13 @@ test('test: remove me', () => {
591
591
 
592
592
  ## convert-ok-to-match
593
593
 
594
- ### ❌ Incorrect code example
594
+ ### ❌ Example of incorrect code
595
595
 
596
596
  ```js
597
597
  t.ok(result.includes('hello'));
598
598
  ```
599
599
 
600
- ### ✅ Correct code example
600
+ ### ✅ Example of correct code
601
601
 
602
602
  ```js
603
603
  t.match(result, /hello/);
@@ -605,13 +605,13 @@ t.match(result, /hello/);
605
605
 
606
606
  ## convert-ok-to-match
607
607
 
608
- ### ❌ Incorrect code example
608
+ ### ❌ Example of incorrect code
609
609
 
610
610
  ```js
611
611
  t.ok(set.calledWith(1, 2));
612
612
  ```
613
613
 
614
- ### ✅ Correct code example
614
+ ### ✅ Example of correct code
615
615
 
616
616
  ```js
617
617
  t.calledWith(set, [1, 2]);
@@ -619,13 +619,13 @@ t.calledWith(set, [1, 2]);
619
619
 
620
620
  ## convert-equal-to-not-ok
621
621
 
622
- ### ❌ Incorrect code example
622
+ ### ❌ Example of incorrect code
623
623
 
624
624
  ```js
625
625
  t.equal(error, null);
626
626
  ```
627
627
 
628
- ### ✅ Correct code example
628
+ ### ✅ Example of correct code
629
629
 
630
630
  ```js
631
631
  t.notOk(error);
@@ -633,13 +633,13 @@ t.notOk(error);
633
633
 
634
634
  ## convert-equal-to-ok
635
635
 
636
- ### ❌ Incorrect code example
636
+ ### ❌ Example of incorrect code
637
637
 
638
638
  ```js
639
639
  t.equal(result, true);
640
640
  ```
641
641
 
642
- ### ✅ Correct code example
642
+ ### ✅ Example of correct code
643
643
 
644
644
  ```js
645
645
  t.ok(result);
@@ -647,7 +647,7 @@ t.ok(result);
647
647
 
648
648
  ## convert-equal-to-deep-equal
649
649
 
650
- ### ❌ Incorrect code example
650
+ ### ❌ Example of incorrect code
651
651
 
652
652
  ```js
653
653
  const expected = {
@@ -658,7 +658,7 @@ t.equal(error, expected);
658
658
  t.end();
659
659
  ```
660
660
 
661
- ### ✅ Correct code example
661
+ ### ✅ Example of correct code
662
662
 
663
663
  ```js
664
664
  const expected = {
@@ -671,13 +671,13 @@ t.end();
671
671
 
672
672
  ## convert-match-regexp-to-string
673
673
 
674
- ### ❌ Incorrect code example
674
+ ### ❌ Example of incorrect code
675
675
 
676
676
  ```js
677
677
  t.match(result, RegExp('hello'));
678
678
  ```
679
679
 
680
- ### ✅ Correct code example
680
+ ### ✅ Example of correct code
681
681
 
682
682
  ```js
683
683
  t.match(result, 'hello');
@@ -688,13 +688,13 @@ t.match(result, 'hello');
688
688
  `supertape` will put this information for you, and it is always the same.
689
689
  No need to repeat the same information twice on one line, better to avoid it.
690
690
 
691
- ### ❌ Incorrect code example
691
+ ### ❌ Example of incorrect code
692
692
 
693
693
  ```js
694
694
  t.equal(result, expected, 'should equal');
695
695
  ```
696
696
 
697
- ### ✅ Correct code example
697
+ ### ✅ Example of correct code
698
698
 
699
699
  ```js
700
700
  t.equal(result, expected);
@@ -702,13 +702,13 @@ t.equal(result, expected);
702
702
 
703
703
  ## remove-useless-not-called-args
704
704
 
705
- ### ❌ Incorrect code example
705
+ ### ❌ Example of incorrect code
706
706
 
707
707
  ```js
708
708
  t.notCalled(fn, []);
709
709
  ```
710
710
 
711
- ### ✅ Correct code example
711
+ ### ✅ Example of correct code
712
712
 
713
713
  ```js
714
714
  t.notCalled(fn);
@@ -716,7 +716,7 @@ t.notCalled(fn);
716
716
 
717
717
  ## remove-only
718
718
 
719
- ### ❌ Incorrect code example
719
+ ### ❌ Example of incorrect code
720
720
 
721
721
  ```js
722
722
  test.only('some test', (t) => {
@@ -725,7 +725,7 @@ test.only('some test', (t) => {
725
725
 
726
726
  ```
727
727
 
728
- ### ✅ Correct code Example
728
+ ### ✅ Example of correct code
729
729
 
730
730
  ```js
731
731
  test('some test', (t) => {
@@ -735,7 +735,7 @@ test('some test', (t) => {
735
735
 
736
736
  ## remove-skip
737
737
 
738
- ### ❌ Incorrect code example
738
+ ### ❌ Example of incorrect code
739
739
 
740
740
  ```js
741
741
  test.skip('some test', (t) => {
@@ -748,7 +748,7 @@ test.skip('some test', (t) => {
748
748
 
749
749
  When `reImport()` or `reRequire` not called, `stopAll()` is redundant and should be removed.
750
750
 
751
- ### ❌ Incorrect code example
751
+ ### ❌ Example of incorrect code
752
752
 
753
753
  ```js
754
754
  test('some test', (t) => {
@@ -758,7 +758,7 @@ test('some test', (t) => {
758
758
 
759
759
  ```
760
760
 
761
- ### ✅ Correct code Example
761
+ ### ✅ Example of correct code
762
762
 
763
763
  ```js
764
764
  test('some test', (t) => {
@@ -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
 
@@ -1,15 +1,18 @@
1
1
  'use strict';
2
2
 
3
- module.exports.report = () => '"test.only" should not be used';
3
+ const {types} = require('putout');
4
+ const {isIdentifier} = types;
5
+
6
+ module.exports.report = () => `Remove 'test.only'`;
4
7
 
5
8
  module.exports.replace = () => ({
6
9
  '__a.only(__b, __c)': '__a(__b, __c)',
7
10
  '__a.only(__b, __c, __d)': '__a(__b, __c, __d)',
8
- '__a["only"](__b, __c)': '__a(__b, __c)',
9
11
  });
10
12
 
11
13
  module.exports.filter = (path) => {
12
- const {parentPath} = path.parentPath;
13
- return parentPath.isProgram();
14
+ return isIdentifier(path.node.callee.object, {
15
+ name: 'test',
16
+ });
14
17
  };
15
18
 
@@ -1,15 +1,19 @@
1
1
  'use strict';
2
2
 
3
- module.exports.report = () => '"test.skip" should not be used';
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
- const {parentPath} = path.parentPath;
13
- return parentPath.isProgram();
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": "7.7.0",
3
+ "version": "9.0.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",
@@ -31,22 +31,22 @@
31
31
  "putout"
32
32
  ],
33
33
  "devDependencies": {
34
- "@putout/test": "^4.0.0",
34
+ "@putout/test": "^5.0.0",
35
35
  "c8": "^7.5.0",
36
36
  "eslint": "^8.0.1",
37
37
  "eslint-plugin-node": "^11.0.0",
38
- "eslint-plugin-putout": "^13.0.0",
38
+ "eslint-plugin-putout": "^14.0.0",
39
39
  "lerna": "^4.0.0",
40
- "madrun": "^8.0.1",
40
+ "madrun": "^9.0.0",
41
41
  "montag": "^1.2.1",
42
42
  "nodemon": "^2.0.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "putout": ">=22.5"
45
+ "putout": ">=25"
46
46
  },
47
47
  "license": "MIT",
48
48
  "engines": {
49
- "node": ">=14"
49
+ "node": ">=16"
50
50
  },
51
51
  "publishConfig": {
52
52
  "access": "public"
@@ -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
-