@putout/test 13.3.0 → 14.0.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 +3 -3
- package/lib/fixture.js +10 -0
- package/lib/format/index.js +123 -0
- package/lib/test.js +7 -138
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -148,7 +148,7 @@ test('putout: test: reportWithOptions', (t) => {
|
|
|
148
148
|
Check no report of `filename.js` with `options`:
|
|
149
149
|
|
|
150
150
|
```js
|
|
151
|
-
test('putout: test:
|
|
151
|
+
test('putout: test: no report with options: remove-import', (t) => {
|
|
152
152
|
const cache = new Map();
|
|
153
153
|
|
|
154
154
|
t.noReportWithOptions('remove-import', {
|
|
@@ -163,7 +163,7 @@ test('putout: test: noReportWithOptions', (t) => {
|
|
|
163
163
|
Check transform of `filename.js` with `options`:
|
|
164
164
|
|
|
165
165
|
```js
|
|
166
|
-
test('putout: plugin: declare-undefined-variables: transform: parse', (t) => {
|
|
166
|
+
test('putout: plugin: declare-undefined-variables: transform with options: parse', (t) => {
|
|
167
167
|
t.transformWithOptions('parse', {
|
|
168
168
|
dismiss: [
|
|
169
169
|
'assign',
|
|
@@ -239,7 +239,7 @@ test('plugin-putout: check-replace-code: no report: import', (t) => {
|
|
|
239
239
|
Check error message of a plugin not produced
|
|
240
240
|
|
|
241
241
|
```js
|
|
242
|
-
test('test: no report after transform', (t) => {
|
|
242
|
+
test('test: no report after transform: file', (t) => {
|
|
243
243
|
t.noReportAfterTransform('file');
|
|
244
244
|
t.end();
|
|
245
245
|
});
|
package/lib/fixture.js
CHANGED
|
@@ -48,6 +48,16 @@ module.exports.writeFixFixture = ({full, code, extension}) => {
|
|
|
48
48
|
writeFileSync(`${full}-fix.${extension}`, code);
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
+
module.exports.writeFormatFixture = (full, code) => {
|
|
52
|
+
const {writeFileSync} = global.__putout_test_fs;
|
|
53
|
+
writeFileSync(`${full}-format`, code);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
module.exports.readFormatFixture = (full) => {
|
|
57
|
+
const {readFileSync} = global.__putout_test_fs;
|
|
58
|
+
return readFileSync(`${full}-format`, 'utf8');
|
|
59
|
+
};
|
|
60
|
+
|
|
51
61
|
module.exports.writeFixture = ({full, code, extension}) => {
|
|
52
62
|
const {writeFileSync} = global.__putout_test_fs;
|
|
53
63
|
writeFileSync(`${full}.${extension}`, code);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const process = require('node:process');
|
|
4
|
+
const {join} = require('node:path');
|
|
5
|
+
|
|
6
|
+
const putout = require('putout');
|
|
7
|
+
const currify = require('currify');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
readFixture,
|
|
11
|
+
writeFormatFixture,
|
|
12
|
+
readFormatFixture,
|
|
13
|
+
} = require('../fixture');
|
|
14
|
+
|
|
15
|
+
const isUpdate = () => Boolean(Number(process.env.UPDATE));
|
|
16
|
+
const {isArray} = Array;
|
|
17
|
+
|
|
18
|
+
module.exports.format = currify((dir, options, t) => async (formatter, name, formatterOptions = {}) => {
|
|
19
|
+
const full = join(dir, name);
|
|
20
|
+
const [input, isTS] = readFixture(full);
|
|
21
|
+
|
|
22
|
+
const {places} = putout(input, {
|
|
23
|
+
fixCount: 1,
|
|
24
|
+
isTS,
|
|
25
|
+
...options,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const report = putout.initReport();
|
|
29
|
+
|
|
30
|
+
const result = await report(formatter, {
|
|
31
|
+
formatterOptions,
|
|
32
|
+
name,
|
|
33
|
+
source: input,
|
|
34
|
+
places,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (isUpdate()) {
|
|
38
|
+
writeFormatFixture(full, result);
|
|
39
|
+
return t.pass('fixed fixture updated');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const expected = readFormatFixture(full);
|
|
43
|
+
|
|
44
|
+
const {is, output} = t.equal(result, expected);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
is,
|
|
48
|
+
output,
|
|
49
|
+
result,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
module.exports.noFormat = currify((dir, options, t) => async (formatter, name, formatterOptions = {}) => {
|
|
54
|
+
const full = join(dir, name);
|
|
55
|
+
const [input] = readFixture(full);
|
|
56
|
+
const {places} = putout(input, options);
|
|
57
|
+
|
|
58
|
+
const report = putout.initReport();
|
|
59
|
+
|
|
60
|
+
const result = await report(formatter, {
|
|
61
|
+
name,
|
|
62
|
+
places,
|
|
63
|
+
formatterOptions,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const {is, output} = t.equal(result, '', 'should not format');
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
is,
|
|
70
|
+
output,
|
|
71
|
+
result,
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
module.exports.formatMany = currify((dir, options, t) => async (formatter, names, formatterOptions = {}) => {
|
|
76
|
+
const joinTwo = (a) => (b) => join(a, b);
|
|
77
|
+
|
|
78
|
+
if (!isArray(names))
|
|
79
|
+
throw Error(`☝️ Looks like 'formatMany()' received 'names' with type: '${typeof names}', expected: 'array'`);
|
|
80
|
+
|
|
81
|
+
const fullNames = names.map(joinTwo(dir));
|
|
82
|
+
|
|
83
|
+
let result = '';
|
|
84
|
+
|
|
85
|
+
const count = names.length;
|
|
86
|
+
const report = putout.initReport();
|
|
87
|
+
|
|
88
|
+
for (let index = 0; index < count; index++) {
|
|
89
|
+
const name = names[index];
|
|
90
|
+
const full = fullNames[index];
|
|
91
|
+
const [input] = readFixture(full);
|
|
92
|
+
|
|
93
|
+
const {places} = putout(input, {
|
|
94
|
+
fixCount: 1,
|
|
95
|
+
...options,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
result += await report(formatter, {
|
|
99
|
+
name,
|
|
100
|
+
formatterOptions,
|
|
101
|
+
source: input,
|
|
102
|
+
places,
|
|
103
|
+
index,
|
|
104
|
+
count,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const outputName = join(dir, String(names.join('-')));
|
|
109
|
+
|
|
110
|
+
if (isUpdate()) {
|
|
111
|
+
writeFormatFixture(outputName, result);
|
|
112
|
+
return t.pass('fixed fixture updated');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const expected = readFormatFixture(outputName);
|
|
116
|
+
const {is, output} = t.equal(result, expected);
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
is,
|
|
120
|
+
output,
|
|
121
|
+
result,
|
|
122
|
+
};
|
|
123
|
+
});
|
package/lib/test.js
CHANGED
|
@@ -18,6 +18,11 @@ const {createProgress} = require('@putout/engine-runner/progress');
|
|
|
18
18
|
|
|
19
19
|
const {createError} = require('./create-error');
|
|
20
20
|
const {preTest} = require('./pre-test');
|
|
21
|
+
const {
|
|
22
|
+
format,
|
|
23
|
+
noFormat,
|
|
24
|
+
formatMany,
|
|
25
|
+
} = require('./format');
|
|
21
26
|
|
|
22
27
|
const {
|
|
23
28
|
readFixture,
|
|
@@ -97,148 +102,12 @@ function createTest(dir, maybeOptions) {
|
|
|
97
102
|
noReportWithOptions: noReportWithOptions(dir, linterOptions, options),
|
|
98
103
|
reportCode: reportCode(lint, options),
|
|
99
104
|
noReportCode: noReportCode(lint, options),
|
|
100
|
-
format:
|
|
101
|
-
formatMany:
|
|
105
|
+
format: format(dir, options),
|
|
106
|
+
formatMany: formatMany(dir, options),
|
|
102
107
|
noFormat: noFormat(dir, options),
|
|
103
108
|
});
|
|
104
109
|
}
|
|
105
110
|
|
|
106
|
-
const format = currify((dir, options, t) => async (formatter, name, formatterOptions = {}) => {
|
|
107
|
-
const full = join(dir, name);
|
|
108
|
-
const outputName = `${full}-format`;
|
|
109
|
-
const [input, isTS] = readFixture(full);
|
|
110
|
-
const [expected] = readFixture(outputName);
|
|
111
|
-
|
|
112
|
-
const {places} = putout(input, {
|
|
113
|
-
fixCount: 1,
|
|
114
|
-
isTS,
|
|
115
|
-
...options,
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const report = putout.initReport();
|
|
119
|
-
|
|
120
|
-
const result = await report(formatter, {
|
|
121
|
-
formatterOptions,
|
|
122
|
-
name,
|
|
123
|
-
source: input,
|
|
124
|
-
places,
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
const {is, output} = t.equal(result, expected);
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
is,
|
|
131
|
-
output,
|
|
132
|
-
result,
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const noFormat = currify((dir, options, t) => async (formatter, name, formatterOptions = {}) => {
|
|
137
|
-
const full = join(dir, name);
|
|
138
|
-
const [input] = readFixture(full);
|
|
139
|
-
const {places} = putout(input, options);
|
|
140
|
-
|
|
141
|
-
const report = putout.initReport();
|
|
142
|
-
|
|
143
|
-
const result = await report(formatter, {
|
|
144
|
-
name,
|
|
145
|
-
places,
|
|
146
|
-
formatterOptions,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const {is, output} = t.equal(result, '', 'should not format');
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
is,
|
|
153
|
-
output,
|
|
154
|
-
result,
|
|
155
|
-
};
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
const formatMany = currify((dir, options, t) => async (formatter, names, formatterOptions = {}) => {
|
|
159
|
-
const joinTwo = (a) => (b) => join(a, b);
|
|
160
|
-
|
|
161
|
-
if (!isArray(names))
|
|
162
|
-
throw Error(`☝️ Looks like 'formatMany()' received 'names' with type: '${typeof names}', expected: 'array'`);
|
|
163
|
-
|
|
164
|
-
const fullNames = names.map(joinTwo(dir));
|
|
165
|
-
|
|
166
|
-
let result = '';
|
|
167
|
-
|
|
168
|
-
const count = names.length;
|
|
169
|
-
const report = putout.initReport();
|
|
170
|
-
|
|
171
|
-
for (let index = 0; index < count; index++) {
|
|
172
|
-
const name = names[index];
|
|
173
|
-
const full = fullNames[index];
|
|
174
|
-
const [input] = readFixture(full);
|
|
175
|
-
|
|
176
|
-
const {places} = putout(input, {
|
|
177
|
-
fixCount: 1,
|
|
178
|
-
...options,
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
result += await report(formatter, {
|
|
182
|
-
name,
|
|
183
|
-
formatterOptions,
|
|
184
|
-
source: input,
|
|
185
|
-
places,
|
|
186
|
-
index,
|
|
187
|
-
count,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const outputName = join(dir, `${names.join('-')}-format`);
|
|
192
|
-
const [expected] = readFixture(outputName);
|
|
193
|
-
|
|
194
|
-
const {is, output} = t.equal(result, expected);
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
is,
|
|
198
|
-
output,
|
|
199
|
-
result,
|
|
200
|
-
};
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
const formatManySave = currify((dir, options, t) => async (formatter, names, formatterOptions = {}) => {
|
|
204
|
-
const runFormat = await formatMany(dir, options, t);
|
|
205
|
-
|
|
206
|
-
if (!isUpdate())
|
|
207
|
-
return await runFormat(formatter, names, formatterOptions);
|
|
208
|
-
|
|
209
|
-
const {writeFileSync} = global.__putout_test_fs;
|
|
210
|
-
|
|
211
|
-
if (!isArray(names))
|
|
212
|
-
throw Error(`☝️ Looks like 'formatMany()' received 'names' with type: '${typeof names}', expected: 'array'`);
|
|
213
|
-
|
|
214
|
-
const name = `${names.join('-')}-format.js`;
|
|
215
|
-
const outputName = join(dir, name);
|
|
216
|
-
|
|
217
|
-
const {result} = await runFormat(formatter, names, formatterOptions);
|
|
218
|
-
|
|
219
|
-
writeFileSync(outputName, result);
|
|
220
|
-
|
|
221
|
-
return t.pass('fixed fixture updated');
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
const formatSave = currify((dir, options, t) => async (formatter, name, formatterOptions = {}) => {
|
|
225
|
-
const runFormat = format(dir, options, t);
|
|
226
|
-
|
|
227
|
-
if (!isUpdate())
|
|
228
|
-
return await runFormat(formatter, name, formatterOptions);
|
|
229
|
-
|
|
230
|
-
const {writeFileSync} = global.__putout_test_fs;
|
|
231
|
-
|
|
232
|
-
const full = join(dir, name);
|
|
233
|
-
const outputName = `${full}-format.js`;
|
|
234
|
-
|
|
235
|
-
const {result} = await runFormat(formatter, name, formatterOptions);
|
|
236
|
-
|
|
237
|
-
writeFileSync(outputName, result);
|
|
238
|
-
|
|
239
|
-
return t.pass('fixed fixture updated');
|
|
240
|
-
});
|
|
241
|
-
|
|
242
111
|
const toObject = (array) => {
|
|
243
112
|
const result = {};
|
|
244
113
|
const first = parsePlugin(array);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/test",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Test runner for 🐊Putout plugins ",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"report": "madrun report"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@putout/cli-process-file": "^
|
|
41
|
+
"@putout/cli-process-file": "^4.0.0",
|
|
42
42
|
"@putout/engine-processor": "*",
|
|
43
43
|
"@putout/engine-runner": "*",
|
|
44
44
|
"@putout/eslint": "^4.0.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"c8": "^10.0.0",
|
|
71
71
|
"eslint": "^9.0.0",
|
|
72
72
|
"eslint-plugin-n": "^17.0.0",
|
|
73
|
-
"eslint-plugin-putout": "^
|
|
73
|
+
"eslint-plugin-putout": "^28.0.0",
|
|
74
74
|
"madrun": "^11.0.0",
|
|
75
75
|
"mock-require": "^3.0.3",
|
|
76
76
|
"nodemon": "^3.0.1",
|