@putout/test 13.3.1 → 14.1.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 +16 -2
- package/lib/fixture.js +10 -0
- package/lib/format/index.js +123 -0
- package/lib/pre-test.js +2 -0
- package/lib/test.js +11 -141
- package/lib/test.mjs +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -70,6 +70,20 @@ const test = createTest(import.meta.url, {
|
|
|
70
70
|
});
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
And apply new [operators](https://github.com/coderaiser/supertape?tab=readme-ov-file#operators):
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
const test = createTest(import.meta.url, {
|
|
77
|
+
extension: 'wast',
|
|
78
|
+
lint: putout,
|
|
79
|
+
plugins: [
|
|
80
|
+
['remove-unused-variables', rmVars],
|
|
81
|
+
],
|
|
82
|
+
}, {
|
|
83
|
+
render: (operator) => (name) => operator.transform,
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
73
87
|
### `report(filename, message: string | string[], plugins?: PutoutPlugin[])`
|
|
74
88
|
|
|
75
89
|
Check error message (or messages) of a plugin:
|
|
@@ -148,7 +162,7 @@ test('putout: test: reportWithOptions', (t) => {
|
|
|
148
162
|
Check no report of `filename.js` with `options`:
|
|
149
163
|
|
|
150
164
|
```js
|
|
151
|
-
test('putout: test:
|
|
165
|
+
test('putout: test: no report with options: remove-import', (t) => {
|
|
152
166
|
const cache = new Map();
|
|
153
167
|
|
|
154
168
|
t.noReportWithOptions('remove-import', {
|
|
@@ -163,7 +177,7 @@ test('putout: test: noReportWithOptions', (t) => {
|
|
|
163
177
|
Check transform of `filename.js` with `options`:
|
|
164
178
|
|
|
165
179
|
```js
|
|
166
|
-
test('putout: plugin: declare-undefined-variables: transform: parse', (t) => {
|
|
180
|
+
test('putout: plugin: declare-undefined-variables: transform with options: parse', (t) => {
|
|
167
181
|
t.transformWithOptions('parse', {
|
|
168
182
|
dismiss: [
|
|
169
183
|
'assign',
|
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/pre-test.js
CHANGED
package/lib/test.js
CHANGED
|
@@ -19,6 +19,12 @@ const {createProgress} = require('@putout/engine-runner/progress');
|
|
|
19
19
|
const {createError} = require('./create-error');
|
|
20
20
|
const {preTest} = require('./pre-test');
|
|
21
21
|
|
|
22
|
+
const {
|
|
23
|
+
format,
|
|
24
|
+
noFormat,
|
|
25
|
+
formatMany,
|
|
26
|
+
} = require('./format');
|
|
27
|
+
|
|
22
28
|
const {
|
|
23
29
|
readFixture,
|
|
24
30
|
writeFixture,
|
|
@@ -59,11 +65,11 @@ const parsePlugin = (plugins) => {
|
|
|
59
65
|
return plugins;
|
|
60
66
|
};
|
|
61
67
|
|
|
62
|
-
function createTest(dir, maybeOptions) {
|
|
68
|
+
function createTest(dir, maybeOptions, maybeExtends = {}) {
|
|
63
69
|
dir = join(dir, 'fixture');
|
|
64
70
|
|
|
65
71
|
const {
|
|
66
|
-
extension =
|
|
72
|
+
extension = '',
|
|
67
73
|
lint = putout,
|
|
68
74
|
...options
|
|
69
75
|
} = parseOptions(maybeOptions);
|
|
@@ -97,148 +103,13 @@ function createTest(dir, maybeOptions) {
|
|
|
97
103
|
noReportWithOptions: noReportWithOptions(dir, linterOptions, options),
|
|
98
104
|
reportCode: reportCode(lint, options),
|
|
99
105
|
noReportCode: noReportCode(lint, options),
|
|
100
|
-
format:
|
|
101
|
-
formatMany:
|
|
106
|
+
format: format(dir, options),
|
|
107
|
+
formatMany: formatMany(dir, options),
|
|
102
108
|
noFormat: noFormat(dir, options),
|
|
109
|
+
...maybeExtends,
|
|
103
110
|
});
|
|
104
111
|
}
|
|
105
112
|
|
|
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
113
|
const toObject = (array) => {
|
|
243
114
|
const result = {};
|
|
244
115
|
const first = parsePlugin(array);
|
|
@@ -341,7 +212,6 @@ const transformWithOptions = currify((dir, linterOptions, options, t, name, plug
|
|
|
341
212
|
const [input, isTS, currentExtension] = readFixture(full, extension);
|
|
342
213
|
|
|
343
214
|
const rule = parseRule(options);
|
|
344
|
-
|
|
345
215
|
const rules = {
|
|
346
216
|
[rule]: ['on', pluginOptions],
|
|
347
217
|
};
|
package/lib/test.mjs
CHANGED
|
@@ -4,9 +4,9 @@ import create from './test.js';
|
|
|
4
4
|
|
|
5
5
|
export default create;
|
|
6
6
|
|
|
7
|
-
export const createTest = (url, plugins) => {
|
|
7
|
+
export const createTest = (url, plugins, maybeExtends) => {
|
|
8
8
|
const __filename = fileURLToPath(url);
|
|
9
9
|
const __dirname = dirname(__filename);
|
|
10
10
|
|
|
11
|
-
return create(__dirname, plugins);
|
|
11
|
+
return create(__dirname, plugins, maybeExtends);
|
|
12
12
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/test",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.1.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 ",
|
|
@@ -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",
|