@putout/test 7.4.0 → 7.5.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/lib/eslint/eslint.mjs +4 -3
- package/lib/pre-test.js +76 -0
- package/lib/processor/index.mjs +2 -2
- package/lib/test.js +4 -70
- package/lib/test.mjs +2 -2
- package/package.json +1 -1
package/lib/eslint/eslint.mjs
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {readFile} from 'fs/promises';
|
|
1
|
+
import {readFile} from 'node:fs/promises';
|
|
2
2
|
import {
|
|
3
3
|
readFileSync,
|
|
4
4
|
writeFileSync,
|
|
5
5
|
unlinkSync,
|
|
6
|
-
} from 'fs';
|
|
6
|
+
} from 'node:fs';
|
|
7
7
|
import {
|
|
8
8
|
join,
|
|
9
9
|
extname,
|
|
10
10
|
basename,
|
|
11
|
-
} from 'path';
|
|
11
|
+
} from 'node:path';
|
|
12
12
|
import eslint from '@putout/eslint';
|
|
13
13
|
import tryToCatch from 'try-to-catch';
|
|
14
14
|
import {extend} from 'supertape';
|
|
15
15
|
import {lint} from '@putout/eslint/lint';
|
|
16
16
|
import tryCatch from 'try-catch';
|
|
17
|
+
import process from 'node:process';
|
|
17
18
|
|
|
18
19
|
const {keys} = Object;
|
|
19
20
|
const {isArray} = Array;
|
package/lib/pre-test.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isCorrectPlugin = require('./is-correct-plugin');
|
|
4
|
+
const {entries} = Object;
|
|
5
|
+
const {isArray} = Array;
|
|
6
|
+
|
|
7
|
+
const maybeTuple = (a) => isArray(a) ? a : ['on', a];
|
|
8
|
+
const maybeEntries = (a) => isArray(a) ? a : entries(a).pop();
|
|
9
|
+
|
|
10
|
+
module.exports._maybeEntries = maybeEntries;
|
|
11
|
+
|
|
12
|
+
module.exports.preTest = function preTest(test, plugin) {
|
|
13
|
+
const [name, {
|
|
14
|
+
report,
|
|
15
|
+
find,
|
|
16
|
+
traverse,
|
|
17
|
+
include,
|
|
18
|
+
exclude,
|
|
19
|
+
fix,
|
|
20
|
+
rules,
|
|
21
|
+
replace,
|
|
22
|
+
filter,
|
|
23
|
+
match,
|
|
24
|
+
declare,
|
|
25
|
+
}] = maybeEntries(plugin);
|
|
26
|
+
|
|
27
|
+
const options = {
|
|
28
|
+
checkDuplicates: false,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (rules) {
|
|
32
|
+
test(`${name}: rules is an object`, (t) => {
|
|
33
|
+
t.equal(typeof rules, 'object', 'should export "rules" object');
|
|
34
|
+
t.end();
|
|
35
|
+
}, options);
|
|
36
|
+
|
|
37
|
+
const entries = Object.entries(rules);
|
|
38
|
+
|
|
39
|
+
for (const [entryName, pluginTuple] of entries) {
|
|
40
|
+
const [, plugin] = maybeTuple(pluginTuple);
|
|
41
|
+
|
|
42
|
+
preTest(test, {
|
|
43
|
+
[`${name}/${entryName}`]: plugin,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!declare)
|
|
51
|
+
test(`${name}: report: is function`, (t) => {
|
|
52
|
+
t.equal(typeof report, 'function', `should export 'report' function`);
|
|
53
|
+
t.end();
|
|
54
|
+
}, options);
|
|
55
|
+
|
|
56
|
+
test(`${name}: plugins should be of type: replace, template, traverse or find`, (t) => {
|
|
57
|
+
const result = isCorrectPlugin({
|
|
58
|
+
find,
|
|
59
|
+
fix,
|
|
60
|
+
|
|
61
|
+
traverse,
|
|
62
|
+
|
|
63
|
+
include,
|
|
64
|
+
exclude,
|
|
65
|
+
|
|
66
|
+
filter,
|
|
67
|
+
match,
|
|
68
|
+
replace,
|
|
69
|
+
|
|
70
|
+
declare,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
t.ok(result, `should export 'replace', 'find', 'traverse', 'include', 'exclude', or 'declare' function`);
|
|
74
|
+
t.end();
|
|
75
|
+
}, options);
|
|
76
|
+
};
|
package/lib/processor/index.mjs
CHANGED
package/lib/test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const process = require('node:process');
|
|
3
4
|
const {join} = require('path');
|
|
4
5
|
|
|
5
6
|
const {
|
|
@@ -14,14 +15,12 @@ const test = require('supertape');
|
|
|
14
15
|
const putout = require('putout');
|
|
15
16
|
const currify = require('currify');
|
|
16
17
|
|
|
17
|
-
const
|
|
18
|
-
|
|
18
|
+
const {preTest} = require('./pre-test');
|
|
19
|
+
const {isArray} = Array;
|
|
19
20
|
const isString = (a) => typeof a === 'string';
|
|
20
21
|
const isObject = (a) => typeof a === 'object';
|
|
21
|
-
const {isArray} = Array;
|
|
22
22
|
|
|
23
|
-
const {keys
|
|
24
|
-
const maybeEntries = (a) => isArray(a) ? a : entries(a).pop();
|
|
23
|
+
const {keys} = Object;
|
|
25
24
|
|
|
26
25
|
global.__putout_test_fs = {
|
|
27
26
|
readFileSync,
|
|
@@ -83,7 +82,6 @@ const rmFixture = (name) => {
|
|
|
83
82
|
|
|
84
83
|
module.exports = createTest;
|
|
85
84
|
module.exports.createTest = createTest;
|
|
86
|
-
module.exports._maybeEntries = maybeEntries;
|
|
87
85
|
|
|
88
86
|
const parsePlugin = (plugins) => {
|
|
89
87
|
if (isArray(plugins))
|
|
@@ -531,67 +529,3 @@ function parseOptions(plugin) {
|
|
|
531
529
|
|
|
532
530
|
return plugin;
|
|
533
531
|
}
|
|
534
|
-
|
|
535
|
-
function preTest(test, plugin) {
|
|
536
|
-
const [name, {
|
|
537
|
-
report,
|
|
538
|
-
find,
|
|
539
|
-
traverse,
|
|
540
|
-
include,
|
|
541
|
-
exclude,
|
|
542
|
-
fix,
|
|
543
|
-
rules,
|
|
544
|
-
replace,
|
|
545
|
-
filter,
|
|
546
|
-
match,
|
|
547
|
-
declare,
|
|
548
|
-
}] = maybeEntries(plugin);
|
|
549
|
-
|
|
550
|
-
const options = {
|
|
551
|
-
checkDuplicates: false,
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
if (rules) {
|
|
555
|
-
test(`${name}: rules is an object`, (t) => {
|
|
556
|
-
t.equal(typeof rules, 'object', 'should export "rules" object');
|
|
557
|
-
t.end();
|
|
558
|
-
}, options);
|
|
559
|
-
|
|
560
|
-
const entries = Object.entries(rules);
|
|
561
|
-
|
|
562
|
-
for (const [entryName, plugin] of entries) {
|
|
563
|
-
preTest(test, {
|
|
564
|
-
[`${name}/${entryName}`]: plugin,
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
if (!declare)
|
|
572
|
-
test(`${name}: report: is function`, (t) => {
|
|
573
|
-
t.equal(typeof report, 'function', `should export 'report' function`);
|
|
574
|
-
t.end();
|
|
575
|
-
}, options);
|
|
576
|
-
|
|
577
|
-
test(`${name}: plugins should be of type: replace, template, traverse or find`, (t) => {
|
|
578
|
-
const result = isCorrectPlugin({
|
|
579
|
-
find,
|
|
580
|
-
fix,
|
|
581
|
-
|
|
582
|
-
traverse,
|
|
583
|
-
|
|
584
|
-
include,
|
|
585
|
-
exclude,
|
|
586
|
-
|
|
587
|
-
filter,
|
|
588
|
-
match,
|
|
589
|
-
replace,
|
|
590
|
-
|
|
591
|
-
declare,
|
|
592
|
-
});
|
|
593
|
-
|
|
594
|
-
t.ok(result, `should export 'replace', 'find', 'traverse', 'include', 'exclude', or 'declare' function`);
|
|
595
|
-
t.end();
|
|
596
|
-
}, options);
|
|
597
|
-
}
|
package/lib/test.mjs
CHANGED