@putout/test 3.7.1 → 3.7.5
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 +139 -37
- package/lib/processor/index.js +5 -7
- package/lib/test.js +22 -24
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# @putout/test [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
|
|
2
2
|
|
|
3
|
-
[NPMIMGURL]:
|
|
4
|
-
[NPMURL]:
|
|
3
|
+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/test.svg?style=flat&longCache=true
|
|
4
|
+
[NPMURL]: https://npmjs.org/package/@putout/test "npm"
|
|
5
|
+
[DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/test-runner
|
|
6
|
+
[DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/test-runner
|
|
5
7
|
|
|
6
|
-
[
|
|
7
|
-
[DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/test-runner
|
|
8
|
-
|
|
9
|
-
Test runner for `putout plugins`. Basically it is [supercharged](https://github.com/coderaiser/supertape) `tape` with aditional asseritions:
|
|
8
|
+
Test runner for [`putout plugins`](https://github.com/coderaiser/putout#plugins-api). Basically it is [supercharged `tape`](https://github.com/coderaiser/supertape) with aditional asseritions:
|
|
10
9
|
|
|
11
10
|
## Install
|
|
12
11
|
|
|
@@ -14,19 +13,40 @@ Test runner for `putout plugins`. Basically it is [supercharged](https://github.
|
|
|
14
13
|
npm i @putout/test -D
|
|
15
14
|
```
|
|
16
15
|
|
|
16
|
+
## Autofix
|
|
17
|
+
|
|
18
|
+
Set environment variable `UPDATE=1` to update `transform` and `format` fixtures.
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
UPDATE=1 tape test/*.js
|
|
22
|
+
```
|
|
23
|
+
|
|
17
24
|
## Plugins API
|
|
18
25
|
|
|
19
|
-
###
|
|
26
|
+
### report(filename, message | []messages)
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
checks error message (or messages) of a plugin
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
```js
|
|
31
|
+
test('remove usless variables: for-of', (t) => {
|
|
32
|
+
t.report('dot', 'Dot files should be added to .gitignore');
|
|
33
|
+
t.end();
|
|
34
|
+
});
|
|
35
|
+
```
|
|
25
36
|
|
|
26
37
|
### reportCode(input, message)
|
|
38
|
+
|
|
27
39
|
checks error message of a plugin from `input` code
|
|
28
40
|
|
|
41
|
+
```js
|
|
42
|
+
test('remove debugger: report', (t) => {
|
|
43
|
+
t.reportCode('debugger', 'Unexpected "debugger" statement');
|
|
44
|
+
t.end();
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
29
48
|
### transform(filename [, output, plugins])
|
|
49
|
+
|
|
30
50
|
check transform of `filename.js` -> `filename-fix.js` in `test/fixtures` directory
|
|
31
51
|
|
|
32
52
|
```js
|
|
@@ -39,24 +59,98 @@ test('remove usless variables: for-of', (t) => {
|
|
|
39
59
|
```
|
|
40
60
|
|
|
41
61
|
### transformCode(input, output)
|
|
62
|
+
|
|
42
63
|
check transform of `input` -> `output` code
|
|
43
64
|
|
|
65
|
+
```js
|
|
66
|
+
test('remove-console: property identifier: code', (t) => {
|
|
67
|
+
t.transformCode('console.log()', '');
|
|
68
|
+
t.end();
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
44
72
|
### reportWithOptions(filename, options)
|
|
73
|
+
|
|
45
74
|
check report of `filename.js` with `options`
|
|
46
75
|
|
|
76
|
+
```js
|
|
77
|
+
test('putout: test: reportWithOptions', (t) => {
|
|
78
|
+
const cache = new Map();
|
|
79
|
+
cache.set('x', 'y');
|
|
80
|
+
|
|
81
|
+
t.reportWithOptions('remove-import', 'avoid imports', {
|
|
82
|
+
cache,
|
|
83
|
+
});
|
|
84
|
+
t.end();
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
47
88
|
### noReportWithOptions(filename, options)
|
|
89
|
+
|
|
48
90
|
check no report of `filename.js` with `options`
|
|
49
91
|
|
|
92
|
+
```js
|
|
93
|
+
test('putout: test: noReportWithOptions', (t) => {
|
|
94
|
+
const cache = new Map();
|
|
95
|
+
|
|
96
|
+
t.noReportWithOptions('remove-import', {
|
|
97
|
+
cache,
|
|
98
|
+
});
|
|
99
|
+
t.end();
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
50
103
|
### transformWithOptions(filename, options)
|
|
104
|
+
|
|
51
105
|
check transform of `filename.js` with `options`
|
|
52
106
|
|
|
107
|
+
```js
|
|
108
|
+
test('putout: plugin: declare-undefined-variables: transform: parse', (t) => {
|
|
109
|
+
t.transformWithOptions('parse', {
|
|
110
|
+
dismiss: ['assign', 'stringify'],
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
t.end();
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
53
117
|
### noTransformWithOptions(filename, options)
|
|
118
|
+
|
|
119
|
+
When file should not be transformed:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
test('test: declared', (t) => {
|
|
123
|
+
t.noTransform('declared');
|
|
124
|
+
t.end();
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### noTransformWithOptions(filename, options)
|
|
129
|
+
|
|
54
130
|
check transform of `filename.js` with `options`
|
|
55
131
|
|
|
132
|
+
```js
|
|
133
|
+
test('putout: plugin: declare-undefined-variables: transform: assign: dismiss', (t) => {
|
|
134
|
+
t.noTransformWithOptions('assign', {
|
|
135
|
+
dismiss: ['assign', 'stringify'],
|
|
136
|
+
});
|
|
137
|
+
t.end();
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
56
141
|
### noReport(filename)
|
|
142
|
+
|
|
57
143
|
checks error message of a plugin not produces
|
|
58
144
|
|
|
145
|
+
```js
|
|
146
|
+
test('plugin-putout: check-replace-code: no report: typescript', (t) => {
|
|
147
|
+
t.noReport('typescript');
|
|
148
|
+
t.end();
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
59
152
|
### noReportAfterTransform(filename)
|
|
153
|
+
|
|
60
154
|
checks error message of a plugin not produces
|
|
61
155
|
|
|
62
156
|
```js
|
|
@@ -66,18 +160,43 @@ test('test: no report after transform', (t) => {
|
|
|
66
160
|
});
|
|
67
161
|
```
|
|
68
162
|
|
|
69
|
-
### noReportCode(filename)
|
|
70
|
-
checks error message of a plugin not produces with a `code`
|
|
71
|
-
|
|
72
163
|
### noTransform(filename)
|
|
73
|
-
|
|
164
|
+
|
|
165
|
+
check transform of `filename.js` produce nothing new
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
test('plugin-apply-numeric-separators: no transform: hex', (t) => {
|
|
169
|
+
t.noTransform('hex');
|
|
170
|
+
t.end();
|
|
171
|
+
});
|
|
172
|
+
```
|
|
74
173
|
|
|
75
174
|
### format(formatter, filename)
|
|
175
|
+
|
|
76
176
|
check file name formatting (pass `process.env.UPDATE=1` to save fixture)
|
|
77
177
|
|
|
178
|
+
### noFormat
|
|
179
|
+
|
|
180
|
+
check that there is no formatting for for such file
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
test('formatter: codeframe: no', (t) => {
|
|
184
|
+
t.noFormat(codeframe, 'no');
|
|
185
|
+
t.end();
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
78
189
|
### formatMany(formatter, [filename1, filename2])
|
|
190
|
+
|
|
79
191
|
check file name formatting (pass `process.env.UPDATE=1` to save fixture)
|
|
80
192
|
|
|
193
|
+
```js
|
|
194
|
+
test('formatter: dump: many', (t) => {
|
|
195
|
+
t.formatMany(dump, ['var', 'var']);
|
|
196
|
+
t.end();
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
81
200
|
#### Usage Example
|
|
82
201
|
|
|
83
202
|
Here is example of tests for [remove-console](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-console):
|
|
@@ -92,27 +211,11 @@ test('remove-console: report', (t) => {
|
|
|
92
211
|
t.end();
|
|
93
212
|
});
|
|
94
213
|
|
|
95
|
-
test('remove-console: property identifier: code', (t) => {
|
|
96
|
-
t.transformCode('console.log()', '');
|
|
97
|
-
t.end();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
214
|
test('remove-console: property identifier', (t) => {
|
|
101
215
|
t.transform('property-identifier');
|
|
102
216
|
t.end();
|
|
103
217
|
});
|
|
104
218
|
|
|
105
|
-
test('remove-console: property literal', (t) => {
|
|
106
|
-
t.transform('property-literal', '\n\n');
|
|
107
|
-
t.end();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// when file should not be transformed
|
|
111
|
-
test('test: declared', (t) => {
|
|
112
|
-
t.noTransform('declared');
|
|
113
|
-
t.end();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
219
|
// when code should not be transformed
|
|
117
220
|
test('test: declared', (t) => {
|
|
118
221
|
t.noTransformCode('alert()');
|
|
@@ -146,12 +249,12 @@ const test = createTest(__dirname, {
|
|
|
146
249
|
Example:
|
|
147
250
|
|
|
148
251
|
```js
|
|
149
|
-
test('putout: processor: json', async (
|
|
150
|
-
await
|
|
252
|
+
test('putout: processor: json', async ({process}) => {
|
|
253
|
+
await process('eslintrc');
|
|
151
254
|
});
|
|
152
255
|
|
|
153
|
-
test('putout: processor: json', async (
|
|
154
|
-
await
|
|
256
|
+
test('putout: processor: json', async ({process}) => {
|
|
257
|
+
await process('package', ['package-json']);
|
|
155
258
|
});
|
|
156
259
|
```
|
|
157
260
|
|
|
@@ -170,8 +273,8 @@ test('putout: process: json: no process', async (t) => {
|
|
|
170
273
|
### comparePlaces(filename, places)
|
|
171
274
|
|
|
172
275
|
```js
|
|
173
|
-
test('putout: processor: css: places', async (
|
|
174
|
-
await
|
|
276
|
+
test('putout: processor: css: places', async ({comparePlaces}) => {
|
|
277
|
+
await comparePlaces('style', [{
|
|
175
278
|
message: 'Expected indentation of 4 spaces (indentation)',
|
|
176
279
|
position: {
|
|
177
280
|
column: 1,
|
|
@@ -185,4 +288,3 @@ test('putout: processor: css: places', async (t) => {
|
|
|
185
288
|
## License
|
|
186
289
|
|
|
187
290
|
MIT
|
|
188
|
-
|
package/lib/processor/index.js
CHANGED
|
@@ -12,13 +12,11 @@ const processFile = require('putout/process-file');
|
|
|
12
12
|
const {runProcessors} = require('@putout/engine-processor');
|
|
13
13
|
|
|
14
14
|
const isStr = (a) => typeof a === 'string';
|
|
15
|
-
const buildOptions = ({options, plugins, processors}) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
};
|
|
15
|
+
const buildOptions = ({options, plugins, processors}) => ({
|
|
16
|
+
...options,
|
|
17
|
+
plugins: plugins || options.plugins,
|
|
18
|
+
processors: processors || options.processors,
|
|
19
|
+
});
|
|
22
20
|
|
|
23
21
|
const addDot = (a) => a ? `.${a}` : '';
|
|
24
22
|
module.exports._addDot = addDot;
|
package/lib/test.js
CHANGED
|
@@ -153,15 +153,7 @@ const formatManySave = currify(({dir, plugins, rules}, t, formatter, names, opti
|
|
|
153
153
|
is,
|
|
154
154
|
output,
|
|
155
155
|
result,
|
|
156
|
-
} = formatMany(
|
|
157
|
-
{dir,
|
|
158
|
-
plugins,
|
|
159
|
-
rules},
|
|
160
|
-
t,
|
|
161
|
-
formatter,
|
|
162
|
-
names,
|
|
163
|
-
options,
|
|
164
|
-
);
|
|
156
|
+
} = formatMany({dir, plugins, rules}, t, formatter, names, options);
|
|
165
157
|
|
|
166
158
|
writeFileSync(outputName, result);
|
|
167
159
|
|
|
@@ -209,17 +201,19 @@ const transform = currify(({dir, plugins, rules}, t, name, transformed = null, a
|
|
|
209
201
|
|
|
210
202
|
addons = addons || {};
|
|
211
203
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
204
|
+
const {code} = putout(input, {
|
|
205
|
+
isTS,
|
|
206
|
+
rules,
|
|
207
|
+
plugins: [{
|
|
208
|
+
...plugins[0],
|
|
209
|
+
...addons,
|
|
210
|
+
}],
|
|
211
|
+
});
|
|
218
212
|
|
|
219
213
|
if (UPDATE)
|
|
220
214
|
writeFileSync(`${full}-fix.js`, code);
|
|
221
215
|
|
|
222
|
-
return t.equal(code, output
|
|
216
|
+
return t.equal(code, output);
|
|
223
217
|
});
|
|
224
218
|
|
|
225
219
|
const transformWithOptions = currify(({dir, plugins}, t, name, options) => {
|
|
@@ -239,7 +233,7 @@ const transformWithOptions = currify(({dir, plugins}, t, name, options) => {
|
|
|
239
233
|
if (UPDATE)
|
|
240
234
|
writeFileSync(`${full}-fix.js`, code);
|
|
241
235
|
|
|
242
|
-
return t.equal(code, output
|
|
236
|
+
return t.equal(code, output);
|
|
243
237
|
});
|
|
244
238
|
|
|
245
239
|
const noTransformWithOptions = currify(({dir, plugins}, t, name, options) => {
|
|
@@ -255,7 +249,7 @@ const noTransformWithOptions = currify(({dir, plugins}, t, name, options) => {
|
|
|
255
249
|
|
|
256
250
|
const {code} = putout(input, {isTS, plugins, rules});
|
|
257
251
|
|
|
258
|
-
return t.equal(code, input
|
|
252
|
+
return t.equal(code, input);
|
|
259
253
|
});
|
|
260
254
|
|
|
261
255
|
const noTransform = currify(({dir, plugins, rules}, t, name, addons = {}) => {
|
|
@@ -267,12 +261,12 @@ const noTransform = currify(({dir, plugins, rules}, t, name, addons = {}) => {
|
|
|
267
261
|
|
|
268
262
|
const transformCode = currify(({plugins, rules}, t, input, output, isTS = false) => {
|
|
269
263
|
const {code} = putout(input, {isTS, plugins, rules});
|
|
270
|
-
return t.equal(code, output
|
|
264
|
+
return t.equal(code, output);
|
|
271
265
|
});
|
|
272
266
|
|
|
273
267
|
const noTransformCode = currify(({plugins, rules}, t, input) => {
|
|
274
268
|
const {code} = putout(input, {plugins, rules});
|
|
275
|
-
return t.equal(code, input
|
|
269
|
+
return t.equal(code, input);
|
|
276
270
|
});
|
|
277
271
|
|
|
278
272
|
const getMessage = ({message}) => message;
|
|
@@ -342,7 +336,7 @@ const reportCode = currify(({plugins, rules, isTS}, t, source, message) => {
|
|
|
342
336
|
if (isArray(message))
|
|
343
337
|
return t.deepEqual(resultMessages, message, 'should equal');
|
|
344
338
|
|
|
345
|
-
return t.equal(resultMessages[0], message
|
|
339
|
+
return t.equal(resultMessages[0], message);
|
|
346
340
|
});
|
|
347
341
|
|
|
348
342
|
const noReportCode = currify(({plugins, rules, isTS}, t, source) => {
|
|
@@ -393,7 +387,7 @@ function preTest(test, plugin) {
|
|
|
393
387
|
test(`${name}: rules is an object`, (t) => {
|
|
394
388
|
t.equal(typeof rules, 'object', 'should export "rules" object');
|
|
395
389
|
t.end();
|
|
396
|
-
});
|
|
390
|
+
}, {checkDuplicates: false});
|
|
397
391
|
|
|
398
392
|
const entries = Object.entries(rules);
|
|
399
393
|
for (const [entryName, plugin] of entries) {
|
|
@@ -405,10 +399,14 @@ function preTest(test, plugin) {
|
|
|
405
399
|
return;
|
|
406
400
|
}
|
|
407
401
|
|
|
402
|
+
const options = {
|
|
403
|
+
checkDuplicates: false,
|
|
404
|
+
};
|
|
405
|
+
|
|
408
406
|
test(`${name}: report: is function`, (t) => {
|
|
409
407
|
t.equal(typeof report, 'function', 'should export "report" function');
|
|
410
408
|
t.end();
|
|
411
|
-
});
|
|
409
|
+
}, options);
|
|
412
410
|
|
|
413
411
|
test(`${name}: plugins should be of type: replace, template, traverse or find`, (t) => {
|
|
414
412
|
const result = isCorrectPlugin({
|
|
@@ -427,6 +425,6 @@ function preTest(test, plugin) {
|
|
|
427
425
|
|
|
428
426
|
t.ok(result, 'should export "replace", "find", "traverse", "include", "exclude" function');
|
|
429
427
|
t.end();
|
|
430
|
-
});
|
|
428
|
+
}, options);
|
|
431
429
|
}
|
|
432
430
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/test",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.5",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "test runner for putout plugins ",
|
|
6
|
-
"homepage": "
|
|
6
|
+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/test#readme",
|
|
7
7
|
"main": "lib/test.js",
|
|
8
8
|
"bin": {
|
|
9
9
|
"tape": "bin/test.mjs"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@putout/engine-processor": "*",
|
|
34
34
|
"currify": "^4.0.0",
|
|
35
35
|
"putout": "*",
|
|
36
|
-
"supertape": "^
|
|
36
|
+
"supertape": "^6.0.0",
|
|
37
37
|
"try-catch": "^3.0.0"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
@@ -47,13 +47,15 @@
|
|
|
47
47
|
"@cloudcmd/stub": "^3.0.0",
|
|
48
48
|
"@putout/formatter-dump": "^2.0.1",
|
|
49
49
|
"@putout/formatter-progress": "^2.0.0",
|
|
50
|
+
"@putout/plugin-extract-object-properties": "^6.0.1",
|
|
51
|
+
"@putout/plugin-putout": "^7.2.0",
|
|
50
52
|
"@putout/plugin-remove-console": "^3.1.0",
|
|
51
|
-
"@putout/plugin-remove-empty": "^
|
|
53
|
+
"@putout/plugin-remove-empty": "^6.0.0",
|
|
52
54
|
"@putout/plugin-remove-unused-variables": "*",
|
|
53
55
|
"c8": "^7.5.0",
|
|
54
|
-
"eslint": "^
|
|
56
|
+
"eslint": "^8.0.0-beta.0",
|
|
55
57
|
"eslint-plugin-node": "^11.0.0",
|
|
56
|
-
"eslint-plugin-putout": "^
|
|
58
|
+
"eslint-plugin-putout": "^10.0.0",
|
|
57
59
|
"lerna": "^4.0.0",
|
|
58
60
|
"madrun": "^8.0.1",
|
|
59
61
|
"mock-require": "^3.0.3",
|