@putout/plugin-tape 6.6.0 → 7.2.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
@@ -432,17 +432,47 @@ test('should call init before show', (t) => {
432
432
 
433
433
  ## declare
434
434
 
435
- ### ❌ Incorrect code example
435
+ ### `mockImport`
436
+
437
+ #### ❌ Incorrect code example
438
+
439
+ ```js
440
+ import {stub} from 'supertape';
441
+
442
+ mockImport('fs/promises', {
443
+ readFile: stub().resolves(''),
444
+ });
445
+ ```
446
+
447
+ ##### ✅ Correct code Example
448
+
449
+ ```js
450
+ import {stub} from 'supertape';
451
+ import {createMockImport} from 'mock-import';
452
+
453
+ const {
454
+ mockImport,
455
+ stopAll,
456
+ reImport,
457
+ } = createMockImport(import.meta.url);
458
+
459
+ mockImport('fs/promises', {
460
+ readFile: stub().resolves(''),
461
+ });
462
+ ```
463
+
464
+ ### `tape`
465
+
466
+ #### ❌ Incorrect code example
436
467
 
437
468
  ```js
438
469
  test('xxx', (t) => {
439
470
  const a = stub();
440
-
441
471
  t.end();
442
472
  });
443
473
  ```
444
474
 
445
- ### ✅ Correct code example
475
+ #### ✅ Correct code example
446
476
 
447
477
  ```js
448
478
  import {
@@ -452,7 +482,6 @@ import {
452
482
 
453
483
  test('xxx', (t) => {
454
484
  const a = stub();
455
-
456
485
  t.end();
457
486
  });
458
487
  ```
@@ -523,7 +552,6 @@ test('stop-all: should be called', (t) => {
523
552
  mockImport('fs/promises', {
524
553
  readFile: stub(),
525
554
  });
526
-
527
555
  t.end();
528
556
  });
529
557
  ```
@@ -537,7 +565,6 @@ test('stop-all: should be called', (t) => {
537
565
  });
538
566
 
539
567
  stopAll();
540
-
541
568
  t.end();
542
569
  });
543
570
  ```
@@ -69,6 +69,9 @@ function check(path) {
69
69
  'mockImport(__a, __b)': () => {
70
70
  hasMockImport = true;
71
71
  },
72
+ 'mockRequire(__a, __b)': () => {
73
+ hasMockImport = true;
74
+ },
72
75
  'stopAll()': () => {
73
76
  hasStopAll = true;
74
77
  },
@@ -5,7 +5,7 @@ const {
5
5
  template,
6
6
  operator,
7
7
  } = require('putout');
8
- const {compare} = operator;
8
+ const {compare, traverse} = operator;
9
9
  const {ExpressionStatement} = types;
10
10
 
11
11
  module.exports.report = () => `'t.end()' is missing at the end of the test`;
@@ -20,7 +20,7 @@ module.exports.replace = () => ({
20
20
  'test(__a, async (t) => __body)': replace,
21
21
  });
22
22
 
23
- function match({__body}) {
23
+ function match({__body}, path) {
24
24
  const {body} = __body;
25
25
  const {length} = body;
26
26
 
@@ -32,7 +32,14 @@ function match({__body}) {
32
32
  return false;
33
33
  }
34
34
 
35
- return !compare(body[length - 1], 't.end()');
35
+ let found = false;
36
+ traverse(path, {
37
+ 't.end()': () => {
38
+ found = true;
39
+ },
40
+ });
41
+
42
+ return !found;
36
43
  }
37
44
 
38
45
  function replace({__body}, path) {
@@ -5,4 +5,14 @@ module.exports = {
5
5
  stub: 'import {stub} from "supertape"',
6
6
  Test: 'import {Test} from "supertape"',
7
7
  Stub: 'import {Stub} from "supertape"',
8
+
9
+ mockImport: `const {mockImport} = createMockImport(import.meta.url)`,
10
+ reImport: `const {reImport} = createMockImport(import.meta.url)`,
11
+ mockRequire: `import mockRequire from 'mock-require'`,
12
+ reRequire: `const {reRequire} = mockRequire`,
13
+ stopAll: {
14
+ esm: `const {stopAll} = createMockImport(import.meta.url)`,
15
+ commonjs: `const {stopAll} = mockRequire`,
16
+ },
17
+ createMockImport: `import {createMockImport} from 'mock-import'`,
8
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "6.6.0",
3
+ "version": "7.2.0",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
5
  "description": "putout plugin helps with tests",
6
6
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-tape",
@@ -33,18 +33,18 @@
33
33
  "putout"
34
34
  ],
35
35
  "devDependencies": {
36
- "@putout/test": "^3.0.0",
36
+ "@putout/test": "^4.0.0",
37
37
  "c8": "^7.5.0",
38
38
  "eslint": "^8.0.1",
39
39
  "eslint-plugin-node": "^11.0.0",
40
- "eslint-plugin-putout": "^11.0.0",
40
+ "eslint-plugin-putout": "^12.0.0",
41
41
  "lerna": "^4.0.0",
42
42
  "madrun": "^8.0.1",
43
43
  "montag": "^1.2.1",
44
44
  "nodemon": "^2.0.1"
45
45
  },
46
46
  "peerDependencies": {
47
- "putout": ">=21"
47
+ "putout": ">=22.5"
48
48
  },
49
49
  "license": "MIT",
50
50
  "engines": {