@putout/test 5.1.0 → 5.2.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 +34 -24
- package/lib/processor/index.mjs +10 -0
- package/lib/test.js +2 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/test.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/test "npm"
|
|
5
5
|
|
|
6
|
-
Test runner for 🐊[
|
|
6
|
+
Test runner for 🐊[**Putout**](https://github.com/coderaiser/putout#plugins-api). Basically it is [supercharged **tape**](https://github.com/coderaiser/supertape) with additional asseritions:
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ npm i @putout/test -D
|
|
|
15
15
|
|
|
16
16
|
Set environment variable `UPDATE=1` to update `transform` and `format` fixtures.
|
|
17
17
|
|
|
18
|
-
☝️ *Remember that `-fix.js` fixtures will be removed when used in noReport
|
|
18
|
+
☝️ *Remember that `-fix.js` fixtures will be removed when used in `noReport`, `noTransform` and `noTransformWithOptions`*
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
21
|
UPDATE=1 tape test/*.js
|
|
@@ -23,8 +23,9 @@ UPDATE=1 tape test/*.js
|
|
|
23
23
|
|
|
24
24
|
## Plugins API
|
|
25
25
|
|
|
26
|
-
All
|
|
27
|
-
|
|
26
|
+
All 🐊**Putout** plugins written in `CommonJS`, since `ESLint` written on `CommonJS` and we have a huge `ESLint`-based ecosystem which is good to reuse.
|
|
27
|
+
|
|
28
|
+
🐊**Putout** can be used in all IDE's supported by`ESLint` as [`eslint-plugin-putout`](https://github.com/coderaiser/putout/tree/packages/eslint-plugin-putout).
|
|
28
29
|
When [async rules will be supported](https://github.com/eslint/eslint/issues/15394) we can switch to `ESM`.
|
|
29
30
|
|
|
30
31
|
To write test for your plugins you need initialize `test` using `createTest`:
|
|
@@ -40,7 +41,7 @@ const test = createTest(import.meta.url, {
|
|
|
40
41
|
|
|
41
42
|
### `report(filename, message | []messages)`
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
Check error message (or messages) of a plugin:
|
|
44
45
|
|
|
45
46
|
```js
|
|
46
47
|
test('remove usless variables: for-of', (t) => {
|
|
@@ -49,9 +50,18 @@ test('remove usless variables: for-of', (t) => {
|
|
|
49
50
|
});
|
|
50
51
|
```
|
|
51
52
|
|
|
53
|
+
When you want to check that report called exact count of times pass an array of messages:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
test('remove usless variables: for-of', (t) => {
|
|
57
|
+
t.report('dot', ['Dot files should be added to .gitignore']);
|
|
58
|
+
t.end();
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
52
62
|
### `reportCode(input, message)`
|
|
53
63
|
|
|
54
|
-
|
|
64
|
+
Check error message of a plugin from `input` code:
|
|
55
65
|
|
|
56
66
|
```js
|
|
57
67
|
test('remove debugger: report', (t) => {
|
|
@@ -62,7 +72,7 @@ test('remove debugger: report', (t) => {
|
|
|
62
72
|
|
|
63
73
|
### `transform(filename [, output, plugins])`
|
|
64
74
|
|
|
65
|
-
|
|
75
|
+
Check transform of `filename.js` -> `filename-fix.js` in `test/fixtures` directory:
|
|
66
76
|
|
|
67
77
|
```js
|
|
68
78
|
test('remove usless variables: for-of', (t) => {
|
|
@@ -75,7 +85,7 @@ test('remove usless variables: for-of', (t) => {
|
|
|
75
85
|
|
|
76
86
|
### `transformCode(input, output)`
|
|
77
87
|
|
|
78
|
-
|
|
88
|
+
Check transform of `input` -> `output` code:
|
|
79
89
|
|
|
80
90
|
```js
|
|
81
91
|
test('remove-console: property identifier: code', (t) => {
|
|
@@ -86,7 +96,7 @@ test('remove-console: property identifier: code', (t) => {
|
|
|
86
96
|
|
|
87
97
|
### `reportWithOptions(filename, options)`
|
|
88
98
|
|
|
89
|
-
|
|
99
|
+
Check report of `filename.js` with `options`:
|
|
90
100
|
|
|
91
101
|
```js
|
|
92
102
|
test('putout: test: reportWithOptions', (t) => {
|
|
@@ -102,7 +112,7 @@ test('putout: test: reportWithOptions', (t) => {
|
|
|
102
112
|
|
|
103
113
|
### `noReportWithOptions(filename, options)`
|
|
104
114
|
|
|
105
|
-
|
|
115
|
+
Check no report of `filename.js` with `options`:
|
|
106
116
|
|
|
107
117
|
```js
|
|
108
118
|
test('putout: test: noReportWithOptions', (t) => {
|
|
@@ -117,7 +127,7 @@ test('putout: test: noReportWithOptions', (t) => {
|
|
|
117
127
|
|
|
118
128
|
### `transformWithOptions(filename, options)`
|
|
119
129
|
|
|
120
|
-
|
|
130
|
+
Check transform of `filename.js` with `options`:
|
|
121
131
|
|
|
122
132
|
```js
|
|
123
133
|
test('putout: plugin: declare-undefined-variables: transform: parse', (t) => {
|
|
@@ -141,7 +151,7 @@ test('test: declared', (t) => {
|
|
|
141
151
|
|
|
142
152
|
### `noTransformWithOptions(filename, options)`
|
|
143
153
|
|
|
144
|
-
|
|
154
|
+
Check transform of `filename.js` with `options`:
|
|
145
155
|
|
|
146
156
|
```js
|
|
147
157
|
test('putout: plugin: declare-undefined-variables: transform: assign: dismiss', (t) => {
|
|
@@ -154,7 +164,7 @@ test('putout: plugin: declare-undefined-variables: transform: assign: dismiss',
|
|
|
154
164
|
|
|
155
165
|
### `noReport(filename)`
|
|
156
166
|
|
|
157
|
-
|
|
167
|
+
Check error message of a plugin not produces
|
|
158
168
|
|
|
159
169
|
```js
|
|
160
170
|
test('plugin-putout: check-replace-code: no report: typescript', (t) => {
|
|
@@ -165,7 +175,7 @@ test('plugin-putout: check-replace-code: no report: typescript', (t) => {
|
|
|
165
175
|
|
|
166
176
|
### `noReportAfterTransform(filename)`
|
|
167
177
|
|
|
168
|
-
|
|
178
|
+
Check error message of a plugin not produced
|
|
169
179
|
|
|
170
180
|
```js
|
|
171
181
|
test('test: no report after transform', (t) => {
|
|
@@ -176,7 +186,7 @@ test('test: no report after transform', (t) => {
|
|
|
176
186
|
|
|
177
187
|
### `noTransform(filename)`
|
|
178
188
|
|
|
179
|
-
|
|
189
|
+
Check transform of `filename.js` produce nothing
|
|
180
190
|
|
|
181
191
|
```js
|
|
182
192
|
test('plugin-apply-numeric-separators: no transform: hex', (t) => {
|
|
@@ -200,7 +210,7 @@ const test = createTest(import.meta.url, {
|
|
|
200
210
|
|
|
201
211
|
### `format(formatter, filename)`
|
|
202
212
|
|
|
203
|
-
|
|
213
|
+
Check file name formatting (pass `process.env.UPDATE=1` to save `fixture`):
|
|
204
214
|
|
|
205
215
|
```js
|
|
206
216
|
test('formatter: codeframe', async ({format}) => {
|
|
@@ -210,7 +220,7 @@ test('formatter: codeframe', async ({format}) => {
|
|
|
210
220
|
|
|
211
221
|
### `noFormat`
|
|
212
222
|
|
|
213
|
-
|
|
223
|
+
Check that there is no formatting for for such file:
|
|
214
224
|
|
|
215
225
|
```js
|
|
216
226
|
test('formatter: codeframe: no', async ({noFormat}) => {
|
|
@@ -220,7 +230,7 @@ test('formatter: codeframe: no', async ({noFormat}) => {
|
|
|
220
230
|
|
|
221
231
|
### `formatMany(formatter, [filename1, filename2])`
|
|
222
232
|
|
|
223
|
-
|
|
233
|
+
Check file name formatting (pass `process.env.UPDATE=1` to save `fixture`):
|
|
224
234
|
|
|
225
235
|
```js
|
|
226
236
|
test('formatter: dump: many', async ({formatMany}) => {
|
|
@@ -272,7 +282,7 @@ Works in similar to [transform](#transformfilename--output-plugins) way:
|
|
|
272
282
|
|
|
273
283
|
- ✅ reads `operator-linebreak.js`;
|
|
274
284
|
- ✅ transforms it;
|
|
275
|
-
- ✅
|
|
285
|
+
- ✅ check that transformed is equal to `operator-linebreak-fix.js`;
|
|
276
286
|
|
|
277
287
|
Example:
|
|
278
288
|
|
|
@@ -311,12 +321,12 @@ test('test: eslint: noProcess', async ({noProcess}) => {
|
|
|
311
321
|
```js
|
|
312
322
|
test('eslint-config: operator-line-break', async ({comparePlaces}) => {
|
|
313
323
|
await comparePlaces('operator-linebreak', [{
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
324
|
+
message: 'There should be no line break before or after \'=\'.',
|
|
325
|
+
position: {
|
|
326
|
+
column: 1,
|
|
327
|
+
line: 2,
|
|
318
328
|
},
|
|
319
|
-
|
|
329
|
+
rule: 'operator-linebreak (eslint)',
|
|
320
330
|
}]);
|
|
321
331
|
});
|
|
322
332
|
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {dirname} from 'path';
|
|
2
|
+
import {fileURLToPath} from 'url';
|
|
3
|
+
import processor from './index.js';
|
|
4
|
+
|
|
5
|
+
export const createTest = (url, plugins) => {
|
|
6
|
+
const __filename = fileURLToPath(url);
|
|
7
|
+
const __dirname = dirname(__filename);
|
|
8
|
+
|
|
9
|
+
return processor.createTest(__dirname, plugins);
|
|
10
|
+
};
|
package/lib/test.js
CHANGED
|
@@ -137,6 +137,7 @@ const formatMany = currify(({dir, plugins, rules}, t) => async (formatter, names
|
|
|
137
137
|
|
|
138
138
|
const count = names.length;
|
|
139
139
|
const report = putout.initReport();
|
|
140
|
+
|
|
140
141
|
for (let index = 0; index < count; index++) {
|
|
141
142
|
const name = names[index];
|
|
142
143
|
const full = fullNames[index];
|
|
@@ -440,6 +441,7 @@ function preTest(test, plugin) {
|
|
|
440
441
|
}, options);
|
|
441
442
|
|
|
442
443
|
const entries = Object.entries(rules);
|
|
444
|
+
|
|
443
445
|
for (const [entryName, plugin] of entries) {
|
|
444
446
|
preTest(test, {
|
|
445
447
|
[`${name}/${entryName}`]: plugin,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/test",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.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 ",
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
"require": "./lib/test.js",
|
|
15
15
|
"import": "./lib/test.mjs"
|
|
16
16
|
},
|
|
17
|
-
"./processor":
|
|
17
|
+
"./processor": {
|
|
18
|
+
"require": "./lib/processor/index.js",
|
|
19
|
+
"import": "./lib/processor/index.mjs"
|
|
20
|
+
},
|
|
18
21
|
"./formatter": "./lib/formatter/index.mjs",
|
|
19
22
|
"./eslint": "./lib/eslint/eslint.mjs"
|
|
20
23
|
},
|
|
@@ -61,7 +64,7 @@
|
|
|
61
64
|
"c8": "^7.5.0",
|
|
62
65
|
"eslint": "^8.0.1",
|
|
63
66
|
"eslint-plugin-node": "^11.0.0",
|
|
64
|
-
"eslint-plugin-putout": "^
|
|
67
|
+
"eslint-plugin-putout": "^15.0.0",
|
|
65
68
|
"lerna": "^4.0.0",
|
|
66
69
|
"madrun": "^9.0.0",
|
|
67
70
|
"mock-require": "^3.0.3",
|