@putout/plugin-tape 19.2.0 → 20.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 +7 -186
- package/lib/convert-called-with-no-args-to-called-with/index.js +1 -0
- package/lib/convert-deep-equal-to-equal/index.js +1 -1
- package/lib/convert-tape-to-supertape/index.js +1 -1
- package/lib/declare/index.js +0 -9
- package/lib/index.js +0 -8
- package/package.json +7 -7
- package/lib/add-await-to-re-import/index.js +0 -24
- package/lib/add-node-prefix-to-mock-require/index.js +0 -38
- package/lib/convert-mock-require-to-mock-import/index.js +0 -48
- package/lib/remove-stop-all/index.js +0 -78
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @putout/plugin-tape [![NPM version][NPMIMGURL]][NPMURL]
|
|
2
2
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-tape.svg?style=flat&longCache=true
|
|
4
|
-
[NPMURL]: https://npmjs.org/package/@putout/plugin-tape"npm"
|
|
4
|
+
[NPMURL]: https://npmjs.org/package/@putout/plugin-tape "npm"
|
|
5
5
|
|
|
6
6
|
> Tape-inspired TAP-compatible simplest high speed test runner with superpowers.
|
|
7
7
|
>
|
|
@@ -18,9 +18,6 @@ npm i @putout/plugin-tape -D
|
|
|
18
18
|
## Rules
|
|
19
19
|
|
|
20
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
21
|
- ✅ [add-t-end](#add-t-end);
|
|
25
22
|
- ✅ [apply-destructuring](#apply-destructuring);
|
|
26
23
|
- ✅ [apply-stub](#apply-stub);
|
|
@@ -37,7 +34,6 @@ npm i @putout/plugin-tape -D
|
|
|
37
34
|
- ✅ [convert-equal-to-ok](#convert-equal-to-ok);
|
|
38
35
|
- ✅ [convert-equals-to-equal](#convert-equals-to-equal);
|
|
39
36
|
- ✅ [convert-match-regexp-to-string](#convert-match-regexp-to-string);
|
|
40
|
-
- ✅ [convert-mock-require-to-mock-import](#convert-mock-require-to-mock-import);
|
|
41
37
|
- ✅ [convert-ok-to-called-with](#convert-ok-to-called-with);
|
|
42
38
|
- ✅ [convert-ok-to-match](#convert-ok-to-match);
|
|
43
39
|
- ✅ [convert-tape-to-supertape](#convert-tape-to-supertape);
|
|
@@ -47,7 +43,6 @@ npm i @putout/plugin-tape -D
|
|
|
47
43
|
- ✅ [remove-default-messages](#remove-default-messages);
|
|
48
44
|
- ✅ [remove-only](#remove-only);
|
|
49
45
|
- ✅ [remove-skip](#remove-skip);
|
|
50
|
-
- ✅ [remove-stop-all](# [remove-stop-all);
|
|
51
46
|
- ✅ [remove-useless-not-called-args](#remove-useless-not-called-args);
|
|
52
47
|
- ✅ [remove-useless-t-end](#remove-useless-t-end);
|
|
53
48
|
- ✅ [switch-expected-with-result](#switch-expected-with-result);
|
|
@@ -58,15 +53,11 @@ npm i @putout/plugin-tape -D
|
|
|
58
53
|
```json
|
|
59
54
|
{
|
|
60
55
|
"rules": {
|
|
61
|
-
"tape/convert-mock-require-to-mock-import": "off",
|
|
62
56
|
"tape/jest": "on",
|
|
63
57
|
"tape/apply-stub": "on",
|
|
64
58
|
"tape/apply-destructuring": "on",
|
|
65
59
|
"tape/apply-with-name": "on",
|
|
66
60
|
"tape/add-t-end": "on",
|
|
67
|
-
"tape/add-stop-all": "on",
|
|
68
|
-
"tape/add-await-to-re-import": "on",
|
|
69
|
-
"tape/add-node-prefix-to-mock-require": "on",
|
|
70
61
|
"tape/remove-useless-t-end": "on",
|
|
71
62
|
"tape/sync-with-name": "on",
|
|
72
63
|
"tape/switch-expected-with-result": "on",
|
|
@@ -89,8 +80,7 @@ npm i @putout/plugin-tape -D
|
|
|
89
80
|
"tape/remove-default-messages": "on",
|
|
90
81
|
"tape/remove-useless-not-called-args": "on",
|
|
91
82
|
"tape/remove-only": "on",
|
|
92
|
-
"tape/remove-skip": "on"
|
|
93
|
-
"tape/remove-stop-all": "on"
|
|
83
|
+
"tape/remove-skip": "on"
|
|
94
84
|
}
|
|
95
85
|
}
|
|
96
86
|
```
|
|
@@ -175,13 +165,13 @@ test('some message', (t) => {
|
|
|
175
165
|
### ✅ Example of correct code
|
|
176
166
|
|
|
177
167
|
```js
|
|
178
|
-
const tryCatch = require('try-catch');
|
|
168
|
+
const {tryCatch} = require('try-catch');
|
|
179
169
|
const test = require('supertape');
|
|
180
170
|
|
|
181
171
|
test('some message', (t) => {
|
|
182
172
|
const [error] = tryCatch(copymitter);
|
|
183
173
|
|
|
184
|
-
t.equal(error.message, 'from
|
|
174
|
+
t.equal(error.message, 'from should be a string!');
|
|
185
175
|
t.end();
|
|
186
176
|
});
|
|
187
177
|
```
|
|
@@ -203,7 +193,7 @@ test('some message', (t) => {
|
|
|
203
193
|
|
|
204
194
|
```js
|
|
205
195
|
const test = require('supertape');
|
|
206
|
-
const tryCatch = require('try-catch');
|
|
196
|
+
const {tryCatch} = require('try-catch');
|
|
207
197
|
|
|
208
198
|
test('some test', (t) => {
|
|
209
199
|
const [error] = tryCatch(copymitter);
|
|
@@ -495,38 +485,7 @@ test('should call init before show', (t) => {
|
|
|
495
485
|
|
|
496
486
|
## declare
|
|
497
487
|
|
|
498
|
-
###
|
|
499
|
-
|
|
500
|
-
#### ❌ Example of incorrect code
|
|
501
|
-
|
|
502
|
-
```js
|
|
503
|
-
import {stub} from 'supertape';
|
|
504
|
-
|
|
505
|
-
mockImport('fs/promises', {
|
|
506
|
-
readFile: stub().resolves(''),
|
|
507
|
-
});
|
|
508
|
-
```
|
|
509
|
-
|
|
510
|
-
##### ✅ Example of correct code
|
|
511
|
-
|
|
512
|
-
```js
|
|
513
|
-
import {stub} from 'supertape';
|
|
514
|
-
import {createMockImport} from 'mock-import';
|
|
515
|
-
|
|
516
|
-
const {
|
|
517
|
-
mockImport,
|
|
518
|
-
stopAll,
|
|
519
|
-
reImport,
|
|
520
|
-
} = createMockImport(import.meta.url);
|
|
521
|
-
|
|
522
|
-
mockImport('fs/promises', {
|
|
523
|
-
readFile: stub().resolves(''),
|
|
524
|
-
});
|
|
525
|
-
```
|
|
526
|
-
|
|
527
|
-
### `test`
|
|
528
|
-
|
|
529
|
-
#### ❌ Example of incorrect code
|
|
488
|
+
### ❌ Example of incorrect code
|
|
530
489
|
|
|
531
490
|
```js
|
|
532
491
|
test('xxx', (t) => {
|
|
@@ -535,7 +494,7 @@ test('xxx', (t) => {
|
|
|
535
494
|
});
|
|
536
495
|
```
|
|
537
496
|
|
|
538
|
-
|
|
497
|
+
### ✅ Example of correct code
|
|
539
498
|
|
|
540
499
|
```js
|
|
541
500
|
import {test, stub} from 'supertape';
|
|
@@ -546,26 +505,6 @@ test('xxx', (t) => {
|
|
|
546
505
|
});
|
|
547
506
|
```
|
|
548
507
|
|
|
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
|
-
|
|
569
508
|
## add-args
|
|
570
509
|
|
|
571
510
|
### ❌ Example of incorrect code
|
|
@@ -600,55 +539,6 @@ test('xxx', (t) => {
|
|
|
600
539
|
});
|
|
601
540
|
```
|
|
602
541
|
|
|
603
|
-
## add-await-to-re-import
|
|
604
|
-
|
|
605
|
-
### ❌ Example of incorrect code
|
|
606
|
-
|
|
607
|
-
```js
|
|
608
|
-
test('stop-all: should be called', (t) => {
|
|
609
|
-
const read = reImport('./read');
|
|
610
|
-
t.end();
|
|
611
|
-
});
|
|
612
|
-
```
|
|
613
|
-
|
|
614
|
-
### ✅ Example of correct code
|
|
615
|
-
|
|
616
|
-
```js
|
|
617
|
-
test('stop-all: should be called', async (t) => {
|
|
618
|
-
const read = await reImport('./read');
|
|
619
|
-
t.end();
|
|
620
|
-
});
|
|
621
|
-
```
|
|
622
|
-
|
|
623
|
-
## add-stop-all
|
|
624
|
-
|
|
625
|
-
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.
|
|
626
|
-
|
|
627
|
-
### ❌ Example of incorrect code
|
|
628
|
-
|
|
629
|
-
```js
|
|
630
|
-
test('stop-all: should be called', (t) => {
|
|
631
|
-
mockImport('fs/promises', {
|
|
632
|
-
readFile: stub(),
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
t.end();
|
|
636
|
-
});
|
|
637
|
-
```
|
|
638
|
-
|
|
639
|
-
### ✅ Example of correct code
|
|
640
|
-
|
|
641
|
-
```js
|
|
642
|
-
test('stop-all: should be called', (t) => {
|
|
643
|
-
mockImport('fs/promises', {
|
|
644
|
-
readFile: stub(),
|
|
645
|
-
});
|
|
646
|
-
|
|
647
|
-
stopAll();
|
|
648
|
-
t.end();
|
|
649
|
-
});
|
|
650
|
-
```
|
|
651
|
-
|
|
652
542
|
## remove-useless-t-end
|
|
653
543
|
|
|
654
544
|
### ❌ Example of incorrect code
|
|
@@ -853,75 +743,6 @@ test('some test', (t) => {
|
|
|
853
743
|
});
|
|
854
744
|
```
|
|
855
745
|
|
|
856
|
-
## remove-stop-all
|
|
857
|
-
|
|
858
|
-
When `reImport()` or `reRequire` not called, `stopAll()` is redundant and should be removed.
|
|
859
|
-
|
|
860
|
-
### ❌ Example of incorrect code
|
|
861
|
-
|
|
862
|
-
```js
|
|
863
|
-
test('some test', (t) => {
|
|
864
|
-
stopAll();
|
|
865
|
-
t.end();
|
|
866
|
-
});
|
|
867
|
-
```
|
|
868
|
-
|
|
869
|
-
### ✅ Example of correct code
|
|
870
|
-
|
|
871
|
-
```js
|
|
872
|
-
test('some test', (t) => {
|
|
873
|
-
t.end();
|
|
874
|
-
});
|
|
875
|
-
```
|
|
876
|
-
|
|
877
|
-
## convert-mock-import-to-require
|
|
878
|
-
|
|
879
|
-
Convert [mockRequire](https://github.com/boblauer/mock-require) to [mockImport](https://github.com/coderaiser/mock-import).
|
|
880
|
-
|
|
881
|
-
### ❌ Example of incorrect code
|
|
882
|
-
|
|
883
|
-
```js
|
|
884
|
-
const mockRequire = require('mock-require');
|
|
885
|
-
|
|
886
|
-
const {reRequire, stopAll} = mockRequire;
|
|
887
|
-
|
|
888
|
-
test('', (t) => {
|
|
889
|
-
mockRequire('fs/promises', {
|
|
890
|
-
unlink: stub(),
|
|
891
|
-
});
|
|
892
|
-
|
|
893
|
-
const fn = reRequire('..');
|
|
894
|
-
fn();
|
|
895
|
-
|
|
896
|
-
stopAll();
|
|
897
|
-
t.end();
|
|
898
|
-
});
|
|
899
|
-
```
|
|
900
|
-
|
|
901
|
-
### ✅ Example of correct code
|
|
902
|
-
|
|
903
|
-
```js
|
|
904
|
-
import {createMockImport} from 'mock-import';
|
|
905
|
-
|
|
906
|
-
const {
|
|
907
|
-
mockImport,
|
|
908
|
-
reImport,
|
|
909
|
-
stopAll,
|
|
910
|
-
} = createMockImport(import.meta.url);
|
|
911
|
-
|
|
912
|
-
test('', async (t) => {
|
|
913
|
-
mockImport('fs/promises', {
|
|
914
|
-
unlink: stub(),
|
|
915
|
-
});
|
|
916
|
-
|
|
917
|
-
const fn = await reImport('..');
|
|
918
|
-
fn();
|
|
919
|
-
|
|
920
|
-
stopAll();
|
|
921
|
-
t.end();
|
|
922
|
-
});
|
|
923
|
-
```
|
|
924
|
-
|
|
925
746
|
## License
|
|
926
747
|
|
|
927
748
|
MIT
|
|
@@ -5,4 +5,5 @@ export const replace = () => ({
|
|
|
5
5
|
't.calledWithNoArgs(__a, __array, __b)': 't.calledWith(__a, __array, __b)',
|
|
6
6
|
't.calledWithNoArgs(__a, __identifier)': 't.calledWith(__a, __identifier)',
|
|
7
7
|
't.calledWithNoArgs(__a, __identifier, __b)': 't.calledWith(__a, __identifier, __b)',
|
|
8
|
+
't.calledWithNoArgs(__a, __object)': 't.calledWith(__a, [__object])',
|
|
8
9
|
});
|
|
@@ -20,7 +20,7 @@ export const report = (path) => {
|
|
|
20
20
|
if (args.length === 2)
|
|
21
21
|
return `Use 't.equal(${args[0]}, ${args[1]})' instead of '${path}' when comparing with primitive`;
|
|
22
22
|
|
|
23
|
-
return `Use 't.equal(${args[0]}, ${args[1]}, ${args[2]})' instead of '${path} when
|
|
23
|
+
return `Use 't.equal(${args[0]}, ${args[1]}, ${args[2]})' instead of '${path} when comparing with primitive'`;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
const check = ({__b}, path) => {
|
package/lib/declare/index.js
CHANGED
|
@@ -3,13 +3,4 @@ export const declare = () => ({
|
|
|
3
3
|
stub: 'import {stub} from "supertape"',
|
|
4
4
|
Test: 'import {Test} from "supertape"',
|
|
5
5
|
Stub: 'import {Stub} from "supertape"',
|
|
6
|
-
mockImport: `const {mockImport} = createMockImport(import.meta.url)`,
|
|
7
|
-
reImport: `const {reImport} = createMockImport(import.meta.url)`,
|
|
8
|
-
mockRequire: `import mockRequire from 'mock-require'`,
|
|
9
|
-
reRequire: `const {reRequire} = mockRequire`,
|
|
10
|
-
stopAll: {
|
|
11
|
-
esm: `const {stopAll} = createMockImport(import.meta.url)`,
|
|
12
|
-
commonjs: `const {stopAll} = mockRequire`,
|
|
13
|
-
},
|
|
14
|
-
createMockImport: `import {createMockImport} from 'mock-import'`,
|
|
15
6
|
});
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as applyStub from './apply-stub/index.js';
|
|
2
2
|
import * as applyDestructuring from './apply-destructuring/index.js';
|
|
3
3
|
import * as applyWithName from './apply-with-name/index.js';
|
|
4
|
-
import * as addAwaitToReImport from './add-await-to-re-import/index.js';
|
|
5
4
|
import * as jest from './jest/index.js';
|
|
6
5
|
import * as syncWithName from './sync-with-name/index.js';
|
|
7
6
|
import * as convertTapeToSupertape from './convert-tape-to-supertape/index.js';
|
|
@@ -19,7 +18,6 @@ import * as convertEqualToDeepEqual from './convert-equal-to-deep-equal/index.js
|
|
|
19
18
|
import * as convertEqualToOk from './convert-equal-to-ok/index.js';
|
|
20
19
|
import * as convertEqualToCalledOnce from './convert-equal-to-called-once/index.js';
|
|
21
20
|
import * as convertDeepEqualToEqual from './convert-deep-equal-to-equal/index.js';
|
|
22
|
-
import * as convertMockRequireToMockImport from './convert-mock-require-to-mock-import/index.js';
|
|
23
21
|
import * as addArgs from './add-args/index.js';
|
|
24
22
|
import * as declare from './declare/index.js';
|
|
25
23
|
import * as removeDefaultMessages from './remove-default-messages/index.js';
|
|
@@ -27,19 +25,15 @@ import * as removeUselessNotCalledArgs from './remove-useless-not-called-args/in
|
|
|
27
25
|
import * as switchExpectedWithResult from './switch-expected-with-result/index.js';
|
|
28
26
|
import * as addTEnd from './add-t-end/index.js';
|
|
29
27
|
import * as addStopAll from './add-stop-all/index.js';
|
|
30
|
-
import * as removeStopAll from './remove-stop-all/index.js';
|
|
31
28
|
import * as removeUselessTEnd from './remove-useless-t-end/index.js';
|
|
32
29
|
import * as removeOnly from './remove-only/index.js';
|
|
33
30
|
import * as removeSkip from './remove-skip/index.js';
|
|
34
31
|
import * as convertEqualsToEqual from './convert-equals-to-equal/index.js';
|
|
35
|
-
import * as addNodePrefixToMockRequire from './add-node-prefix-to-mock-require/index.js';
|
|
36
32
|
|
|
37
33
|
export const rules = {
|
|
38
|
-
'convert-mock-require-to-mock-import': ['off', convertMockRequireToMockImport],
|
|
39
34
|
'apply-stub': applyStub,
|
|
40
35
|
'apply-destructuring': applyDestructuring,
|
|
41
36
|
'apply-with-name': applyWithName,
|
|
42
|
-
'add-await-to-re-import': addAwaitToReImport,
|
|
43
37
|
'jest': jest,
|
|
44
38
|
'sync-with-name': syncWithName,
|
|
45
39
|
'convert-tape-to-supertape': convertTapeToSupertape,
|
|
@@ -65,9 +59,7 @@ export const rules = {
|
|
|
65
59
|
'switch-expected-with-result': switchExpectedWithResult,
|
|
66
60
|
'add-t-end': addTEnd,
|
|
67
61
|
'add-stop-all': addStopAll,
|
|
68
|
-
'remove-stop-all': removeStopAll,
|
|
69
62
|
'remove-useless-t-end': removeUselessTEnd,
|
|
70
63
|
'remove-only': removeOnly,
|
|
71
64
|
'remove-skip': removeSkip,
|
|
72
|
-
'add-node-prefix-to-mock-require': addNodePrefixToMockRequire,
|
|
73
65
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-tape",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin helps with tests",
|
|
@@ -31,21 +31,21 @@
|
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@putout/plugin-putout": "*",
|
|
34
|
-
"@putout/test": "^
|
|
34
|
+
"@putout/test": "^15.0.0",
|
|
35
35
|
"c8": "^10.0.0",
|
|
36
|
-
"eslint": "^
|
|
36
|
+
"eslint": "^10.0.0-alpha.0",
|
|
37
37
|
"eslint-plugin-n": "^17.0.0",
|
|
38
|
-
"eslint-plugin-putout": "^
|
|
39
|
-
"madrun": "^
|
|
38
|
+
"eslint-plugin-putout": "^29.0.0",
|
|
39
|
+
"madrun": "^12.0.0",
|
|
40
40
|
"montag": "^1.2.1",
|
|
41
41
|
"nodemon": "^3.0.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"putout": ">=
|
|
44
|
+
"putout": ">=41"
|
|
45
45
|
},
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": ">=22"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {types} from 'putout';
|
|
2
|
-
|
|
3
|
-
const {isFunction} = types;
|
|
4
|
-
|
|
5
|
-
export const report = () => `Call 'reImport()' using await`;
|
|
6
|
-
|
|
7
|
-
export const match = () => ({
|
|
8
|
-
'reImport(__a)': (vars, path) => {
|
|
9
|
-
const {parentPath} = path;
|
|
10
|
-
|
|
11
|
-
return !parentPath.isAwaitExpression();
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export const replace = () => ({
|
|
16
|
-
'reImport(__a)': (vars, path) => {
|
|
17
|
-
const fnPath = path.findParent(isFunction);
|
|
18
|
-
|
|
19
|
-
if (fnPath)
|
|
20
|
-
fnPath.node.async = true;
|
|
21
|
-
|
|
22
|
-
return 'await reImport(__a)';
|
|
23
|
-
},
|
|
24
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {isBuiltin} from 'node:module';
|
|
2
|
-
import {operator, types} from 'putout';
|
|
3
|
-
|
|
4
|
-
const {isStringLiteral} = types;
|
|
5
|
-
const {
|
|
6
|
-
getTemplateValues,
|
|
7
|
-
setLiteralValue,
|
|
8
|
-
} = operator;
|
|
9
|
-
|
|
10
|
-
export const report = ({__a}) => `Add 'node:' prefix: '${__a.value}' -> 'node:${__a.value}'`;
|
|
11
|
-
|
|
12
|
-
export const fix = ({__a}) => {
|
|
13
|
-
setLiteralValue(__a, `node:${__a.value}`);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const MOCK_REQUIRE = 'mockRequire(__a, __b)';
|
|
17
|
-
const MOCK_IMPORT = 'mockImport(__a, __b)';
|
|
18
|
-
|
|
19
|
-
export const traverse = ({push}) => ({
|
|
20
|
-
[MOCK_REQUIRE]: createTraverser(push, MOCK_REQUIRE),
|
|
21
|
-
[MOCK_IMPORT]: createTraverser(push, MOCK_IMPORT),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const createTraverser = (push, template) => (path) => {
|
|
25
|
-
const {__a} = getTemplateValues(path, template);
|
|
26
|
-
|
|
27
|
-
if (!isStringLiteral(__a))
|
|
28
|
-
return;
|
|
29
|
-
|
|
30
|
-
if (__a.value.startsWith('node:'))
|
|
31
|
-
return;
|
|
32
|
-
|
|
33
|
-
if (isBuiltin(__a.value))
|
|
34
|
-
push({
|
|
35
|
-
path,
|
|
36
|
-
__a,
|
|
37
|
-
});
|
|
38
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {operator, template} from 'putout';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
remove,
|
|
5
|
-
getPathAfterImports,
|
|
6
|
-
insertBefore,
|
|
7
|
-
} = operator;
|
|
8
|
-
|
|
9
|
-
const initStopAll = template.ast(`const {stopAll} = createMockImport(import.meta.url)`);
|
|
10
|
-
|
|
11
|
-
export const report = () => '"mockImport" should be used instead of "mockRequire"';
|
|
12
|
-
|
|
13
|
-
export const replace = () => ({
|
|
14
|
-
'mockRequire(__a, __b)': 'mockImport(__a, __b)',
|
|
15
|
-
'reRequire(__a)': (vars, path) => {
|
|
16
|
-
const {scope} = path;
|
|
17
|
-
const {block} = scope;
|
|
18
|
-
|
|
19
|
-
if (!block.async)
|
|
20
|
-
block.async = true;
|
|
21
|
-
|
|
22
|
-
if (!scope.hasBinding('createMockImport')) {
|
|
23
|
-
const programScope = scope.getProgramParent();
|
|
24
|
-
const programPath = programScope.path;
|
|
25
|
-
|
|
26
|
-
maybeRemoveOldStopAll(scope);
|
|
27
|
-
|
|
28
|
-
const endOfImportPath = getPathAfterImports(programPath.get('body'));
|
|
29
|
-
insertBefore(endOfImportPath, initStopAll);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return 'await reImport(__a)';
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
function maybeRemoveOldStopAll(scope) {
|
|
37
|
-
const binding = scope.getBinding('stopAll');
|
|
38
|
-
|
|
39
|
-
if (!binding)
|
|
40
|
-
return;
|
|
41
|
-
|
|
42
|
-
const {path} = binding;
|
|
43
|
-
|
|
44
|
-
if (path) {
|
|
45
|
-
remove(path);
|
|
46
|
-
path.scope.crawl();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {operator} from 'putout';
|
|
2
|
-
import {
|
|
3
|
-
TEST,
|
|
4
|
-
TEST_ONLY,
|
|
5
|
-
TEST_SKIP,
|
|
6
|
-
TEST_ASYNC,
|
|
7
|
-
TEST_ASYNC_ONLY,
|
|
8
|
-
TEST_ASYNC_SKIP,
|
|
9
|
-
} from '../test-signatures.js';
|
|
10
|
-
|
|
11
|
-
const {remove} = operator;
|
|
12
|
-
|
|
13
|
-
export const report = () => `Remove 'stopAll()' when you not calling 'reImport()'`;
|
|
14
|
-
|
|
15
|
-
export const fix = (path) => {
|
|
16
|
-
remove(path);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const traverse = ({push}) => ({
|
|
20
|
-
[TEST]: createTraverse(push),
|
|
21
|
-
[TEST_ONLY]: createTraverse(push),
|
|
22
|
-
[TEST_SKIP]: createTraverse(push),
|
|
23
|
-
[TEST_ASYNC]: createTraverse(push),
|
|
24
|
-
[TEST_ASYNC_ONLY]: createTraverse(push),
|
|
25
|
-
[TEST_ASYNC_SKIP]: createTraverse(push),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const createTraverse = (push) => (path) => {
|
|
29
|
-
const {
|
|
30
|
-
hasReImport,
|
|
31
|
-
hasMockImport,
|
|
32
|
-
stopAllPath,
|
|
33
|
-
} = check(path);
|
|
34
|
-
|
|
35
|
-
if (hasReImport)
|
|
36
|
-
return;
|
|
37
|
-
|
|
38
|
-
if (hasMockImport)
|
|
39
|
-
return;
|
|
40
|
-
|
|
41
|
-
if (!stopAllPath)
|
|
42
|
-
return;
|
|
43
|
-
|
|
44
|
-
push(stopAllPath);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
function check(path) {
|
|
48
|
-
let hasReImport = false;
|
|
49
|
-
let hasMockImport = false;
|
|
50
|
-
let stopAllPath = null;
|
|
51
|
-
|
|
52
|
-
operator.traverse(path, {
|
|
53
|
-
'reImport(__a)': () => {
|
|
54
|
-
hasReImport = true;
|
|
55
|
-
},
|
|
56
|
-
'mockRequire(__a, __b)': () => {
|
|
57
|
-
hasMockImport = true;
|
|
58
|
-
},
|
|
59
|
-
'mockImport(__a, __b)': () => {
|
|
60
|
-
hasMockImport = true;
|
|
61
|
-
},
|
|
62
|
-
'traceImport(__a, __b)': () => {
|
|
63
|
-
hasReImport = true;
|
|
64
|
-
},
|
|
65
|
-
'reRequire(__a)': () => {
|
|
66
|
-
hasReImport = true;
|
|
67
|
-
},
|
|
68
|
-
'stopAll()': (path) => {
|
|
69
|
-
stopAllPath = path;
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
hasReImport,
|
|
75
|
-
hasMockImport,
|
|
76
|
-
stopAllPath,
|
|
77
|
-
};
|
|
78
|
-
}
|