Skip to content

Commit 8c24505

Browse files
committed
feature: @putout/plugin-tape: convert to ESM
1 parent 0ec1b47 commit 8c24505

File tree

77 files changed

+302
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+302
-434
lines changed

packages/plugin-tape/.putout.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
"declare": "off",
55
"regexp/apply-literal-notation": "off"
66
}
7+
},
8+
"rules": {
9+
"tape": "off"
710
}
8-
}
11+
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {addArgs} = operator;
5-
6-
module.exports = addArgs({
4+
const {
5+
report,
6+
fix,
7+
traverse,
8+
} = addArgs({
79
t: ['t', [
810
'test("__a", (__args) => __body)',
911
'test("__a", async (__args) => __body)',
@@ -13,3 +15,9 @@ module.exports = addArgs({
1315
'test.skip("__a", async (__args) => __body)',
1416
]],
1517
});
18+
19+
export {
20+
report,
21+
fix,
22+
traverse,
23+
};

packages/plugin-tape/lib/add-args/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as addArgs from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const addArgs = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['tape/add-args', addArgs],
97
],

packages/plugin-tape/lib/add-await-to-re-import/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
'use strict';
1+
import {types} from 'putout';
22

3-
const {types} = require('putout');
43
const {isFunction} = types;
54

6-
module.exports.report = () => `Call 'reImport()' using await`;
5+
export const report = () => `Call 'reImport()' using await`;
76

8-
module.exports.match = () => ({
7+
export const match = () => ({
98
'reImport(__a)': (vars, path) => {
109
const {parentPath} = path;
1110

1211
return !parentPath.isAwaitExpression();
1312
},
1413
});
1514

16-
module.exports.replace = () => ({
15+
export const replace = () => ({
1716
'reImport(__a)': (vars, path) => {
1817
const fnPath = path.findParent(isFunction);
1918

packages/plugin-tape/lib/add-await-to-re-import/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as addAwaitToReImport from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const addAwaitToReImport = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['tape/add-await-to-re-import', addAwaitToReImport],
97
],

packages/plugin-tape/lib/add-node-prefix-to-mock-require/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
'use strict';
2-
3-
const {isBuiltin} = require('node:module');
4-
const {operator, types} = require('putout');
1+
import {isBuiltin} from 'node:module';
2+
import {operator, types} from 'putout';
53

64
const {isStringLiteral} = types;
75
const {
86
getTemplateValues,
97
setLiteralValue,
108
} = operator;
119

12-
module.exports.report = ({__a}) => `Add 'node:' prefix: '${__a.value}' -> 'node:${__a.value}'`;
10+
export const report = ({__a}) => `Add 'node:' prefix: '${__a.value}' -> 'node:${__a.value}'`;
1311

14-
module.exports.fix = ({__a}) => {
12+
export const fix = ({__a}) => {
1513
setLiteralValue(__a, `node:${__a.value}`);
1614
};
1715

1816
const MOCK_REQUIRE = 'mockRequire(__a, __b)';
1917
const MOCK_IMPORT = 'mockImport(__a, __b)';
2018

21-
module.exports.traverse = ({push}) => ({
19+
export const traverse = ({push}) => ({
2220
[MOCK_REQUIRE]: createTraverser(push, MOCK_REQUIRE),
2321
[MOCK_IMPORT]: createTraverser(push, MOCK_IMPORT),
2422
});

packages/plugin-tape/lib/add-node-prefix-to-mock-require/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['add-node-prefix-to-mock-require', plugin],
97
],

packages/plugin-tape/lib/add-stop-all/index.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
1-
'use strict';
2-
3-
const {
1+
import {
42
types,
53
operator,
64
template,
7-
} = require('putout');
8-
9-
const {
5+
} from 'putout';
6+
import {
107
TEST,
118
TEST_ONLY,
129
TEST_SKIP,
1310
TEST_ASYNC,
1411
TEST_ASYNC_ONLY,
1512
TEST_ASYNC_SKIP,
16-
} = require('../test-signatures');
13+
} from '../test-signatures.js';
1714

18-
const {
19-
traverse,
20-
compare,
21-
insertBefore,
22-
} = operator;
15+
const {compare, insertBefore} = operator;
2316

2417
const {expressionStatement} = types;
2518

26-
module.exports.report = () => `Call 'stopAll()' at the end of test when 'mockImport()' used`;
19+
export const report = () => `Call 'stopAll()' at the end of test when 'mockImport()' used`;
2720

28-
module.exports.fix = (path) => {
21+
export const fix = (path) => {
2922
const assertionPath = getAssertionsPath(path);
3023
const stopAllNode = template.ast('stopAll()');
3124

3225
insertBefore(assertionPath, expressionStatement(stopAllNode));
3326
};
3427

35-
module.exports.traverse = ({push}) => ({
28+
export const traverse = ({push}) => ({
3629
[TEST]: createTraverse(push),
3730
[TEST_ONLY]: createTraverse(push),
3831
[TEST_SKIP]: createTraverse(push),
@@ -65,7 +58,7 @@ function check(path) {
6558
let hasMockImport = false;
6659
let hasAssertions = false;
6760

68-
traverse(path, {
61+
operator.traverse(path, {
6962
'mockImport(__a, __b)': () => {
7063
hasMockImport = true;
7164
},

0 commit comments

Comments
 (0)