@putout/test 6.4.0 → 6.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 CHANGED
@@ -151,7 +151,10 @@ Check transform of `filename.js` with `options`:
151
151
  ```js
152
152
  test('putout: plugin: declare-undefined-variables: transform: parse', (t) => {
153
153
  t.transformWithOptions('parse', {
154
- dismiss: ['assign', 'stringify'],
154
+ dismiss: [
155
+ 'assign',
156
+ 'stringify',
157
+ ],
155
158
  });
156
159
  t.end();
157
160
  });
@@ -175,7 +178,10 @@ Check transform of `filename.js` with `options`:
175
178
  ```js
176
179
  test('putout: plugin: declare-undefined-variables: transform: assign: dismiss', (t) => {
177
180
  t.noTransformWithOptions('assign', {
178
- dismiss: ['assign', 'stringify'],
181
+ dismiss: [
182
+ 'assign',
183
+ 'stringify',
184
+ ],
179
185
  });
180
186
  t.end();
181
187
  });
@@ -292,6 +298,7 @@ First you need to create test with:
292
298
 
293
299
  ```js
294
300
  import {createTest} from '@putout/test/eslint';
301
+
295
302
  const test = createTest(import.meta.url);
296
303
  ```
297
304
 
@@ -365,9 +372,7 @@ with `overrides`:
365
372
  ```js
366
373
  test('eslint-config: operator-line-break', async ({comparePlaces}) => {
367
374
  const overrides = {
368
- extends: [
369
- 'plugin:putout/safe',
370
- ],
375
+ extends: ['plugin:putout/safe'],
371
376
  };
372
377
 
373
378
  await comparePlaces('operator-linebreak', [{
@@ -410,12 +415,8 @@ import {createTest} from '@putout/test/processor';
410
415
 
411
416
  const test = createTest(import.meta.url, {
412
417
  extension: 'json',
413
- processors: [
414
- 'json',
415
- ],
416
- plugins: [
417
- 'eslint',
418
- ],
418
+ processors: ['json'],
419
+ plugins: ['eslint'],
419
420
  });
420
421
  ```
421
422
 
@@ -9,18 +9,17 @@ import {
9
9
  extname,
10
10
  basename,
11
11
  } from 'path';
12
-
13
12
  import eslint from '@putout/eslint';
14
13
  import tryToCatch from 'try-to-catch';
15
14
  import {extend} from 'supertape';
16
15
  import {lint} from '@putout/eslint/lint';
17
-
18
16
  import tryCatch from 'try-catch';
19
17
 
20
18
  const {keys} = Object;
21
19
  const {isArray} = Array;
22
20
 
23
21
  const isUpdate = () => process.env.UPDATE === '1';
22
+
24
23
  const update = (name, data) => {
25
24
  const fn = global.writeFileSync || writeFileSync;
26
25
  fn(name, data);
@@ -32,10 +31,12 @@ const remove = (name) => {
32
31
  const fixtureName = name.replace(base, `${base}-fix`);
33
32
 
34
33
  const fn = global.unlinkSync || unlinkSync;
34
+
35
35
  tryCatch(fn, String(fixtureName));
36
36
  };
37
37
 
38
38
  const getMessage = ({message}) => message;
39
+
39
40
  const config = {
40
41
  extends: [
41
42
  'plugin:n/recommended',
@@ -48,7 +49,10 @@ const readSync = (name) => {
48
49
  const [, data] = tryCatch(readFileSync, `${name}.js`, 'utf8');
49
50
 
50
51
  if (data)
51
- return [`${name}.js`, data];
52
+ return [
53
+ `${name}.js`,
54
+ data,
55
+ ];
52
56
 
53
57
  return [`${name}.ts`, readFileSync(`${name}.ts`, 'utf8')];
54
58
  };
@@ -57,7 +61,10 @@ const read = async (name) => {
57
61
  const [, data] = await tryToCatch(readFile, `${name}.js`, 'utf8');
58
62
 
59
63
  if (data)
60
- return [`${name}.js`, data];
64
+ return [
65
+ `${name}.js`,
66
+ data,
67
+ ];
61
68
 
62
69
  return [`${name}.ts`, await readFile(`${name}.ts`, 'utf8')];
63
70
  };
@@ -164,4 +171,3 @@ export const createTest = (url, plugins = {}) => {
164
171
  },
165
172
  });
166
173
  };
