@putout/plugin-tape 6.7.0 → 7.3.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,7 +432,38 @@ 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) => {
@@ -441,7 +472,7 @@ test('xxx', (t) => {
441
472
  });
442
473
  ```
443
474
 
444
- ### ✅ Correct code example
475
+ #### ✅ Correct code example
445
476
 
446
477
  ```js
447
478
  import {
@@ -4,5 +4,9 @@ const {operator} = require('putout');
4
4
  const {addArgs} = operator;
5
5
 
6
6
  module.exports = addArgs({
7
- t: ['t', 'test("__a", (__args) => __body)'],
7
+ t: ['t', [
8
+ 'test("__a", (__args) => __body)',
9
+ 'test("__a", async (__args) => __body)',
10
+ ],
11
+ ],
8
12
  });
@@ -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.7.0",
3
+ "version": "7.3.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": {