@putout/test 5.1.0 → 5.4.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 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 🐊[`Putout`](https://github.com/coderaiser/putout#plugins-api). Basically it is [supercharged `tape`](https://github.com/coderaiser/supertape) with aditional asseritions:
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, noTransform, noTransformWithOptions*
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,15 +23,16 @@ UPDATE=1 tape test/*.js
23
23
 
24
24
  ## Plugins API
25
25
 
26
- All plugins 🐊`Putout` plugins written in `CommonJS`, since `ESLint` written on `CommonJS` and we have a huge `ESLint`-based ecosystem which is good to reuse.
27
- 🐊`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).
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`:
31
32
 
32
33
  ```js
33
34
  import {createTest} from '@putout/test';
34
- const rmVars = require('@putout/plugin-remove-unused-variables');
35
+ import rmVars from '@putout/plugin-remove-unused-variables';
35
36
 
36
37
  const test = createTest(import.meta.url, {
37
38
  'remove-unused-variables': rmVars,
@@ -40,7 +41,7 @@ const test = createTest(import.meta.url, {
40
41
 
41
42
  ### `report(filename, message | []messages)`
42
43
 
43
- checks error message (or messages) of a plugin
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
- checks error message of a plugin from `input` code
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
- check transform of `filename.js` -> `filename-fix.js` in `test/fixtures` directory
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
- check transform of `input` -> `output` code
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
- check report of `filename.js` with `options`
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
- check no report of `filename.js` with `options`
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
- check transform of `filename.js` with `options`
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
- check transform of `filename.js` with `options`
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
- checks error message of a plugin not produces
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
- checks error message of a plugin not produced
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
- check transform of `filename.js` produce nothing
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
- check file name formatting (pass `process.env.UPDATE=1` to save fixture)
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
- check that there is no formatting for for such file
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
- check file name formatting (pass `process.env.UPDATE=1` to save fixture)
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
- - ✅ checks that transformed is equal to `operator-linebreak-fix.js`;
285
+ - ✅ check that transformed is equal to `operator-linebreak-fix.js`;
276
286
 
277
287
  Example:
278
288
 
@@ -306,21 +316,42 @@ test('test: eslint: noProcess', async ({noProcess}) => {
306
316
  });
307
317
  ```
308
318
 
309
- ### `comparePlaces(filename, places)`
319
+ ### `comparePlaces(filename, places[, overrides])`
310
320
 
311
321
  ```js
312
322
  test('eslint-config: operator-line-break', async ({comparePlaces}) => {
313
323
  await comparePlaces('operator-linebreak', [{
314
- "message": "There should be no line break before or after '='.",
315
- "position": {
316
- "column": 1,
317
- "line": 2,
324
+ message: 'There should be no line break before or after \'=\'.',
325
+ position: {
326
+ column: 1,
327
+ line: 2,
318
328
  },
319
- "rule": "operator-linebreak (eslint)",
329
+ rule: 'operator-linebreak (eslint)',
320
330
  }]);
321
331
  });
322
332
  ```
323
333
 
334
+ with `overrides`:
335
+
336
+ ```js
337
+ test('eslint-config: operator-line-break', async ({comparePlaces}) => {
338
+ const overrides = {
339
+ extends: [
340
+ 'plugin:putout/safe',
341
+ ],
342
+ };
343
+
344
+ await comparePlaces('operator-linebreak', [{
345
+ message: 'There should be no line break before or after \'=\'.',
346
+ position: {
347
+ column: 1,
348
+ line: 2,
349
+ },
350
+ rule: 'operator-linebreak (eslint)',
351
+ }], overrides);
352
+ });
353
+ ```
354
+
324
355
  ## Processors API
325
356
 
326
357
  With `processors api` you can test `processors` in a simplest possible way.
@@ -328,9 +359,9 @@ With `processors api` you can test `processors` in a simplest possible way.
328
359
  First things first, init `test` with:
329
360
 
330
361
  ```js
331
- const {createTest} = require('@putout/test/processor');
362
+ import {createTest} from '@putout/test/processor';
332
363
 
333
- const test = createTest(__dirname, {
364
+ const test = createTest(import.meta.url, {
334
365
  extension: 'json',
335
366
  processors: [
336
367
  'json',
@@ -7,7 +7,7 @@ import {extend} from 'supertape';
7
7
 
8
8
  const config = {
9
9
  extends: [
10
- 'plugin:node/recommended',
10
+ 'plugin:n/recommended',
11
11
  'plugin:eslint-plugin/recommended',
12
12
  'plugin:putout/recommended',
13
13
  ],
@@ -59,14 +59,17 @@ export const createTest = (url) => {
59
59
 
60
60
  return operator.equal(source, code);
61
61
  },
62
- comparePlaces: (operator) => async (name, expected) => {
62
+ comparePlaces: (operator) => async (name, expected, override) => {
63
63
  const full = join(fixtureDir, name);
64
64
  const [resolvedName, code] = await read(full);
65
65
 
66
66
  const [, places] = await eslint({
67
- config,
68
67
  name: resolvedName,
69
68
  code,
69
+ config: {
70
+ ...config,
71
+ ...override,
72
+ },
70
73
  });
71
74
 
72
75
  return operator.deepEqual(places, expected);
@@ -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];
@@ -380,7 +381,7 @@ const reportCode = currify(({plugins, rules, isTS}, t, source, message) => {
380
381
  const resultMessages = places.map(getMessage);
381
382
 
382
383
  if (isArray(message))
383
- return t.deepEqual(resultMessages, message, 'should equal');
384
+ return t.deepEqual(resultMessages, message);
384
385
 
385
386
  return t.equal(resultMessages[0], message);
386
387
  });
@@ -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.1.0",
3
+ "version": "5.4.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": "./lib/processor/index.js",
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
  },
@@ -60,9 +63,9 @@
60
63
  "@putout/plugin-remove-unused-variables": "*",
61
64
  "c8": "^7.5.0",
62
65
  "eslint": "^8.0.1",
63
- "eslint-plugin-node": "^11.0.0",
64
- "eslint-plugin-putout": "^13.0.0",
65
- "lerna": "^4.0.0",
66
+ "eslint-plugin-n": "^15.2.4",
67
+ "eslint-plugin-putout": "^15.0.0",
68
+ "lerna": "^5.0.0",
66
69
  "madrun": "^9.0.0",
67
70
  "mock-require": "^3.0.3",
68
71
  "nodemon": "^2.0.1"