@putout/test 5.7.0 → 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 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.
@@ -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
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/test",
3
- "version": "5.7.0",
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 ",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@putout/engine-processor": "*",
44
- "@putout/eslint": "^1.0.0",
44
+ "@putout/eslint": "^1.2.0",
45
45
  "currify": "^4.0.0",
46
46
  "putout": "*",
47
47
  "supertape": "^7.0.0",