167
-
@@ -39,4 +39,3 @@ module.exports = (plugin) => {
39
39
 
40
40
  return isInclude || isExclude;
41
41
  };
42
-
@@ -1,9 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- readFile,
5
- writeFile,
6
- } = require('fs/promises');
3
+ const {readFile, writeFile} = require('fs/promises');
4
+
7
5
  const {
8
6
  join,
9
7
  extname,
@@ -16,6 +14,7 @@ const {runProcessors} = require('@putout/engine-processor');
16
14
 
17
15
  const isStr = (a) => typeof a === 'string';
18
16
  const isUpdate = () => Number(global.process.env.UPDATE);
17
+
19
18
  const update = async (a, b) => {
20
19
  const write = global.writeFile || writeFile;
21
20
  await write(a, b);
@@ -28,6 +27,7 @@ const buildOptions = ({options, plugins, processors}) => ({
28
27
  });
29
28
 
30
29
  const addDot = (a) => a ? `.${a}` : '';
30
+
31
31
  module.exports._addDot = addDot;
32
32
 
33
33
  module.exports.createTest = (dir, options) => {
@@ -81,6 +81,7 @@ const createNoProcess = (dir, options) => (operator) => async (filename, plugins
81
81
 
82
82
  return operator.equal(processedSource, rawSource, 'fixtures should equal');
83
83
  };
84
+
84
85
  module.exports._createNoProcess = createNoProcess;
85
86
 
86
87
  const createComparePlaces = (dir, options) => (operator) => async (filename, expectedPlaces) => {
@@ -94,6 +95,7 @@ const createComparePlaces = (dir, options) => (operator) => async (filename, exp
94
95
 
95
96
  return operator.deepEqual(places, expectedPlaces, 'places should equal');
96
97
  };
98
+
97
99
  module.exports._createComparePlaces = createComparePlaces;
98
100
 
99
101
  async function process(filename, dir, {processors, plugins, extension, fix = true, noChange = false, processorRunners}) {
@@ -105,6 +107,7 @@ async function process(filename, dir, {processors, plugins, extension, fix = tru
105
107
 
106
108
  const rawSource = await readFile(inputName, 'utf8');
107
109
  const output = !fix || noChange ? '' : await readFile(outputName, 'utf8');
110
+
108
111
  const options = {
109
112
  dir,
110
113
  processors,
@@ -117,7 +120,9 @@ async function process(filename, dir, {processors, plugins, extension, fix = tru
117
120
  } = await runProcessors({
118
121
  fix,
119
122
  name: inputName,
120
- processFile: processFile({fix}),
123
+ processFile: processFile({
124
+ fix,
125
+ }),
121
126
  options,
122
127
  rawSource,
123
128
  processorRunners,
@@ -133,4 +138,3 @@ async function process(filename, dir, {processors, plugins, extension, fix = tru
133
138
  rawSource,
134
139
  };
135
140
  }
136
-
package/lib/test.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {join} = require('path');
4
+
4
5
  const {
5
6
  readFileSync,
6
7
  writeFileSync,
@@ -18,6 +19,7 @@ const isCorrectPlugin = require('./is-correct-plugin');
18
19
  const isString = (a) => typeof a === 'string';
19
20
  const isObject = (a) => typeof a === 'object';
20
21
  const {isArray} = Array;
22
+
21
23
  const {keys, entries} = Object;
22
24
 
23
25
  global.__putout_test_fs = {
@@ -39,9 +41,15 @@ const readFixture = (name) => {
39
41
  const [e, data] = tryCatch(readFileSync, `${name}.ts`, 'utf8');
40
42
 
41
43
  if (!e)
42
- return [data, TS.ENABLED];
43
-
44
- return [readFileSync(`${name}.js`, 'utf8'), TS.DISABLED];
44
+ return [
45
+ data,
46
+ TS.ENABLED,
47
+ ];
48
+
49
+ return [
50
+ readFileSync(`${name}.js`, 'utf8'),
51
+ TS.DISABLED,
52
+ ];
45
53
  };
46
54
 
47
55
  const writeFixture = ({full, code, isTS}) => {
@@ -108,9 +116,9 @@ function createTest(dir, maybeOptions) {
108
116
  reportCode: reportCode(options),
109
117
 
110
118
  formatSave: formatSave(dir, options),
111
- format: (update ? formatSave : format)(dir, options),
119
+ format: update ? formatSave : format(dir, options),
112
120
  formatManySave: formatManySave(dir, options),
113
- formatMany: (update ? formatManySave : formatMany)(dir, options),
121
+ formatMany: update ? formatManySave : formatMany(dir, options),
114
122
  noFormat: noFormat(dir, options),
115
123
  });
116
124
  }
@@ -128,6 +136,7 @@ const format = currify((dir, options, t) => async (formatter, name, formatterOpt
128
136
  });
129
137
 
130
138
  const report = putout.initReport();
139
+
131
140
  const result = await report(formatter, {
132
141
  formatterOptions,
133
142
  name,
@@ -137,7 +146,11 @@ const format = currify((dir, options, t) => async (formatter, name, formatterOpt
137
146
 
138
147
  const {is, output} = t.equal(result, expected);
139
148
 
140
- return {is, output, result};
149
+ return {
150
+ is,
151
+ output,
152
+ result,
153
+ };
141
154
  });
142
155
 
143
156
  const noFormat = currify((dir, options, t) => async (formatter, name, formatterOptions = {}) => {
@@ -146,6 +159,7 @@ const noFormat = currify((dir, options, t) => async (formatter, name, formatterO
146
159
  const {places} = putout(input, options);
147
160
 
148
161
  const report = putout.initReport();
162
+
149
163
  const result = await report(formatter, {
150
164
  name,
151
165
  places,
@@ -154,7 +168,11 @@ const noFormat = currify((dir, options, t) => async (formatter, name, formatterO
154
168
 
155
169
  const {is, output} = t.equal(result, '', 'should not format');
156
170
 
157
- return {is, output, result};
171
+ return {
172
+ is,
173
+ output,
174
+ result,
175
+ };
158
176
  });
159
177
 
160
178
  const formatMany = currify((dir, options, t) => async (formatter, names, formatterOptions = {}) => {
@@ -195,14 +213,15 @@ const formatMany = currify((dir, options, t) => async (formatter, names, formatt
195
213
 
196
214
  const {is, output} = t.equal(result, expected);
197
215
 
198
- return {is, output, result};
216
+ return {
217
+ is,
218
+ output,
219
+ result,
220
+ };
199
221
  });
200
222
 
201
223
  const formatManySave = currify((dir, options, t) => async (formatter, names, options = {}) => {
202
- const {
203
- existsSync,
204
- writeFileSync,
205
- } = global.__putout_test_fs;
224
+ const {existsSync, writeFileSync} = global.__putout_test_fs;
206
225
 
207
226
  if (!isArray(names))
208
227
  throw Error(`☝️ Looks like 'formatManySave()' received 'names' with type: '${typeof names}', expected: 'array'`);
@@ -222,10 +241,7 @@ const formatManySave = currify((dir, options, t) => async (formatter, names, opt
222
241
  });
223
242
 
224
243
  const formatSave = currify((dir, options, t) => async (formatter, name, options = {}) => {
225
- const {
226
- existsSync,
227
- writeFileSync,
228
- } = global.__putout_test_fs;
244
+ const {existsSync, writeFileSync} = global.__putout_test_fs;
229
245
 
230
246
  const full = join(dir, name);
231
247
  const outputName = `${full}-format.js`;
@@ -332,7 +348,6 @@ const noTransformWithOptions = currify((dir, options, t, name, ruleOptions) => {
332
348
  rmFixture(`${full}-fix`);
333
349
 
334
350
  const rule = parseRule(options);
335
-
336
351
  const rules = {
337
352
  [rule]: ['on', ruleOptions],
338
353
  };
@@ -343,6 +358,16 @@ const noTransformWithOptions = currify((dir, options, t, name, ruleOptions) => {
343
358
  ...options,
344
359
  });
345
360
 
361
+ if (isUpdate()) {
362
+ writeSourceFixture({
363
+ full,
364
+ code,
365
+ isTS,
366
+ });
367
+
368
+ return t.pass('source fixture updated');
369
+ }
370
+
346
371
  return t.equal(code, input);
347
372
  });
348
373
 
@@ -398,7 +423,10 @@ const report = currify((dir, options, t, name, message) => {
398
423
  const full = join(dir, name);
399
424
  const [source, isTS] = readFixture(full);
400
425
 
401
- return reportCode({isTS, ...options}, t, source, message);
426
+ return reportCode({
427
+ isTS,
428
+ ...options,
429
+ }, t, source, message);
402
430
  });
403
431
 
404
432
  const noReport = currify((dir, options, t, name) => {
@@ -407,16 +435,24 @@ const noReport = currify((dir, options, t, name) => {
407
435
 
408
436
  rmFixture(`${full}-fix`);
409
437
 
410
- return noReportCode({isTS, ...options}, t, source);
438
+ return noReportCode({
439
+ isTS,
440
+ ...options,
441
+ }, t, source);
411
442
  });
443
+
412
444
  module.exports._createNoReport = noReport;
413
445
 
414
446
  const noReportAfterTransform = currify((dir, options, t, name) => {
415
447
  const full = join(dir, name);
416
448
  const [source, isTS] = readFixture(full);
417
449
 
418
- return noReportCodeAfterTransform({isTS, ...options}, t, source);
450
+ return noReportCodeAfterTransform({
451
+ isTS,
452
+ ...options,
453
+ }, t, source);
419
454
  });
455
+
420
456
  module.exports._createNoReportAfterTransform = noReportAfterTransform;
421
457
 
422
458
  const reportWithOptions = currify((dir, options, t, name, message, ruleOptions) => {
@@ -424,11 +460,16 @@ const reportWithOptions = currify((dir, options, t, name, message, ruleOptions)
424
460
  const [source, isTS] = readFixture(full);
425
461
 
426
462
  const rule = parseRule(options);
463
+
427
464
  const rules = {
428
465
  [rule]: ['on', ruleOptions],
429
466
  };
430
467
 
431
- return reportCode({...options, rules, isTS}, t, source, message);
468
+ return reportCode({
469
+ ...options,
470
+ rules,
471
+ isTS,
472
+ }, t, source, message);
432
473
  });
433
474
 
434
475
  const noReportWithOptions = currify((dir, options, t, name, ruleOptions) => {
@@ -438,11 +479,16 @@ const noReportWithOptions = currify((dir, options, t, name, ruleOptions) => {
438
479
  rmFixture(`${full}-fix`);
439
480
 
440
481
  const rule = parseRule(options);
482
+
441
483
  const rules = {
442
484
  [rule]: ['on', ruleOptions],
443
485
  };
444
486
 
445
- return noReportCode({isTS, ...options, rules}, t, source);
487
+ return noReportCode({
488
+ isTS,
489
+ ...options,
490
+ rules,
491
+ }, t, source);
446
492
  });
447
493
 
448
494
  const reportCode = currify((options, t, source, message) => {
@@ -549,4 +595,3 @@ function preTest(test, plugin) {
549
595
  t.end();
550
596
  }, options);
551
597
  }
552
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/test",
3
- "version": "6.4.0",
3
+ "version": "6.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 ",
@@ -64,7 +64,7 @@
64
64
  "@putout/plugin-remove-unused-variables": "*",
65
65
  "c8": "^7.5.0",
66
66
  "eslint": "^8.0.1",
67
- "eslint-plugin-n": "^15.2.4",
67
+ "eslint-plugin-n": "^16.0.0",
68
68
  "eslint-plugin-putout": "^17.0.0",
69
69
  "lerna": "^6.0.1",
70
70
  "madrun": "^9.0.0",