@putout/test 7.5.0 → 7.7.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 +12 -1
- package/lib/is-correct-plugin.js +7 -1
- package/lib/pre-test.js +10 -3
- package/lib/test.js +23 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -209,6 +209,17 @@ test('test: no report after transform', (t) => {
|
|
|
209
209
|
});
|
|
210
210
|
```
|
|
211
211
|
|
|
212
|
+
### `noReportAfterTransformWithOptions(filename)`
|
|
213
|
+
|
|
214
|
+
Check error message of a plugin not produced with provided options:
|
|
215
|
+
|
|
216
|
+
```js
|
|
217
|
+
test('test: no report', (t) => {
|
|
218
|
+
t.noReportAfterTransformWithOptions('file');
|
|
219
|
+
t.end();
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
212
223
|
### `noTransform(filename)`
|
|
213
224
|
|
|
214
225
|
Check transform of `filename.js` produce nothing
|
|
@@ -398,7 +409,7 @@ test('test: eslint: transform', (t) => {
|
|
|
398
409
|
### `report(filename, message | []messages)`
|
|
399
410
|
|
|
400
411
|
```js
|
|
401
|
-
test('test: eslint:
|
|
412
|
+
test('test: eslint: report', (t) => {
|
|
402
413
|
t.report('remove-debugger', `Avoid 'debugger' statement`);
|
|
403
414
|
t.end();
|
|
404
415
|
});
|
package/lib/is-correct-plugin.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const isFn = (a) => typeof a === 'function';
|
|
4
4
|
|
|
5
|
-
module.exports = (
|
|
5
|
+
module.exports.getIsCorrectPluginMessage = () => `should export 'replace', 'find', 'traverse', 'include', 'exclude', 'declare' or 'scan' function`;
|
|
6
|
+
|
|
7
|
+
module.exports.isCorrectPlugin = (plugin) => {
|
|
6
8
|
const {
|
|
7
9
|
find,
|
|
8
10
|
fix,
|
|
@@ -11,6 +13,7 @@ module.exports = (plugin) => {
|
|
|
11
13
|
exclude,
|
|
12
14
|
replace,
|
|
13
15
|
declare,
|
|
16
|
+
scan,
|
|
14
17
|
} = plugin;
|
|
15
18
|
|
|
16
19
|
const isFix = isFn(fix);
|
|
@@ -25,6 +28,9 @@ module.exports = (plugin) => {
|
|
|
25
28
|
if (!isFix)
|
|
26
29
|
return false;
|
|
27
30
|
|
|
31
|
+
if (isFn(scan))
|
|
32
|
+
return true;
|
|
33
|
+
|
|
28
34
|
const isFind = isFn(find);
|
|
29
35
|
const isTraverse = isFn(traverse);
|
|
30
36
|
|
package/lib/pre-test.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const {
|
|
4
|
+
isCorrectPlugin,
|
|
5
|
+
getIsCorrectPluginMessage,
|
|
6
|
+
} = require('./is-correct-plugin');
|
|
7
|
+
|
|
4
8
|
const {entries} = Object;
|
|
5
9
|
const {isArray} = Array;
|
|
6
10
|
|
|
@@ -8,6 +12,7 @@ const maybeTuple = (a) => isArray(a) ? a : ['on', a];
|
|
|
8
12
|
const maybeEntries = (a) => isArray(a) ? a : entries(a).pop();
|
|
9
13
|
|
|
10
14
|
module.exports._maybeEntries = maybeEntries;
|
|
15
|
+
module.exports._maybeTuple = maybeTuple;
|
|
11
16
|
|
|
12
17
|
module.exports.preTest = function preTest(test, plugin) {
|
|
13
18
|
const [name, {
|
|
@@ -22,6 +27,7 @@ module.exports.preTest = function preTest(test, plugin) {
|
|
|
22
27
|
filter,
|
|
23
28
|
match,
|
|
24
29
|
declare,
|
|
30
|
+
scan,
|
|
25
31
|
}] = maybeEntries(plugin);
|
|
26
32
|
|
|
27
33
|
const options = {
|
|
@@ -53,7 +59,7 @@ module.exports.preTest = function preTest(test, plugin) {
|
|
|
53
59
|
t.end();
|
|
54
60
|
}, options);
|
|
55
61
|
|
|
56
|
-
test(`${name}: plugins should be of type:
|
|
62
|
+
test(`${name}: plugins should be of type: Replacer, Includer, Traverser, Scanner, Declarator or Finder`, (t) => {
|
|
57
63
|
const result = isCorrectPlugin({
|
|
58
64
|
find,
|
|
59
65
|
fix,
|
|
@@ -68,9 +74,10 @@ module.exports.preTest = function preTest(test, plugin) {
|
|
|
68
74
|
replace,
|
|
69
75
|
|
|
70
76
|
declare,
|
|
77
|
+
scan,
|
|
71
78
|
});
|
|
72
79
|
|
|
73
|
-
t.ok(result,
|
|
80
|
+
t.ok(result, getIsCorrectPluginMessage());
|
|
74
81
|
t.end();
|
|
75
82
|
}, options);
|
|
76
83
|
};
|
package/lib/test.js
CHANGED
|
@@ -110,6 +110,7 @@ function createTest(dir, maybeOptions) {
|
|
|
110
110
|
report: report(dir, options),
|
|
111
111
|
noReport: noReport(dir, options),
|
|
112
112
|
noReportAfterTransform: noReportAfterTransform(dir, options),
|
|
113
|
+
noReportAfterTransformWithOptions: noReportAfterTransformWithOptions(dir, options),
|
|
113
114
|
reportWithOptions: reportWithOptions(dir, options),
|
|
114
115
|
noReportWithOptions: noReportWithOptions(dir, options),
|
|
115
116
|
reportCode: reportCode(options),
|
|
@@ -259,9 +260,8 @@ const toObject = (array) => {
|
|
|
259
260
|
const result = {};
|
|
260
261
|
const first = parsePlugin(array);
|
|
261
262
|
|
|
262
|
-
if (isObject(first) && !isArray(first))
|
|
263
|
+
if (isObject(first) && !isArray(first))
|
|
263
264
|
return first;
|
|
264
|
-
}
|
|
265
265
|
|
|
266
266
|
for (const [name, value] of array) {
|
|
267
267
|
result[name] = value;
|
|
@@ -453,6 +453,27 @@ const noReportAfterTransform = currify((dir, options, t, name) => {
|
|
|
453
453
|
|
|
454
454
|
module.exports._createNoReportAfterTransform = noReportAfterTransform;
|
|
455
455
|
|
|
456
|
+
const noReportAfterTransformWithOptions = currify((dir, options, t, name, ruleOptions) => {
|
|
457
|
+
const full = join(dir, name);
|
|
458
|
+
const [source, isTS] = readFixture(full);
|
|
459
|
+
const rule = parseRule(options);
|
|
460
|
+
|
|
461
|
+
const rules = {
|
|
462
|
+
[rule]: ['on', ruleOptions],
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
return noReportCodeAfterTransform({
|
|
466
|
+
isTS,
|
|
467
|
+
...options,
|
|
468
|
+
rules: {
|
|
469
|
+
...options.rules,
|
|
470
|
+
...rules,
|
|
471
|
+
},
|
|
472
|
+
}, t, source);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
module.exports._createNoReportAfterTransformWithOptions = noReportAfterTransformWithOptions;
|
|
476
|
+
|
|
456
477
|
const reportWithOptions = currify((dir, options, t, name, message, ruleOptions) => {
|
|
457
478
|
const full = join(dir, name);
|
|
458
479
|
const [source, isTS] = readFixture(full);
|