Skip to content

Commit e26fabd

Browse files
committed
feature: @putout/plugin-printer: remove-legacy-test-declaration: add
1 parent a8fc2b2 commit e26fabd

File tree

16 files changed

+156
-0
lines changed

16 files changed

+156
-0
lines changed

packages/plugin-printer/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ npm i @putout/plugin-printer -D
2020
-[apply-types](#apply-types);
2121
-[declare](#declare);
2222
-[remove-args](#remove-args);
23+
-[remove-legacy-test-declaration](#remove-legacy-test-declaration);
2324

2425
## Config
2526

@@ -123,15 +124,39 @@ print.indent();
123124

124125
```js
125126
isIdentifier();
127+
128+
test('', (t) => {
129+
t.print(fixture.returnStatement);
130+
});
126131
```
127132

128133
### ✅ Example of correct code
129134

130135
```js
131136
const {types} = require('@putout/babel');
137+
const {createTest} = require('#test');
138+
139+
const {test, fixture} = createTest(__dirname);
132140
const {isIdentifier} = types;
133141

134142
isIdentifier();
143+
144+
test('', (t) => {
145+
t.print(fixture.returnStatement);
146+
});
147+
```
148+
149+
## remove-legacy-test-declaration
150+
151+
```diff
152+
-const {printExtension} = require('../../../test/printer');
153+
-const {readFixtures} = require('../../../test/fixture');
154+
-
155+
-const fixture = readFixtures(__dirname);
156+
-
157+
-const test = extend({
158+
- print: printExtension,
159+
-});
135160
```
136161

137162
## License
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const {createTest} = require('#test');
2+
const {fixture} = createTest(__dirname);
3+
const {test} = createTest(__dirname);
4+
5+
test('', (t) => {
6+
t.print(fixture.returnStatement);
7+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test('', (t) => {
2+
t.print(fixture.returnStatement);
3+
});

packages/plugin-printer/lib/declare/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
const types = require('@putout/plugin-putout/declare/types');
44

55
module.exports.declare = () => ({
6+
createTest: `const {createTest} = require('#test')`,
7+
test: 'const {test} = createTest(__dirname)',
8+
fixture: 'const {fixture} = createTest(__dirname)',
69
types: `import {types} from '@putout/babel'`,
710
...types,
811
});

packages/plugin-printer/lib/declare/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ test('printer: declare: transform', (t) => {
1818
t.transform('declare');
1919
t.end();
2020
});
21+
22+
test('printer: declare: transform: create-test', (t) => {
23+
t.transform('create-test');
24+
t.end();
25+
});

packages/plugin-printer/lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const applyComputedPrint = require('./apply-computed-print');
77
const addArgs = require('./add-args');
88
const declare = require('./declare');
99
const applyTypes = require('./apply-types');
10+
const removeLegacyTestDeclaration = require('./remove-legacy-test-declaration');
1011

1112
module.exports.rules = {
1213
'remove-args': removeArgs,
@@ -16,4 +17,5 @@ module.exports.rules = {
1617
'add-args': addArgs,
1718
declare,
1819
'apply-types': applyTypes,
20+
'remove-legacy-test-declaration': removeLegacyTestDeclaration,
1921
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports.createTest = (dir) => {
2+
const fixture = readFixtures(dir);
3+
const test = extend({
4+
print: printExtension,
5+
});
6+
};
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const test = extend({
2+
chainAll: (operator) => (source, expected) => {
3+
return operator.chain(source, expected, {
4+
all: true,
5+
});
6+
},
7+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const test = switchCase.get('test');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)