Skip to content

Commit de6a1c3

Browse files
committed
feature: @putout/plugin-printer: remove-legacy-test-declaration: esm
1 parent ee2366e commit de6a1c3

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {extend} from 'supertape';
2+
import {printExtension} from '#test/printer';
3+
import {readFixtures} from '#test/fixture';
4+
5+
export const createTest = (dir) => {
6+
const fixture = readFixtures(dir);
7+
const test = extend({
8+
print: printExtension,
9+
});
10+
11+
return {
12+
fixture,
13+
test,
14+
};
15+
};
16+

packages/plugin-printer/lib/remove-legacy-test-declaration/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {operator} from 'putout';
22

3-
const {traverse} = operator;
4-
3+
const {compare} = operator;
54
const EXTEND = `
65
const test = extend({
76
print: printExtension,
@@ -25,13 +24,15 @@ export const replace = () => ({
2524
});
2625

2726
function check(vars, path) {
28-
let is = true;
2927
const programPath = path.scope.getProgramParent().path;
3028

31-
traverse(programPath, {
32-
'module.exports.createTest = (__args) => __body': () => {
33-
is = false;
34-
},
35-
});
36-
return is;
29+
for (const current of programPath.node.body) {
30+
if (compare(current, 'module.exports.createTest = (__args) => __body'))
31+
return false;
32+
33+
if (compare(current, 'export const createTest = (__args) => __body'))
34+
return false;
35+
}
36+
37+
return true;
3738
}

packages/plugin-printer/lib/remove-legacy-test-declaration/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ test('printer: remove-legacy-test-declaration: no report: create-test', (t) => {
3131
t.noReport('create-test');
3232
t.end();
3333
});
34+
35+
test('printer: remove-legacy-test-declaration: no report: esm', (t) => {
36+
t.noReport('esm');
37+
t.end();
38+
});

0 commit comments

Comments
 (0)