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