@putout/plugin-tape 21.19.0 → 21.19.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
@@ -17,13 +17,12 @@ npm i @putout/plugin-tape -D
17
17
 
18
18
  ## Rules
19
19
 
20
- - ✅ [convert-ok-to-pass](#convert-ok-to-pass)
21
20
  - ✅ [add-args](#add-args);
22
21
  - ✅ [add-t-end](#add-t-end);
23
22
  - ✅ [apply-assertions-order](#apply-assertions-order);
24
23
  - ✅ [apply-destructuring](#apply-destructuring);
25
- - ✅ [apply-stub](#apply-stub);
26
24
  - ✅ [apply-stringify](#apply-stringify);
25
+ - ✅ [apply-stub](#apply-stub);
27
26
  - ✅ [apply-with-name](#apply-with-name);
28
27
  - ✅ [convert-called-with-args](#convert-called-with-args);
29
28
  - ✅ [convert-called-with-no-args-to-called-with](#convert-called-with-no-args-to-called-with);
@@ -31,12 +30,12 @@ npm i @putout/plugin-tape -D
31
30
  - ✅ [convert-deep-equal-to-equal](#convert-deep-equal-to-equal);
32
31
  - ✅ [convert-does-not-throw-to-try-catch](#convert-does-not-throw-to-try-catch);
33
32
  - ✅ [convert-emitter-to-promise](#convert-emitter-to-promise);
33
+ - ✅ [convert-equal-length-to-match-string](#convert-equal-length-to-match-string);
34
34
  - ✅ [convert-equal-to-called-once](#convert-equal-to-called-once);
35
35
  - ✅ [convert-equal-to-deep-equal](#convert-equal-to-deep-equal);
36
36
  - ✅ [convert-equal-to-not-ok](#convert-equal-to-not-ok);
37
37
  - ✅ [convert-equal-to-ok](#convert-equal-to-ok);
38
38
  - ✅ [convert-equals-to-equal](#convert-equals-to-equal);
39
- - ✅ [convert-equal-length-to-match-string](#convert-equal-length-to-match-string);
40
39
  - ✅ [convert-match-regexp-to-string](#convert-match-regexp-to-string);
41
40
  - ✅ [convert-ok-to-called-with](#convert-ok-to-called-with);
42
41
  - ✅ [convert-ok-to-match](#convert-ok-to-match);
@@ -49,10 +48,10 @@ npm i @putout/plugin-tape -D
49
48
  - ✅ [remove-default-messages](#remove-default-messages);
50
49
  - ✅ [remove-only](#remove-only);
51
50
  - ✅ [remove-skip](#remove-skip);
51
+ - ✅ [remove-t-from-async](#remove-t-from-async);
52
52
  - ✅ [remove-useless-not-called-args](#remove-useless-not-called-args);
53
53
  - ✅ [remove-useless-t-end](#remove-useless-t-end);
54
54
  - ✅ [remove-useless-undefined](#remove-useless-undefined);
55
- - ✅ [remove-t-from-async](#remove-t-from-async);
56
55
  - ✅ [switch-expected-with-result](#switch-expected-with-result);
57
56
  - ✅ [sync-with-name](#sync-with-name);
58
57
 
@@ -61,150 +60,198 @@ npm i @putout/plugin-tape -D
61
60
  ```json
62
61
  {
63
62
  "rules": {
64
- "tape/jest": "on",
65
- "tape/apply-stub": "on",
66
- "tape/apply-stringify": "on",
63
+ "tape/add-args": "on",
64
+ "tape/add-t-end": "on",
67
65
  "tape/apply-assertions-order": "on",
68
66
  "tape/apply-destructuring": "on",
67
+ "tape/apply-stringify": "on",
68
+ "tape/apply-stub": "on",
69
+
69
70
  "tape/apply-with-name": "on",
70
- "tape/add-t-end": "on",
71
- "tape/remove-useless-t-end": "on",
72
- "tape/sync-with-name": "on",
73
- "tape/switch-expected-with-result": "on",
74
- "tape/convert-tape-to-supertape": "on",
75
- "tape/convert-throws-to-try-catch": "on",
76
- "tape/convert-does-not-throw-to-try-catch": "on",
71
+
77
72
  "tape/convert-called-with-args": "on",
78
- "tape/convert-called-with-to-called-with-no-args": "on",
73
+
79
74
  "tape/convert-called-with-no-args-to-called-with": "on",
75
+ "tape/convert-called-with-to-called-with-no-args": "on",
76
+
77
+ "tape/convert-deep-equal-to-equal": "on",
78
+ "tape/convert-does-not-throw-to-try-catch": "on",
79
+
80
+ "tape/convert-emitter-to-promise": "on",
81
+ "tape/convert-equal-length-to-match-string": "on",
80
82
  "tape/convert-equal-to-called-once": "on",
81
83
  "tape/convert-equal-to-deep-equal": "on",
82
84
  "tape/convert-equals-to-equal": "on",
83
- "tape/convert-equal-length-to-match-string": "on",
84
- "tape/convert-deep-equal-to-equal": "on",
85
- "tape/convert-emitter-to-promise": "on",
86
- "tape/convert-ok-to-match": "on",
87
- "tape/convert-ok-to-called-with": "on",
85
+
88
86
  "tape/convert-match-regexp-to-string": "on",
89
- "tape/add-args": "on",
87
+ "tape/convert-ok-to-called-with": "on",
88
+ "tape/convert-ok-to-match": "on",
89
+
90
+ "tape/convert-ok-to-pass": "on",
91
+ "tape/convert-tape-to-supertape": "on",
92
+ "tape/convert-throws-to-try-catch": "on",
93
+
90
94
  "tape/declare": "on",
91
95
  "tape/extract-args-from-called-with": "on",
96
+
97
+ "tape/extract-result-from-assertion": "on",
98
+ "tape/jest": "on",
99
+
92
100
  "tape/remove-default-messages": "on",
93
- "tape/remove-useless-not-called-args": "on",
94
- "tape/remove-useless-undefined": "on",
95
- "tape/remove-t-from-async": "on",
101
+
96
102
  "tape/remove-only": ["on", {
97
103
  "allowed": ["test"]
98
104
  }],
99
105
  "tape/remove-skip": ["on", {
100
106
  "allowed": ["test"]
101
107
  }],
102
- "tape/extract-result-from-assertion": "on",
103
- "tape/convert-ok-to-pass": "on"
108
+ "tape/remove-t-from-async": "on",
109
+ "tape/remove-useless-not-called-args": "on",
110
+ "tape/remove-useless-t-end": "on",
111
+
112
+ "tape/remove-useless-undefined": "on",
113
+ "tape/switch-expected-with-result": "on",
114
+ "tape/sync-with-name": "on"
104
115
  }
105
116
  }
106
117
  ```
107
118
 
108
- ## jest
109
-
110
- 🐊**Putout** gives ability to switch easily from [**Jest**](https://github.com/coderaiser/putout/blob/master/packages/plugin-jest/README.md#putoutplugin-jest-) to 📼**Supertape**. Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e610ded68d5808c2dbc09a1f84be8a96/c8f515668b5bdf16b58ef85c3ca13d93682f3ccb).
119
+ ## add-args
111
120
 
112
121
  ### ❌ Example of incorrect code
113
122
 
114
123
  ```js
115
- it('should equal', () => {
116
- expect(a).toEqual(b);
124
+ test('xxx', () => {
125
+ t.end();
126
+ });
127
+
128
+ test('hello: world', async () => {
129
+ const result = await get();
130
+
131
+ deepEqual(result, []);
117
132
  });
118
133
  ```
119
134
 
120
135
  ### ✅ Example of correct code
121
136
 
122
137
  ```js
123
- import {test} from 'supertape';
124
-
125
- test('should equal', () => {
126
- t.equal(a, b);
138
+ test('xxx', (t) => {
127
139
  t.end();
128
140
  });
129
- ```
130
-
131
- ## switch-expected-with-result
132
141
 
133
- 📼**Supertape** uses more natural way of
134
- comparing: first you pass `result` and then `expected`.
142
+ test('hello: world', async ({deepEqual}) => {
143
+ const result = await get();
144
+
145
+ deepEqual(result, []);
146
+ });
147
+ ```
135
148
 
136
- It gives you ability to use value instead of `expected` and
137
- understand code faster: no need to search for a second argument.
138
- While `result` is always a variable, so it most likely much shorter.
149
+ ## add-t-end
139
150
 
140
151
  ### ❌ Example of incorrect code
141
152
 
142
153
  ```js
143
- test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
144
- t.equal(expected, result);
145
- t.end();
146
- });
154
+ test('xxx', () => {});
147
155
  ```
148
156
 
149
157
  ### ✅ Example of correct code
150
158
 
151
159
  ```js
152
- test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
153
- t.equal(result, expected);
160
+ test('xxx', (t) => {
154
161
  t.end();
155
162
  });
156
163
  ```
157
164
 
158
- ## convert-tape-to-supertape
165
+ ## apply-assertions-order
166
+
167
+ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/0c0adae586448bd0921129275fb08891/c2f031920a3f1eb119c71b5ac3ba3c27ce1710ea).
159
168
 
160
169
  ### ❌ Example of incorrect code
161
170
 
162
171
  ```js
163
- const test = require('tape');
172
+ t.equal(result, expected);
173
+ cleanup();
174
+ t.end();
164
175
  ```
165
176
 
166
177
  ### ✅ Example of correct code
167
178
 
168
179
  ```js
169
- const test = require('supertape');
180
+ cleanup();
181
+
182
+ t.equal(result, expected);
183
+ t.end();
170
184
  ```
171
185
 
172
- ## convert-throws-to-try-catch
186
+ ## apply-destructuring
187
+
188
+ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/adf238850271c0a4ad917e71bab8757c/4ff416c3d9f3de0930339c7a4929eb4b62461d1a).
173
189
 
174
190
  ### ❌ Example of incorrect code
175
191
 
176
192
  ```js
177
193
  const test = require('supertape');
178
-
179
- test('some message', (t) => {
180
- t.throws(copymitter, /from should be a string!/, 'should throw when no args');
181
- t.end();
182
- });
183
194
  ```
184
195
 
185
196
  ### ✅ Example of correct code
186
197
 
187
198
  ```js
188
- const {tryCatch} = require('try-catch');
189
- const test = require('supertape');
199
+ const {test} = require('supertape');
200
+ ```
190
201
 
191
- test('some message', (t) => {
192
- const [error] = tryCatch(copymitter);
193
-
194
- t.equal(error.message, 'from should be a string!');
195
- t.end();
196
- });
202
+ ## apply-stringify
203
+
204
+ Checkout in 🐊[**Putout Editor**](https://putout.vercel.app/#/gist/6791411046ac930e7d53a8954ec1ac90/e3735554f156221a8f2661a447a9b4f7db8994e9)
205
+
206
+ ### ❌ Example of incorrect code
207
+
208
+ ```js
209
+ const read = stub().returns('{"checkCoverage": true}');
197
210
  ```
198
211
 
199
- ## convert-does-not-throw-to-try-catch
212
+ ### ✅ Example of correct code
213
+
214
+ ```js
215
+ const read = stub().returns(stringify({
216
+ checkCoverage: true,
217
+ }));
218
+ ```
219
+
220
+ ## apply-stub
221
+
222
+ Apply [stub](https://github.com/cloudcmd/stub) functions created. Look how it works in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d098a8c8d03a072a7f3981e3cfb1d7af/f1542bfa39513ac625b2a9cd9243cc06dee286c0).
200
223
 
201
224
  ### ❌ Example of incorrect code
202
225
 
203
226
  ```js
204
- const test = require('supertape');
227
+ const a = async () => true;
228
+ const b = async () => {};
229
+ const c = async () => throwError('hello');
205
230
 
206
- test('some message', (t) => {
207
- t.doesNotThrow(copymitter, 'should throw when no args');
231
+ const d = async () => {
232
+ throw Error('hello');
233
+ };
234
+ ```
235
+
236
+ ### ✅ Example of correct code
237
+
238
+ ```js
239
+ const a = stub().resolves(true);
240
+ const b = stub().resolves();
241
+ const c = stub().rejects(Error('hello'));
242
+ const d = stub().rejects(Error('hello'));
243
+ ```
244
+
245
+ ## apply-with-name
246
+
247
+ ### ❌ Example of incorrect code
248
+
249
+ ```js
250
+ test('should call init before show', (t) => {
251
+ const init = stub();
252
+ const show = stub();
253
+
254
+ t.calledInOrder([init, show]);
208
255
  t.end();
209
256
  });
210
257
  ```
@@ -212,13 +259,11 @@ test('some message', (t) => {
212
259
  ### ✅ Example of correct code
213
260
 
214
261
  ```js
215
- const test = require('supertape');
216
- const {tryCatch} = require('try-catch');
217
-
218
- test('some test', (t) => {
219
- const [error] = tryCatch(copymitter);
262
+ test('should call init before show', (t) => {
263
+ const init = stub().withName('init');
264
+ const show = stub().withName('show');
220
265
 
221
- t.notOk(error, 'should not throw when no args');
266
+ t.calledInOrder([init, show]);
222
267
  t.end();
223
268
  });
224
269
  ```
@@ -255,9 +300,7 @@ test('some message', (t) => {
255
300
  });
256
301
  ```
257
302
 
258
- ## convert-equal-to-called-once
259
-
260
- 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).
303
+ ## convert-called-with-no-args-to-called-with
261
304
 
262
305
  ### ❌ Example of incorrect code
263
306
 
@@ -269,7 +312,7 @@ test('some message', (t) => {
269
312
  const fn = stub();
270
313
  fn();
271
314
 
272
- t.equal(fn.callCount, 1);
315
+ t.calledWithNoArgs(fn, [1, 2]);
273
316
  t.end();
274
317
  });
275
318
  ```
@@ -284,14 +327,12 @@ test('some message', (t) => {
284
327
  const fn = stub();
285
328
  fn();
286
329
 
287
- t.calledOnce(fn);
330
+ t.calledWith(fn, [1, 2]);
288
331
  t.end();
289
332
  });
290
333
  ```
291
334
 
292
- ## convert-deep-equal-to-equal
293
-
294
- 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);
335
+ ## convert-called-with-to-called-with-no-args
295
336
 
296
337
  ### ❌ Example of incorrect code
297
338
 
@@ -300,7 +341,10 @@ const test = require('supertape');
300
341
  const {stub} = test;
301
342
 
302
343
  test('some message', (t) => {
303
- t.deepEqual(x, 5);
344
+ const fn = stub();
345
+ fn();
346
+
347
+ t.calledWith(fn);
304
348
  t.end();
305
349
  });
306
350
  ```
@@ -312,12 +356,17 @@ const test = require('supertape');
312
356
  const {stub} = test;
313
357
 
314
358
  test('some message', (t) => {
315
- t.equal(x, 5);
359
+ const fn = stub();
360
+ fn();
361
+
362
+ t.calledWithNoArgs(fn);
316
363
  t.end();
317
364
  });
318
365
  ```
319
366
 
320
- ## convert-called-with-to-called-with-no-args
367
+ ## convert-deep-equal-to-equal
368
+
369
+ 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);
321
370
 
322
371
  ### ❌ Example of incorrect code
323
372
 
@@ -326,10 +375,7 @@ const test = require('supertape');
326
375
  const {stub} = test;
327
376
 
328
377
  test('some message', (t) => {
329
- const fn = stub();
330
- fn();
331
-
332
- t.calledWith(fn);
378
+ t.deepEqual(x, 5);
333
379
  t.end();
334
380
  });
335
381
  ```
@@ -341,27 +387,20 @@ const test = require('supertape');
341
387
  const {stub} = test;
342
388
 
343
389
  test('some message', (t) => {
344
- const fn = stub();
345
- fn();
346
-
347
- t.calledWithNoArgs(fn);
390
+ t.equal(x, 5);
348
391
  t.end();
349
392
  });
350
393
  ```
351
394
 
352
- ## convert-called-with-no-args-to-called-with
395
+ ## convert-does-not-throw-to-try-catch
353
396
 
354
397
  ### ❌ Example of incorrect code
355
398
 
356
399
  ```js
357
400
  const test = require('supertape');
358
- const {stub} = test;
359
401
 
360
402
  test('some message', (t) => {
361
- const fn = stub();
362
- fn();
363
-
364
- t.calledWithNoArgs(fn, [1, 2]);
403
+ t.doesNotThrow(copymitter, 'should throw when no args');
365
404
  t.end();
366
405
  });
367
406
  ```
@@ -370,13 +409,12 @@ test('some message', (t) => {
370
409
 
371
410
  ```js
372
411
  const test = require('supertape');
373
- const {stub} = test;
412
+ const {tryCatch} = require('try-catch');
374
413
 
375
- test('some message', (t) => {
376
- const fn = stub();
377
- fn();
414
+ test('some test', (t) => {
415
+ const [error] = tryCatch(copymitter);
378
416
 
379
- t.calledWith(fn, [1, 2]);
417
+ t.notOk(error, 'should not throw when no args');
380
418
  t.end();
381
419
  });
382
420
  ```
@@ -409,243 +447,197 @@ test('copymitter', async (t) => {
409
447
  });
410
448
  ```
411
449
 
412
- ## apply-assertions-order
450
+ ## convert-equal-length-to-match-string
413
451
 
414
- Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/0c0adae586448bd0921129275fb08891/c2f031920a3f1eb119c71b5ac3ba3c27ce1710ea).
452
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/df8cdc1545ac527b79ecc9bbca98f0d5/167216bb0f2228f1d4214f2d55ef5acef2d96447).
415
453
 
416
454
  ### ❌ Example of incorrect code
417
455
 
418
456
  ```js
419
- t.equal(result, expected);
420
- cleanup();
421
- t.end();
457
+ test('hello: world', (t) => {
458
+ const count = (written.match(/## my-rule/) || []).length;
459
+
460
+ t.equal(count, 1);
461
+ t.end();
462
+ });
422
463
  ```
423
464
 
424
465
  ### ✅ Example of correct code
425
466
 
426
467
  ```js
427
- cleanup();
428
-
429
- t.equal(result, expected);
430
- t.end();
468
+ test('hello: world', (t) => {
469
+ t.match(written, /## my-rule/);
470
+ t.end();
471
+ });
431
472
  ```
432
473
 
433
- ## apply-destructuring
474
+ ## convert-equal-to-called-once
434
475
 
435
- Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/adf238850271c0a4ad917e71bab8757c/4ff416c3d9f3de0930339c7a4929eb4b62461d1a).
476
+ 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).
436
477
 
437
478
  ### ❌ Example of incorrect code
438
479
 
439
480
  ```js
440
481
  const test = require('supertape');
482
+ const {stub} = test;
483
+
484
+ test('some message', (t) => {
485
+ const fn = stub();
486
+ fn();
487
+
488
+ t.equal(fn.callCount, 1);
489
+ t.end();
490
+ });
441
491
  ```
442
492
 
443
493
  ### ✅ Example of correct code
444
494
 
445
495
  ```js
446
- const {test} = require('supertape');
447
- ```
496
+ const test = require('supertape');
497
+ const {stub} = test;
448
498
 
449
- ## apply-stub
499
+ test('some message', (t) => {
500
+ const fn = stub();
501
+ fn();
502
+
503
+ t.calledOnce(fn);
504
+ t.end();
505
+ });
506
+ ```
450
507
 
451
- Apply [stub](https://github.com/cloudcmd/stub) functions created. Look how it works in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d098a8c8d03a072a7f3981e3cfb1d7af/f1542bfa39513ac625b2a9cd9243cc06dee286c0).
508
+ ## convert-equal-to-deep-equal
452
509
 
453
510
  ### ❌ Example of incorrect code
454
511
 
455
512
  ```js
456
- const a = async () => true;
457
- const b = async () => {};
458
- const c = async () => throwError('hello');
459
-
460
- const d = async () => {
461
- throw Error('hello');
513
+ const expected = {
514
+ hello: 'world',
462
515
  };
516
+
517
+ t.equal(error, expected);
518
+ t.end();
463
519
  ```
464
520
 
465
521
  ### ✅ Example of correct code
466
522
 
467
523
  ```js
468
- const a = stub().resolves(true);
469
- const b = stub().resolves();
470
- const c = stub().rejects(Error('hello'));
471
- const d = stub().rejects(Error('hello'));
472
- ```
524
+ const expected = {
525
+ hello: 'world',
526
+ };
473
527
 
474
- ## apply-stringify
528
+ t.deepEqual(error, expected);
529
+ t.end();
530
+ ```
475
531
 
476
- Checkout in 🐊[**Putout Editor**](https://putout.vercel.app/#/gist/6791411046ac930e7d53a8954ec1ac90/e3735554f156221a8f2661a447a9b4f7db8994e9)
532
+ ## convert-equal-to-not-ok
477
533
 
478
534
  ### ❌ Example of incorrect code
479
535
 
480
536
  ```js
481
- const read = stub().returns('{"checkCoverage": true}');
537
+ t.equal(error, null);
482
538
  ```
483
539
 
484
540
  ### ✅ Example of correct code
485
541
 
486
542
  ```js
487
- const read = stub().returns(stringify({
488
- checkCoverage: true,
489
- }));
543
+ t.notOk(error);
490
544
  ```
491
545
 
492
- ## apply-with-name
546
+ ## convert-equal-to-ok
493
547
 
494
548
  ### ❌ Example of incorrect code
495
549
 
496
550
  ```js
497
- test('should call init before show', (t) => {
498
- const init = stub();
499
- const show = stub();
500
-
501
- t.calledInOrder([init, show]);
502
- t.end();
503
- });
551
+ t.equal(result, true);
504
552
  ```
505
553
 
506
554
  ### ✅ Example of correct code
507
555
 
508
556
  ```js
509
- test('should call init before show', (t) => {
510
- const init = stub().withName('init');
511
- const show = stub().withName('show');
512
-
513
- t.calledInOrder([init, show]);
514
- t.end();
515
- });
557
+ t.ok(result);
516
558
  ```
517
559
 
518
- ## sync-with-name
560
+ ## convert-equals-to-equal
561
+
562
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9a428ce99c5ec8966363a7a6da5bbba8/7441cbf7c8429b265259e7d67125fa138d7db19b).
519
563
 
520
564
  ### ❌ Example of incorrect code
521
565
 
522
566
  ```js
523
- test('should call init before show', (t) => {
524
- const init = stub().withName('show');
525
- const show = stub().withName('show');
526
-
527
- t.calledInOrder([init, show]);
528
- t.end();
529
- });
567
+ t.equals(e.message, 'token should be a string!', 'should throw');
530
568
  ```
531
569
 
532
570
  ### ✅ Example of correct code
533
571
 
534
572
  ```js
535
- test('should call init before show', (t) => {
536
- const init = stub().withName('init');
537
- const show = stub().withName('show');
538
-
539
- t.calledInOrder([init, show]);
540
- t.end();
541
- });
573
+ t.equal(e.message, 'token should be a string!', 'should throw');
542
574
  ```
543
575
 
544
- ## extract-args-from-called-with
545
-
546
- Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/1a4b8e28b15ada7c7ad17e544ae03e2a/c6ca31508b8d4f2572d6a0c65dfbfe28c53016b1).
576
+ ## convert-match-regexp-to-string
547
577
 
548
578
  ### ❌ Example of incorrect code
549
579
 
550
580
  ```js
551
- test('abc: def', (t) => {
552
- t.calledWith(executeFn, [
553
- ['tape', 'test.js'], {
554
- exit,
555
- },
556
- ]);
557
- });
581
+ t.match(result, RegExp('hello'));
558
582
  ```
559
583
 
560
584
  ### ✅ Example of correct code
561
585
 
562
586
  ```js
563
- test('abc: def', (t) => {
564
- const args = [
565
- ['tape', 'test.js'], {
566
- exit,
567
- },
568
- ];
569
-
570
- t.calledWith(executeFn, args);
571
- });
587
+ t.match(result, 'hello');
572
588
  ```
573
589
 
574
- ## declare
590
+ ## convert-ok-to-called-with
575
591
 
576
592
  ### ❌ Example of incorrect code
577
593
 
578
594
  ```js
579
- test('xxx', (t) => {
580
- const a = stub();
581
- t.end();
582
- });
595
+ t.ok(set.calledWith(1, 2));
583
596
  ```
584
597
 
585
598
  ### ✅ Example of correct code
586
599
 
587
600
  ```js
588
- import {test, stub} from 'supertape';
589
-
590
- test('xxx', (t) => {
591
- const a = stub();
592
- t.end();
593
- });
601
+ t.calledWith(set, [1, 2]);
594
602
  ```
595
603
 
596
- ## add-args
604
+ ## convert-ok-to-match
597
605
 
598
606
  ### ❌ Example of incorrect code
599
607
 
600
608
  ```js
601
- test('xxx', () => {
602
- t.end();
603
- });
604
-
605
- test('hello: world', async () => {
606
- const result = await get();
607
-
608
- deepEqual(result, []);
609
- });
609
+ t.ok(result.includes('hello'));
610
610
  ```
611
611
 
612
612
  ### ✅ Example of correct code
613
613
 
614
614
  ```js
615
- test('xxx', (t) => {
616
- t.end();
617
- });
618
-
619
- test('hello: world', async ({deepEqual}) => {
620
- const result = await get();
621
-
622
- deepEqual(result, []);
623
- });
615
+ t.match(result, /hello/);
624
616
  ```
625
617
 
626
- ## add-t-end
618
+ ## convert-tape-to-supertape
627
619
 
628
620
  ### ❌ Example of incorrect code
629
621
 
630
622
  ```js
631
- test('xxx', () => {});
623
+ const test = require('tape');
632
624
  ```
633
625
 
634
626
  ### ✅ Example of correct code
635
627
 
636
628
  ```js
637
- test('xxx', (t) => {
638
- t.end();
639
- });
629
+ const test = require('supertape');
640
630
  ```
641
631
 
642
- ## remove-useless-t-end
632
+ ## convert-throws-to-try-catch
643
633
 
644
634
  ### ❌ Example of incorrect code
645
635
 
646
636
  ```js
647
- test('test: remove me', () => {
648
- t.end();
637
+ const test = require('supertape');
638
+
639
+ test('some message', (t) => {
640
+ t.throws(copymitter, /from should be a string!/, 'should throw when no args');
649
641
  t.end();
650
642
  });
651
643
  ```
@@ -653,25 +645,24 @@ test('test: remove me', () => {
653
645
  ### ✅ Example of correct code
654
646
 
655
647
  ```js
656
- test('test: remove me', () => {
648
+ const {tryCatch} = require('try-catch');
649
+ const test = require('supertape');
650
+
651
+ test('some message', (t) => {
652
+ const [error] = tryCatch(copymitter);
653
+
654
+ t.equal(error.message, 'from should be a string!');
657
655
  t.end();
658
656
  });
659
657
  ```
660
658
 
661
- ## remove-t-from-async
659
+ ## declare
662
660
 
663
661
  ### ❌ Example of incorrect code
664
662
 
665
663
  ```js
666
- test('sqlite: all returns empty array', async (t) => {
667
- const db = await createDb();
668
- await db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY, x TEXT)');
669
- const rows = await db.all('SELECT x FROM t WHERE x = :x', {
670
- x: 'missing',
671
- });
672
-
673
- await t.dbAll(rows, []);
674
-
664
+ test('xxx', (t) => {
665
+ const a = stub();
675
666
  t.end();
676
667
  });
677
668
  ```
@@ -679,158 +670,191 @@ test('sqlite: all returns empty array', async (t) => {
679
670
  ### ✅ Example of correct code
680
671
 
681
672
  ```js
682
- test('sqlite: all returns empty array', async ({dbAll}) => {
683
- const db = await createDb();
684
- await db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY, x TEXT)');
685
- const rows = await db.all('SELECT x FROM t WHERE x = :x', {
686
- x: 'missing',
687
- });
688
-
689
- await dbAll(rows, []);
673
+ import {test, stub} from 'supertape';
674
+
675
+ test('xxx', (t) => {
676
+ const a = stub();
677
+ t.end();
690
678
  });
691
679
  ```
692
680
 
693
- ## remove-useless-undefined
681
+ ## extract-args-from-called-with
682
+
683
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/1a4b8e28b15ada7c7ad17e544ae03e2a/c6ca31508b8d4f2572d6a0c65dfbfe28c53016b1).
694
684
 
695
685
  ### ❌ Example of incorrect code
696
686
 
697
687
  ```js
698
- stub().returns(undefined);
699
- stub().resolves(undefined);
688
+ test('abc: def', (t) => {
689
+ t.calledWith(executeFn, [
690
+ ['tape', 'test.js'], {
691
+ exit,
692
+ },
693
+ ]);
694
+ });
700
695
  ```
701
696
 
702
697
  ### ✅ Example of correct code
703
698
 
704
699
  ```js
705
- stub();
706
- stub().resolves();
700
+ test('abc: def', (t) => {
701
+ const args = [
702
+ ['tape', 'test.js'], {
703
+ exit,
704
+ },
705
+ ];
706
+
707
+ t.calledWith(executeFn, args);
708
+ });
707
709
  ```
708
710
 
709
- ## convert-ok-to-match
711
+ ## extract-result-from-assertion
712
+
713
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/264bc87f56eae9aa2b2884ff64fe7a06/94836a115a072a18fd717d5454792c1895ab0476).
710
714
 
711
715
  ### ❌ Example of incorrect code
712
716
 
713
717
  ```js
714
- t.ok(result.includes('hello'));
718
+ t.notOk(screen.getByRole('button').disabled);
719
+
720
+ t.deepEqual(readState({
721
+ getItem,
722
+ }), {
723
+ a: 1,
724
+ });
715
725
  ```
716
726
 
717
727
  ### ✅ Example of correct code
718
728
 
719
729
  ```js
720
- t.match(result, /hello/);
721
- ```
730
+ const {disabled} = screen.getByRole('button');
731
+ t.notOk(disabled);
722
732
 
723
- ## convert-ok-to-called-with
733
+ const result = readState({
734
+ getItem,
735
+ });
724
736
 
725
- ### ❌ Example of incorrect code
737
+ const expected = {
738
+ a: 1,
739
+ };
726
740
 
727
- ```js
728
- t.ok(set.calledWith(1, 2));
741
+ t.deepEqual(result, expected);
729
742
  ```
730
743
 
731
- ### ✅ Example of correct code
732
-
733
- ```js
734
- t.calledWith(set, [1, 2]);
735
- ```
744
+ ## jest
736
745
 
737
- ## convert-equal-to-not-ok
746
+ 🐊**Putout** gives ability to switch easily from [**Jest**](https://github.com/coderaiser/putout/blob/master/packages/plugin-jest/README.md#putoutplugin-jest-) to 📼**Supertape**. Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e610ded68d5808c2dbc09a1f84be8a96/c8f515668b5bdf16b58ef85c3ca13d93682f3ccb).
738
747
 
739
748
  ### ❌ Example of incorrect code
740
749
 
741
750
  ```js
742
- t.equal(error, null);
751
+ it('should equal', () => {
752
+ expect(a).toEqual(b);
753
+ });
743
754
  ```
744
755
 
745
756
  ### ✅ Example of correct code
746
757
 
747
758
  ```js
748
- t.notOk(error);
749
- ```
750
-
751
- ## convert-equal-to-ok
752
-
753
- ### ❌ Example of incorrect code
759
+ import {test} from 'supertape';
754
760
 
755
- ```js
756
- t.equal(result, true);
761
+ test('should equal', () => {
762
+ t.equal(a, b);
763
+ t.end();
764
+ });
757
765
  ```
758
766
 
759
- ### ✅ Example of correct code
760
-
761
- ```js
762
- t.ok(result);
763
- ```
767
+ ## remove-default-messages
764
768
 
765
- ## convert-equal-to-deep-equal
769
+ 📼**Supertape** will put this information for you, and it is always the same.
770
+ No need to repeat the same information twice on one line, better to avoid it.
766
771
 
767
772
  ### ❌ Example of incorrect code
768
773
 
769
774
  ```js
770
- const expected = {
771
- hello: 'world',
772
- };
773
-
774
- t.equal(error, expected);
775
- t.end();
775
+ t.equal(result, expected, 'should equal');
776
776
  ```
777
777
 
778
778
  ### ✅ Example of correct code
779
779
 
780
780
  ```js
781
- const expected = {
782
- hello: 'world',
783
- };
784
-
785
- t.deepEqual(error, expected);
786
- t.end();
781
+ t.equal(result, expected);
787
782
  ```
788
783
 
789
- ## convert-equals-to-equal
790
-
791
- Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9a428ce99c5ec8966363a7a6da5bbba8/7441cbf7c8429b265259e7d67125fa138d7db19b).
784
+ ## remove-only
792
785
 
793
786
  ### ❌ Example of incorrect code
794
787
 
795
788
  ```js
796
- t.equals(e.message, 'token should be a string!', 'should throw');
789
+ test.only('some test', (t) => {
790
+ t.end();
791
+ });
792
+
793
+ testDeclareBeforeReference.only('some test', (t) => {
794
+ t.end();
795
+ });
797
796
  ```
798
797
 
799
798
  ### ✅ Example of correct code
800
799
 
801
800
  ```js
802
- t.equal(e.message, 'token should be a string!', 'should throw');
801
+ test('some test', (t) => {
802
+ t.end();
803
+ });
804
+
805
+ testDeclareBeforeReference('some test', (t) => {
806
+ t.end();
807
+ });
803
808
  ```
804
809
 
805
- ## convert-match-regexp-to-string
810
+ ## remove-skip
806
811
 
807
812
  ### ❌ Example of incorrect code
808
813
 
809
814
  ```js
810
- t.match(result, RegExp('hello'));
815
+ test.skip('some test', (t) => {
816
+ t.end();
817
+ });
811
818
  ```
812
819
 
813
820
  ### ✅ Example of correct code
814
821
 
815
822
  ```js
816
- t.match(result, 'hello');
823
+ test('some test', (t) => {
824
+ t.end();
825
+ });
817
826
  ```
818
827
 
819
- ## remove-default-messages
820
-
821
- 📼**Supertape** will put this information for you, and it is always the same.
822
- No need to repeat the same information twice on one line, better to avoid it.
828
+ ## remove-t-from-async
823
829
 
824
830
  ### ❌ Example of incorrect code
825
831
 
826
832
  ```js
827
- t.equal(result, expected, 'should equal');
833
+ test('sqlite: all returns empty array', async (t) => {
834
+ const db = await createDb();
835
+ await db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY, x TEXT)');
836
+ const rows = await db.all('SELECT x FROM t WHERE x = :x', {
837
+ x: 'missing',
838
+ });
839
+
840
+ await t.dbAll(rows, []);
841
+
842
+ t.end();
843
+ });
828
844
  ```
829
845
 
830
846
  ### ✅ Example of correct code
831
847
 
832
848
  ```js
833
- t.equal(result, expected);
849
+ test('sqlite: all returns empty array', async ({dbAll}) => {
850
+ const db = await createDb();
851
+ await db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY, x TEXT)');
852
+ const rows = await db.all('SELECT x FROM t WHERE x = :x', {
853
+ x: 'missing',
854
+ });
855
+
856
+ await dbAll(rows, []);
857
+ });
834
858
  ```
835
859
 
836
860
  ## remove-useless-not-called-args
@@ -847,16 +871,13 @@ t.notCalled(fn, []);
847
871
  t.notCalled(fn);
848
872
  ```
849
873
 
850
- ## remove-only
874
+ ## remove-useless-t-end
851
875
 
852
876
  ### ❌ Example of incorrect code
853
877
 
854
878
  ```js
855
- test.only('some test', (t) => {
879
+ test('test: remove me', () => {
856
880
  t.end();
857
- });
858
-
859
- testDeclareBeforeReference.only('some test', (t) => {
860
881
  t.end();
861
882
  });
862
883
  ```
@@ -864,77 +885,64 @@ testDeclareBeforeReference.only('some test', (t) => {
864
885
  ### ✅ Example of correct code
865
886
 
866
887
  ```js
867
- test('some test', (t) => {
868
- t.end();
869
- });
870
-
871
- testDeclareBeforeReference('some test', (t) => {
888
+ test('test: remove me', () => {
872
889
  t.end();
873
890
  });
874
891
  ```
875
892
 
876
- ## remove-skip
893
+ ## remove-useless-undefined
877
894
 
878
895
  ### ❌ Example of incorrect code
879
896
 
880
897
  ```js
881
- test.skip('some test', (t) => {
882
- t.end();
883
- });
898
+ stub().returns(undefined);
899
+ stub().resolves(undefined);
884
900
  ```
885
901
 
886
902
  ### ✅ Example of correct code
887
903
 
888
904
  ```js
889
- test('some test', (t) => {
890
- t.end();
891
- });
905
+ stub();
906
+ stub().resolves();
892
907
  ```
893
908
 
894
- ## extract-result-from-assertion
909
+ ## switch-expected-with-result
895
910
 
896
- Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/264bc87f56eae9aa2b2884ff64fe7a06/94836a115a072a18fd717d5454792c1895ab0476).
911
+ 📼**Supertape** uses more natural way of
912
+ comparing: first you pass `result` and then `expected`.
913
+
914
+ It gives you ability to use value instead of `expected` and
915
+ understand code faster: no need to search for a second argument.
916
+ While `result` is always a variable, so it most likely much shorter.
897
917
 
898
918
  ### ❌ Example of incorrect code
899
919
 
900
920
  ```js
901
- t.notOk(screen.getByRole('button').disabled);
902
-
903
- t.deepEqual(readState({
904
- getItem,
905
- }), {
906
- a: 1,
921
+ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
922
+ t.equal(expected, result);
923
+ t.end();
907
924
  });
908
925
  ```
909
926
 
910
927
  ### ✅ Example of correct code
911
928
 
912
929
  ```js
913
- const {disabled} = screen.getByRole('button');
914
- t.notOk(disabled);
915
-
916
- const result = readState({
917
- getItem,
930
+ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
931
+ t.equal(result, expected);
932
+ t.end();
918
933
  });
919
-
920
- const expected = {
921
- a: 1,
922
- };
923
-
924
- t.deepEqual(result, expected);
925
934
  ```
926
935
 
927
- ## convert-equal-length-to-match-string
928
-
929
- Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/df8cdc1545ac527b79ecc9bbca98f0d5/167216bb0f2228f1d4214f2d55ef5acef2d96447).
936
+ ## sync-with-name
930
937
 
931
938
  ### ❌ Example of incorrect code
932
939
 
933
940
  ```js
934
- test('hello: world', (t) => {
935
- const count = (written.match(/## my-rule/) || []).length;
941
+ test('should call init before show', (t) => {
942
+ const init = stub().withName('show');
943
+ const show = stub().withName('show');
936
944
 
937
- t.equal(count, 1);
945
+ t.calledInOrder([init, show]);
938
946
  t.end();
939
947
  });
940
948
  ```
@@ -942,8 +950,11 @@ test('hello: world', (t) => {
942
950
  ### ✅ Example of correct code
943
951
 
944
952
  ```js
945
- test('hello: world', (t) => {
946
- t.match(written, /## my-rule/);
953
+ test('should call init before show', (t) => {
954
+ const init = stub().withName('init');
955
+ const show = stub().withName('show');
956
+
957
+ t.calledInOrder([init, show]);
947
958
  t.end();
948
959
  });
949
960
  ```
@@ -4,6 +4,7 @@ const {
4
4
  isUnaryExpression,
5
5
  isThrowStatement,
6
6
  isBlockStatement,
7
+ isCallExpression,
7
8
  } = types;
8
9
 
9
10
  const REJECTS = template('stub().rejects(A)');
@@ -12,6 +13,9 @@ export const report = () => `Use 'stub()' instead of creating a function`;
12
13
 
13
14
  export const match = () => ({
14
15
  'async () => __a': ({__a}) => {
16
+ if (isCallExpression(__a))
17
+ return false;
18
+
15
19
  if (!isBlockStatement(__a))
16
20
  return true;
17
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "21.19.0",
3
+ "version": "21.19.1",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with tests",