@putout/test 5.2.0 → 5.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/README.md +25 -4
- package/lib/eslint/eslint.mjs +6 -3
- package/lib/processor/index.js +9 -1
- package/lib/test.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ To write test for your plugins you need initialize `test` using `createTest`:
|
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
34
|
import {createTest} from '@putout/test';
|
|
35
|
-
|
|
35
|
+
import rmVars from '@putout/plugin-remove-unused-variables';
|
|
36
36
|
|
|
37
37
|
const test = createTest(import.meta.url, {
|
|
38
38
|
'remove-unused-variables': rmVars,
|
|
@@ -316,7 +316,7 @@ test('test: eslint: noProcess', async ({noProcess}) => {
|
|
|
316
316
|
});
|
|
317
317
|
```
|
|
318
318
|
|
|
319
|
-
### `comparePlaces(filename, places)`
|
|
319
|
+
### `comparePlaces(filename, places[, overrides])`
|
|
320
320
|
|
|
321
321
|
```js
|
|
322
322
|
test('eslint-config: operator-line-break', async ({comparePlaces}) => {
|
|
@@ -331,6 +331,27 @@ test('eslint-config: operator-line-break', async ({comparePlaces}) => {
|
|
|
331
331
|
});
|
|
332
332
|
```
|
|
333
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
|
+
|
|
334
355
|
## Processors API
|
|
335
356
|
|
|
336
357
|
With `processors api` you can test `processors` in a simplest possible way.
|
|
@@ -338,9 +359,9 @@ With `processors api` you can test `processors` in a simplest possible way.
|
|
|
338
359
|
First things first, init `test` with:
|
|
339
360
|
|
|
340
361
|
```js
|
|
341
|
-
|
|
362
|
+
import {createTest} from '@putout/test/processor';
|
|
342
363
|
|
|
343
|
-
const test = createTest(
|
|
364
|
+
const test = createTest(import.meta.url, {
|
|
344
365
|
extension: 'json',
|
|
345
366
|
processors: [
|
|
346
367
|
'json',
|
package/lib/eslint/eslint.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {extend} from 'supertape';
|
|
|
7
7
|
|
|
8
8
|
const config = {
|
|
9
9
|
extends: [
|
|
10
|
-
'plugin:
|
|
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);
|
package/lib/processor/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
readFile,
|
|
5
|
+
writeFile,
|
|
6
|
+
} = require('fs/promises');
|
|
4
7
|
const {
|
|
5
8
|
join,
|
|
6
9
|
extname,
|
|
@@ -12,6 +15,8 @@ const processFile = require('putout/process-file');
|
|
|
12
15
|
const {runProcessors} = require('@putout/engine-processor');
|
|
13
16
|
|
|
14
17
|
const isStr = (a) => typeof a === 'string';
|
|
18
|
+
const isUpdate = () => global.process.env.UPDATE;
|
|
19
|
+
|
|
15
20
|
const buildOptions = ({options, plugins, processors}) => ({
|
|
16
21
|
...options,
|
|
17
22
|
plugins: plugins || options.plugins,
|
|
@@ -110,6 +115,9 @@ async function process(filename, dir, {processors, plugins, extension, fix = tru
|
|
|
110
115
|
rawSource,
|
|
111
116
|
});
|
|
112
117
|
|
|
118
|
+
if (isUpdate() && !noChange)
|
|
119
|
+
await writeFile(outputName, processedSource);
|
|
120
|
+
|
|
113
121
|
return {
|
|
114
122
|
processedSource,
|
|
115
123
|
output,
|
package/lib/test.js
CHANGED
|
@@ -381,7 +381,7 @@ const reportCode = currify(({plugins, rules, isTS}, t, source, message) => {
|
|
|
381
381
|
const resultMessages = places.map(getMessage);
|
|
382
382
|
|
|
383
383
|
if (isArray(message))
|
|
384
|
-
return t.deepEqual(resultMessages, message
|
|
384
|
+
return t.deepEqual(resultMessages, message);
|
|
385
385
|
|
|
386
386
|
return t.equal(resultMessages[0], message);
|
|
387
387
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/test",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.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 ",
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"@putout/plugin-remove-unused-variables": "*",
|
|
64
64
|
"c8": "^7.5.0",
|
|
65
65
|
"eslint": "^8.0.1",
|
|
66
|
-
"eslint-plugin-
|
|
67
|
-
"eslint-plugin-putout": "^
|
|
68
|
-
"lerna": "^
|
|
66
|
+
"eslint-plugin-n": "^15.2.4",
|
|
67
|
+
"eslint-plugin-putout": "^16.0.0",
|
|
68
|
+
"lerna": "^5.0.0",
|
|
69
69
|
"madrun": "^9.0.0",
|
|
70
70
|
"mock-require": "^3.0.3",
|
|
71
71
|
"nodemon": "^2.0.1"
|