@putout/test 5.5.3 → 5.8.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 +18 -0
- package/lib/eslint/eslint.mjs +53 -2
- package/lib/test.js +14 -3
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -352,6 +352,24 @@ test('eslint-config: operator-line-break', async ({comparePlaces}) => {
|
|
|
352
352
|
});
|
|
353
353
|
```
|
|
354
354
|
|
|
355
|
+
### `transform(name)`
|
|
356
|
+
|
|
357
|
+
```js
|
|
358
|
+
test('test: eslint: transform', (t) => {
|
|
359
|
+
t.transform('remove-debugger');
|
|
360
|
+
t.end();
|
|
361
|
+
});
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### `report(filename, message | []messages)`
|
|
365
|
+
|
|
366
|
+
```js
|
|
367
|
+
test('test: eslint: transform', (t) => {
|
|
368
|
+
t.report('remove-debugger', `Avoid 'debugger' statement`);
|
|
369
|
+
t.end();
|
|
370
|
+
});
|
|
371
|
+
```
|
|
372
|
+
|
|
355
373
|
## Processors API
|
|
356
374
|
|
|
357
375
|
With `processors api` you can test `processors` in a simplest possible way.
|
package/lib/eslint/eslint.mjs
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import {readFile} from 'fs/promises';
|
|
2
|
+
import {readFileSync} from 'fs';
|
|
2
3
|
import {join} from 'path';
|
|
3
4
|
|
|
4
|
-
import eslint from 'putout/eslint';
|
|
5
|
+
import eslint from '@putout/eslint';
|
|
5
6
|
import tryToCatch from 'try-to-catch';
|
|
6
7
|
import {extend} from 'supertape';
|
|
8
|
+
import {lint} from '@putout/eslint/lint';
|
|
7
9
|
|
|
10
|
+
import tryCatch from 'try-catch';
|
|
11
|
+
|
|
12
|
+
const {keys} = Object;
|
|
13
|
+
const {isArray} = Array;
|
|
14
|
+
|
|
15
|
+
const getMessage = ({message}) => message;
|
|
8
16
|
const config = {
|
|
9
17
|
extends: [
|
|
10
18
|
'plugin:n/recommended',
|
|
@@ -13,6 +21,15 @@ const config = {
|
|
|
13
21
|
],
|
|
14
22
|
};
|
|
15
23
|
|
|
24
|
+
const readSync = (name) => {
|
|
25
|
+
const [, data] = tryCatch(readFileSync, `${name}.js`, 'utf8');
|
|
26
|
+
|
|
27
|
+
if (data)
|
|
28
|
+
return [`${name}.js`, data];
|
|
29
|
+
|
|
30
|
+
return [`${name}.ts`, readFileSync(`${name}.ts`, 'utf8')];
|
|
31
|
+
};
|
|
32
|
+
|
|
16
33
|
const read = async (name) => {
|
|
17
34
|
const [, data] = await tryToCatch(readFile, `${name}.js`, 'utf8');
|
|
18
35
|
|
|
@@ -22,7 +39,7 @@ const read = async (name) => {
|
|
|
22
39
|
return [`${name}.ts`, await readFile(`${name}.ts`, 'utf8')];
|
|
23
40
|
};
|
|
24
41
|
|
|
25
|
-
export const createTest = (url) => {
|
|
42
|
+
export const createTest = (url, plugins = {}) => {
|
|
26
43
|
const fixtureDir = new URL('fixture', url).pathname;
|
|
27
44
|
|
|
28
45
|
return extend({
|
|
@@ -74,6 +91,40 @@ export const createTest = (url) => {
|
|
|
74
91
|
|
|
75
92
|
return operator.deepEqual(places, expected);
|
|
76
93
|
},
|
|
94
|
+
report: (t) => (name, message, fail = t.fail) => {
|
|
95
|
+
if (!keys(plugins).length)
|
|
96
|
+
return fail('☝️ Looks like plugins not passed');
|
|
97
|
+
|
|
98
|
+
const full = join(fixtureDir, name);
|
|
99
|
+
const [, source] = readSync(full);
|
|
100
|
+
|
|
101
|
+
const [, places] = lint(source, {
|
|
102
|
+
fix: false,
|
|
103
|
+
plugins,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const resultMessages = places.map(getMessage);
|
|
107
|
+
|
|
108
|
+
if (isArray(message))
|
|
109
|
+
return t.deepEqual(resultMessages, message);
|
|
110
|
+
|
|
111
|
+
return t.equal(resultMessages[0], message);
|
|
112
|
+
},
|
|
113
|
+
transform: (t) => (name, fail = t.fail) => {
|
|
114
|
+
if (!keys(plugins).length)
|
|
115
|
+
return fail('☝️ Looks like plugins not passed');
|
|
116
|
+
|
|
117
|
+
const full = join(fixtureDir, name);
|
|
118
|
+
const [, source] = readSync(full);
|
|
119
|
+
const [, fixture] = readSync(`${full}-fix`);
|
|
120
|
+
|
|
121
|
+
const [code] = lint(source, {
|
|
122
|
+
fix: true,
|
|
123
|
+
plugins,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return t.equal(code, fixture);
|
|
127
|
+
},
|
|
77
128
|
});
|
|
78
129
|
};
|
|
79
130
|
|
package/lib/test.js
CHANGED
|
@@ -42,6 +42,15 @@ const readFixture = (name) => {
|
|
|
42
42
|
return [readFileSync(`${name}.js`, 'utf8'), TS.DISABLED];
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
const writeFixture = ({full, code, isTS}) => {
|
|
46
|
+
const {writeFileSync} = global.__putout_test_fs;
|
|
47
|
+
|
|
48
|
+
if (!isTS)
|
|
49
|
+
return writeFileSync(`${full}-fix.js`, code);
|
|
50
|
+
|
|
51
|
+
writeFileSync(`${full}-fix.ts`, code);
|
|
52
|
+
};
|
|
53
|
+
|
|
45
54
|
const rmFixture = (name) => {
|
|
46
55
|
const {unlinkSync} = global.__putout_test_fs;
|
|
47
56
|
|
|
@@ -225,8 +234,6 @@ const formatSave = currify(({dir, plugins, rules}, t) => async (formatter, name,
|
|
|
225
234
|
});
|
|
226
235
|
|
|
227
236
|
const transform = currify(({dir, plugins, rules}, t, name, transformed = null, addons = {}) => {
|
|
228
|
-
const {writeFileSync} = global.__putout_test_fs;
|
|
229
|
-
|
|
230
237
|
const full = join(dir, name);
|
|
231
238
|
const [input, isTS] = readFixture(full);
|
|
232
239
|
const isStr = isString(transformed);
|
|
@@ -248,7 +255,11 @@ const transform = currify(({dir, plugins, rules}, t, name, transformed = null, a
|
|
|
248
255
|
});
|
|
249
256
|
|
|
250
257
|
if (isUpdate() && !isStr) {
|
|
251
|
-
|
|
258
|
+
writeFixture({
|
|
259
|
+
full,
|
|
260
|
+
code,
|
|
261
|
+
isTS,
|
|
262
|
+
});
|
|
252
263
|
}
|
|
253
264
|
|
|
254
265
|
return t.equal(code, output);
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/test",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.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 ",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/test#readme",
|
|
8
8
|
"main": "lib/test.js",
|
|
9
|
+
"commitType": "colon",
|
|
9
10
|
"bin": {
|
|
10
11
|
"tape": "bin/test.mjs"
|
|
11
12
|
},
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
43
|
"@putout/engine-processor": "*",
|
|
44
|
+
"@putout/eslint": "^1.2.0",
|
|
43
45
|
"currify": "^4.0.0",
|
|
44
46
|
"putout": "*",
|
|
45
47
|
"supertape": "^7.0.0",
|