@putout/plugin-tape 3.10.0 → 3.11.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 +29 -0
- package/lib/add-stop-all/index.js +85 -0
- package/lib/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ npm i @putout/plugin-tape -D
|
|
|
21
21
|
"tape/apply-stub-operator": "on",
|
|
22
22
|
"tape/apply-with-name": "on",
|
|
23
23
|
"tape/add-t-end": "on",
|
|
24
|
+
"tape/add-stop-all": "on",
|
|
24
25
|
"tape/remove-useless-t-end": "on",
|
|
25
26
|
"tape/sync-with-name": "on",
|
|
26
27
|
"tape/switch-expected-with-result": "on",
|
|
@@ -433,6 +434,34 @@ test('xxx', (t) => {
|
|
|
433
434
|
});
|
|
434
435
|
```
|
|
435
436
|
|
|
437
|
+
## add-stop-all
|
|
438
|
+
|
|
439
|
+
### ❌ Incorrect code example
|
|
440
|
+
|
|
441
|
+
```js
|
|
442
|
+
test('stop-all: should be called', () => {
|
|
443
|
+
mockImport('fs/promises', {
|
|
444
|
+
readFile: stub(),
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
t.end();
|
|
448
|
+
});
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### ✅ Correct code example
|
|
452
|
+
|
|
453
|
+
```js
|
|
454
|
+
test('stop-all: should be called', () => {
|
|
455
|
+
mockImport('fs/promises', {
|
|
456
|
+
readFile: stub(),
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
stopAll();
|
|
460
|
+
|
|
461
|
+
t.end();
|
|
462
|
+
});
|
|
463
|
+
```
|
|
464
|
+
|
|
436
465
|
## remove-useless-t-end
|
|
437
466
|
|
|
438
467
|
### ❌ Incorrect code example
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
types,
|
|
5
|
+
operator,
|
|
6
|
+
template,
|
|
7
|
+
} = require('putout');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
traverse,
|
|
11
|
+
compare,
|
|
12
|
+
} = operator;
|
|
13
|
+
|
|
14
|
+
const {ExpressionStatement} = types;
|
|
15
|
+
|
|
16
|
+
module.exports.report = () => `Call 'stopAll()' at the end of test when 'mockImport()' used`;
|
|
17
|
+
|
|
18
|
+
module.exports.fix = (path) => {
|
|
19
|
+
const assertionPath = getAssertionsPath(path);
|
|
20
|
+
const stopAllNode = template.ast('stopAll()');
|
|
21
|
+
|
|
22
|
+
assertionPath.insertBefore(ExpressionStatement(stopAllNode));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const TEST = 'test("__a", (t) => __body)';
|
|
26
|
+
|
|
27
|
+
module.exports.traverse = ({push}) => ({
|
|
28
|
+
[TEST]: (path) => {
|
|
29
|
+
const {
|
|
30
|
+
hasMockImport,
|
|
31
|
+
hasStopAll,
|
|
32
|
+
hasAssertions,
|
|
33
|
+
} = check(path);
|
|
34
|
+
|
|
35
|
+
if (!hasMockImport)
|
|
36
|
+
return;
|
|
37
|
+
|
|
38
|
+
if (!hasAssertions)
|
|
39
|
+
return;
|
|
40
|
+
|
|
41
|
+
if (hasStopAll)
|
|
42
|
+
return;
|
|
43
|
+
|
|
44
|
+
push(path);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function check(path) {
|
|
49
|
+
let hasStopAll = false;
|
|
50
|
+
let hasMockImport = false;
|
|
51
|
+
let hasAssertions = false;
|
|
52
|
+
|
|
53
|
+
traverse(path, {
|
|
54
|
+
'mockImport(__a, __b)': (path) => {
|
|
55
|
+
hasMockImport = true;
|
|
56
|
+
},
|
|
57
|
+
'stopAll()': () => {
|
|
58
|
+
hasStopAll = true;
|
|
59
|
+
},
|
|
60
|
+
't.__(__args)': () => {
|
|
61
|
+
hasAssertions = true;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
hasStopAll,
|
|
67
|
+
hasMockImport,
|
|
68
|
+
hasAssertions,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getAssertionsPath(path) {
|
|
73
|
+
const bodyPath = path.get('arguments.1.body.body');
|
|
74
|
+
let resultPath = null;
|
|
75
|
+
|
|
76
|
+
for (const pathEl of bodyPath) {
|
|
77
|
+
if (compare(pathEl, 't.__(__args)')) {
|
|
78
|
+
resultPath = pathEl;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return resultPath;
|
|
84
|
+
}
|
|
85
|
+
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-tape",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "putout plugin helps with tests",
|
|
6
6
|
"homepage": "http://github.com/coderaiser/putout",
|