@putout/plugin-tape 14.1.0 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -17,6 +17,44 @@ npm i @putout/plugin-tape -D
|
|
|
17
17
|
|
|
18
18
|
## Rules
|
|
19
19
|
|
|
20
|
+
- ✅ [add-args](#add-args);
|
|
21
|
+
- ✅ [add-await-to-re-import](#add-await-to-re-import);
|
|
22
|
+
- ✅ [add-node-prefix-to-mock-require](#add-node-prefix-to-mock-require);
|
|
23
|
+
- ✅ [add-stop-all](#add-stop-all);
|
|
24
|
+
- ✅ [add-t-end](#add-t-end);
|
|
25
|
+
- ✅ [apply-destructuring](#apply-destructuring);
|
|
26
|
+
- ✅ [apply-stub](#apply-stub);
|
|
27
|
+
- ✅ [apply-with-name](#apply-with-name);
|
|
28
|
+
- ✅ [convert-called-with-args](#convert-called-with-args);
|
|
29
|
+
- ✅ [convert-called-with-no-args-to-called-with](#convert-called-with-no-args-to-called-with);
|
|
30
|
+
- ✅ [convert-called-with-to-called-with-no-args](#convert-called-with-to-called-with-no-args);
|
|
31
|
+
- ✅ [convert-deep-equal-to-equal](#convert-deep-equal-to-equal);
|
|
32
|
+
- ✅ [convert-does-not-throw-to-try-catch](#convert-does-not-throw-to-try-catch);
|
|
33
|
+
- ✅ [convert-emitter-to-promise](#convert-emitter-to-promise);
|
|
34
|
+
- ✅ [convert-equal-to-called-once](#convert-equal-to-called-once);
|
|
35
|
+
- ✅ [convert-equal-to-deep-equal](#convert-equal-to-deep-equal);
|
|
36
|
+
- ✅ [convert-equal-to-not-ok](#convert-equal-to-not-ok);
|
|
37
|
+
- ✅ [convert-equal-to-ok](#convert-equal-to-ok);
|
|
38
|
+
- ✅ [convert-equals-to-equal](#convert-equals-to-equal);
|
|
39
|
+
- ✅ [convert-match-regexp-to-string](#convert-match-regexp-to-string);
|
|
40
|
+
- ✅ [convert-mock-require-to-mock-import](#convert-mock-require-to-mock-import);
|
|
41
|
+
- ✅ [convert-ok-to-called-with](#convert-ok-to-called-with);
|
|
42
|
+
- ✅ [convert-ok-to-match](#convert-ok-to-match);
|
|
43
|
+
- ✅ [convert-tape-to-supertape](#convert-tape-to-supertape);
|
|
44
|
+
- ✅ [convert-throws-to-try-catch](#convert-throws-to-try-catch);
|
|
45
|
+
- ✅ [declare](#declare);
|
|
46
|
+
- ✅ [jest](#jest);
|
|
47
|
+
- ✅ [remove-default-messages](#remove-default-messages);
|
|
48
|
+
- ✅ [remove-only](#remove-only);
|
|
49
|
+
- ✅ [remove-skip](#remove-skip);
|
|
50
|
+
- ✅ [remove-stop-all](# [remove-stop-all);
|
|
51
|
+
- ✅ [remove-useless-not-called-args](#remove-useless-not-called-args);
|
|
52
|
+
- ✅ [remove-useless-t-end](#remove-useless-t-end);
|
|
53
|
+
- ✅ [switch-expected-with-result](#switch-expected-with-result);
|
|
54
|
+
- ✅ [sync-with-name](#sync-with-name);
|
|
55
|
+
|
|
56
|
+
## Config
|
|
57
|
+
|
|
20
58
|
```json
|
|
21
59
|
{
|
|
22
60
|
"rules": {
|
|
@@ -24,11 +62,11 @@ npm i @putout/plugin-tape -D
|
|
|
24
62
|
"tape/jest": "on",
|
|
25
63
|
"tape/apply-stub": "on",
|
|
26
64
|
"tape/apply-destructuring": "on",
|
|
27
|
-
"tape/apply-stub-operator": "on",
|
|
28
65
|
"tape/apply-with-name": "on",
|
|
29
66
|
"tape/add-t-end": "on",
|
|
30
67
|
"tape/add-stop-all": "on",
|
|
31
68
|
"tape/add-await-to-re-import": "on",
|
|
69
|
+
"tape/add-node-prefix-to-mock-require": "on",
|
|
32
70
|
"tape/remove-useless-t-end": "on",
|
|
33
71
|
"tape/sync-with-name": "on",
|
|
34
72
|
"tape/switch-expected-with-result": "on",
|
|
@@ -350,7 +388,7 @@ test('copymitter', (t) => {
|
|
|
350
388
|
### ✅ Example of correct code
|
|
351
389
|
|
|
352
390
|
```js
|
|
353
|
-
const {once} = require('events');
|
|
391
|
+
const {once} = require('node:events');
|
|
354
392
|
|
|
355
393
|
test('copymitter', async (t) => {
|
|
356
394
|
const cp = copymitter(from, to, ['1']);
|
|
@@ -403,26 +441,6 @@ const c = stub().rejects(Error('hello'));
|
|
|
403
441
|
const d = stub().rejects(Error('hello'));
|
|
404
442
|
```
|
|
405
443
|
|
|
406
|
-
## apply-stub-operator
|
|
407
|
-
|
|
408
|
-
### ❌ Example of incorrect code
|
|
409
|
-
|
|
410
|
-
```js
|
|
411
|
-
test('some message', (t) => {
|
|
412
|
-
t.ok(fn.calledWith(a));
|
|
413
|
-
t.end();
|
|
414
|
-
});
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
### ✅ Example of correct code
|
|
418
|
-
|
|
419
|
-
```js
|
|
420
|
-
test('some message', (t) => {
|
|
421
|
-
t.calledWith(fn, [a]);
|
|
422
|
-
t.end();
|
|
423
|
-
});
|
|
424
|
-
```
|
|
425
|
-
|
|
426
444
|
## apply-with-name
|
|
427
445
|
|
|
428
446
|
### ❌ Example of incorrect code
|
|
@@ -528,6 +546,26 @@ test('xxx', (t) => {
|
|
|
528
546
|
});
|
|
529
547
|
```
|
|
530
548
|
|
|
549
|
+
## add-node-prefix-to-mock-require
|
|
550
|
+
|
|
551
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/38f43d1972b3ebe37597022b42024cd5/ccd8cf8a3ff4a30c6dccc528358f9439f1fd366e).
|
|
552
|
+
|
|
553
|
+
### ❌ Example of incorrect code
|
|
554
|
+
|
|
555
|
+
```js
|
|
556
|
+
mockRequire('fs/promises', {
|
|
557
|
+
readdir,
|
|
558
|
+
});
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
### ✅ Example of correct code
|
|
562
|
+
|
|
563
|
+
```js
|
|
564
|
+
mockRequire('node:fs/promises', {
|
|
565
|
+
readdir,
|
|
566
|
+
});
|
|
567
|
+
```
|
|
568
|
+
|
|
531
569
|
## add-args
|
|
532
570
|
|
|
533
571
|
### ❌ Example of incorrect code
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {isBuiltin} = require('node:module');
|
|
4
|
+
const {operator, types} = require('putout');
|
|
5
|
+
|
|
6
|
+
const {isStringLiteral} = types;
|
|
7
|
+
const {
|
|
8
|
+
getTemplateValues,
|
|
9
|
+
setLiteralValue,
|
|
10
|
+
} = operator;
|
|
11
|
+
|
|
12
|
+
module.exports.report = ({__a}) => `Add 'node:' prefix: '${__a.value}' -> 'node:${__a.value}'`;
|
|
13
|
+
|
|
14
|
+
module.exports.fix = ({__a}) => {
|
|
15
|
+
setLiteralValue(__a, `node:${__a.value}`);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const MOCK_REQUIRE = 'mockRequire(__a, __b)';
|
|
19
|
+
|
|
20
|
+
module.exports.traverse = ({push}) => ({
|
|
21
|
+
[MOCK_REQUIRE](path) {
|
|
22
|
+
const {__a} = getTemplateValues(path, MOCK_REQUIRE);
|
|
23
|
+
|
|
24
|
+
if (!isStringLiteral(__a))
|
|
25
|
+
return;
|
|
26
|
+
|
|
27
|
+
if (__a.value.startsWith('node:'))
|
|
28
|
+
return;
|
|
29
|
+
|
|
30
|
+
if (isBuiltin(__a.value))
|
|
31
|
+
push({
|
|
32
|
+
path,
|
|
33
|
+
__a,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -36,7 +36,9 @@ module.exports.replace = () => ({
|
|
|
36
36
|
|
|
37
37
|
function match({__body}) {
|
|
38
38
|
for (const codeLine of __body.body) {
|
|
39
|
-
const {
|
|
39
|
+
const {
|
|
40
|
+
expression = codeLine,
|
|
41
|
+
} = codeLine;
|
|
40
42
|
|
|
41
43
|
if (compare(expression, ON_END))
|
|
42
44
|
return true;
|
|
@@ -64,7 +66,9 @@ function replace({__a}, path) {
|
|
|
64
66
|
for (let i = 0; i < n; i++) {
|
|
65
67
|
let nodes = [];
|
|
66
68
|
const current = body[i];
|
|
67
|
-
const {
|
|
69
|
+
const {
|
|
70
|
+
expression = current,
|
|
71
|
+
} = current;
|
|
68
72
|
|
|
69
73
|
if (compare(expression, ON_ERROR))
|
|
70
74
|
nodes = getErrorNodes(expression);
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const {operator} = require('putout');
|
|
4
|
+
const {compare} = operator;
|
|
5
|
+
|
|
6
|
+
module.exports.report = (path) => {
|
|
7
|
+
if (compare(path, 't.ok(__args)'))
|
|
8
|
+
return `Use 't.calledWith()' instead of 't.ok()'`;
|
|
9
|
+
|
|
10
|
+
return `Use 't.notCalledWith()' instead of 't.notOk()'`;
|
|
11
|
+
};
|
|
4
12
|
|
|
5
13
|
module.exports.replace = () => ({
|
|
6
14
|
't.ok(__a.calledWith(__args))': 't.calledWith(__a, [__args])',
|
|
7
15
|
't.ok(__a.calledWith(__args), __b)': 't.calledWith(__a, [__args], __b)',
|
|
16
|
+
|
|
8
17
|
't.ok(__a.calledWith(...__b))': 't.calledWith(__a, __b)',
|
|
9
18
|
't.ok(__a.calledWith(...__b), __c)': 't.calledWith(__a, __b, __c)',
|
|
19
|
+
|
|
20
|
+
't.notOk(__a.called, __b)': 't.notCalled(__a, __b)',
|
|
21
|
+
't.ok(__a.calledWith(), __b)': 't.calledWithNoArgs(__a, __b)',
|
|
10
22
|
});
|
package/lib/index.js
CHANGED
|
@@ -27,7 +27,6 @@ const declare = require('./declare');
|
|
|
27
27
|
const removeDefaultMessages = require('./remove-default-messages');
|
|
28
28
|
const removeUselessNotCalledArgs = require('./remove-useless-not-called-args');
|
|
29
29
|
const switchExpectedWithResult = require('./switch-expected-with-result');
|
|
30
|
-
const applyStubOperator = require('./apply-stub-operator');
|
|
31
30
|
const addTEnd = require('./add-t-end');
|
|
32
31
|
const addStopAll = require('./add-stop-all');
|
|
33
32
|
const removeStopAll = require('./remove-stop-all');
|
|
@@ -35,6 +34,7 @@ const removeUselessTEnd = require('./remove-useless-t-end');
|
|
|
35
34
|
const removeOnly = require('./remove-only');
|
|
36
35
|
const removeSkip = require('./remove-skip');
|
|
37
36
|
const convertEqualsToEqual = require('./convert-equals-to-equal');
|
|
37
|
+
const addNodePrefixToMockRequire = require('./add-node-prefix-to-mock-require');
|
|
38
38
|
|
|
39
39
|
module.exports.rules = {
|
|
40
40
|
'convert-mock-require-to-mock-import': ['off', convertMockRequireToMockImport],
|
|
@@ -66,11 +66,11 @@ module.exports.rules = {
|
|
|
66
66
|
'remove-default-messages': removeDefaultMessages,
|
|
67
67
|
'remove-useless-not-called-args': removeUselessNotCalledArgs,
|
|
68
68
|
'switch-expected-with-result': switchExpectedWithResult,
|
|
69
|
-
'apply-stub-operator': applyStubOperator,
|
|
70
69
|
'add-t-end': addTEnd,
|
|
71
70
|
'add-stop-all': addStopAll,
|
|
72
71
|
'remove-stop-all': removeStopAll,
|
|
73
72
|
'remove-useless-t-end': removeUselessTEnd,
|
|
74
73
|
'remove-only': removeOnly,
|
|
75
74
|
'remove-skip': removeSkip,
|
|
75
|
+
'add-node-prefix-to-mock-require': addNodePrefixToMockRequire,
|
|
76
76
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-tape",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "15.0.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin helps with tests",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@putout/plugin-putout": "*",
|
|
35
|
-
"@putout/test": "^
|
|
36
|
-
"c8": "^
|
|
37
|
-
"eslint": "^9.0.0
|
|
38
|
-
"eslint-plugin-n": "^17.0.0
|
|
35
|
+
"@putout/test": "^11.0.0",
|
|
36
|
+
"c8": "^10.0.0",
|
|
37
|
+
"eslint": "^9.0.0",
|
|
38
|
+
"eslint-plugin-n": "^17.0.0",
|
|
39
39
|
"eslint-plugin-putout": "^22.0.0",
|
|
40
40
|
"lerna": "^6.0.1",
|
|
41
41
|
"madrun": "^10.0.0",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"nodemon": "^3.0.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"putout": ">=
|
|
46
|
+
"putout": ">=36"
|
|
47
47
|
},
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=18"
|
|
50
|
+
"node": ">=18.6"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports.report = () => 'Use Stub operator';
|
|
4
|
-
|
|
5
|
-
module.exports.replace = () => ({
|
|
6
|
-
't.ok(__a.calledWith(__b))': 't.calledWith(__a, [__b])',
|
|
7
|
-
't.ok(__a.calledWith(__b, __c))': 't.calledWith(__a, [__b, __c])',
|
|
8
|
-
't.ok(__a.calledWith(...__b))': 't.calledWith(__a, __b)',
|
|
9
|
-
't.ok(__a.calledWith(__b), __c)': 't.calledWith(__a, [__b], __c)',
|
|
10
|
-
't.ok(__a.calledWith(__b, __c), __d)': 't.calledWith(__a, [__b, __c], __d)',
|
|
11
|
-
't.ok(__a.calledWith(...__b), __c)': 't.calledWith(__a, __b, __c)',
|
|
12
|
-
't.notOk(__a.called, __b)': 't.notCalled(__a, __b)',
|
|
13
|
-
't.ok(__a.calledWith(), __b)': 't.calledWithNoArgs(__a, __b)',
|
|
14
|
-
});
|