@putout/test 9.1.0 → 11.0.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
@@ -21,14 +21,6 @@ Set environment variable `UPDATE=1` to update `transform` and `format` fixtures
21
21
  UPDATE=1 tape test/*.js
22
22
  ```
23
23
 
24
- ## Printer
25
-
26
- You can override default printer (`recast`) with [`putout`](https://github.com/putoutjs/printer) or `babel` using:
27
-
28
- ```sh
29
- PUTOUT_PRINTER=putout tape test/*.js
30
- ```
31
-
32
24
  ## Plugins API
33
25
 
34
26
  🐊**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).
@@ -100,6 +92,8 @@ test('remove usless variables: for-of', (t) => {
100
92
  });
101
93
  ```
102
94
 
95
+ *☝️When input and output the same test fails. Use [`noTransform()`](#notransformfilename) for such cases.*
96
+
103
97
  ### `transformCode(input, output)`
104
98
 
105
99
  Check transform of `input` -> `output` code:
@@ -372,6 +366,8 @@ test('test: eslint: transform', async ({process}) => {
372
366
  });
373
367
  ```
374
368
 
369
+ *☝️When input and output the same test fails. Use [`noProcess()`](#noprocessfilename--overrides) for such cases.*
370
+
375
371
  ### `noProcess(filename [, overrides])`
376
372
 
377
373
  Check that filename would not be processed.
@@ -9,12 +9,12 @@ import {
9
9
  extname,
10
10
  basename,
11
11
  } from 'node:path';
12
+ import process from 'node:process';
12
13
  import eslint from '@putout/eslint';
13
14
  import tryToCatch from 'try-to-catch';
14
15
  import {extend} from 'supertape';
15
16
  import {lint} from '@putout/eslint/lint';
16
17
  import tryCatch from 'try-catch';
17
- import process from 'node:process';
18
18
 
19
19
  const {keys} = Object;
20
20
  const {isArray} = Array;
@@ -32,7 +32,6 @@ const remove = async (a) => {
32
32
 
33
33
  const read = async (a, b) => {
34
34
  const read = global.readFile || readFile;
35
-
36
35
  return await read(a, b);
37
36
  };
38
37
 
@@ -44,6 +43,11 @@ const buildOptions = ({options, plugins, processors}) => ({
44
43
 
45
44
  const addDot = (a) => a ? `.${a}` : '';
46
45
 
46
+ const fail = (t, message) => {
47
+ const {__putout_test_fail = t.fail} = global;
48
+ return __putout_test_fail(message);
49
+ };
50
+
47
51
  module.exports._addDot = addDot;
48
52
 
49
53
  module.exports.createTest = (dir, options) => {
@@ -56,10 +60,11 @@ module.exports.createTest = (dir, options) => {
56
60
 
57
61
  const createProcess = (dir, options) => (operator) => async (filename, plugins, processors) => {
58
62
  if (!isStr(filename))
59
- return operator.fail(`Expected filename to be string!`);
63
+ return fail(operator, `Expected filename to be string!`);
60
64
 
61
65
  const {
62
66
  processedSource,
67
+ rawSource,
63
68
  output,
64
69
  } = await process(
65
70
  filename,
@@ -74,6 +79,9 @@ const createProcess = (dir, options) => (operator) => async (filename, plugins,
74
79
  if (isUpdate())
75
80
  return operator.pass('fixtures updated');
76
81
 
82
+ if (rawSource === processedSource)
83
+ return fail(operator, `'input' === 'output', use 'noProcess()'`);
84
+
77
85
  return operator.equal(processedSource, output, 'fixtures should equal');
78
86
  };
79
87
 
@@ -114,7 +122,17 @@ const createComparePlaces = (dir, options) => (operator) => async (filename, exp
114
122
 
115
123
  module.exports._createComparePlaces = createComparePlaces;
116
124
 
117
- async function process(filename, dir, {printer, processors, plugins, extension, fix = true, noChange = false, processorRunners}) {
125
+ async function process(filename, dir, config) {
126
+ let {extension} = config;
127
+ const {
128
+ printer,
129
+ processors,
130
+ plugins,
131
+ fix = true,
132
+ noChange = false,
133
+ processorRunners,
134
+ } = config;
135
+
118
136
  extension = addDot(extname(filename).slice(1) || extension);
119
137
  filename = basename(filename, String(extension));
120
138
 
package/lib/test.js CHANGED
@@ -34,7 +34,11 @@ global.__putout_test_fs = {
34
34
  };
35
35
 
36
36
  const isUpdate = () => Boolean(Number(process.env.UPDATE));
37
- const getPrinter = () => process.env.PUTOUT_PRINTER;
37
+
38
+ const fail = (t, message) => {
39
+ const {__putout_test_fail = t.fail} = global;
40
+ return __putout_test_fail(message);
41
+ };
38
42
 
39
43
  const TS = {
40
44
  ENABLED: true,
@@ -288,7 +292,6 @@ const progress = (dir, options) => (t) => async (name, expected) => {
288
292
  once(progress, 'file'),
289
293
  putout(input, {
290
294
  progress,
291
- printer: getPrinter(),
292
295
  isTS,
293
296
  ...options,
294
297
  }),
@@ -313,7 +316,6 @@ const progressWithOptions = (dir, options) => (t) => async (name, pluginOptions,
313
316
  putout(input, {
314
317
  rules,
315
318
  progress,
316
- printer: getPrinter(),
317
319
  isTS,
318
320
  ...options,
319
321
  }),
@@ -335,7 +337,6 @@ const transform = currify((dir, options, t, name, transformed = null, addons = {
335
337
  addons = addons || {};
336
338
 
337
339
  const {code} = putout(input, {
338
- printer: getPrinter(),
339
340
  isTS,
340
341
  ...options,
341
342
  plugins: [{
@@ -344,6 +345,9 @@ const transform = currify((dir, options, t, name, transformed = null, addons = {
344
345
  }],
345
346
  });
346
347
 
348
+ if (input === code)
349
+ return fail(t, `'input' === 'output', use 'noTransform()'`);
350
+
347
351
  if (isUpdate() && !isStr) {
348
352
  writeFixture({
349
353
  full,
@@ -370,7 +374,6 @@ const transformWithOptions = currify((dir, options, t, name, pluginOptions) => {
370
374
  };
371
375
 
372
376
  const {code} = putout(input, {
373
- printer: getPrinter(),
374
377
  isTS,
375
378
  rules,
376
379
  ...options,
@@ -432,7 +435,6 @@ const noTransform = currify((dir, options, t, name, addons = {}) => {
432
435
  const [input, isTS] = readFixture(full);
433
436
 
434
437
  const {code} = putout(input, {
435
- printer: getPrinter(),
436
438
  isTS,
437
439
  ...options,
438
440
  plugins: [{
@@ -553,7 +555,6 @@ const noReportWithOptions = currify((dir, options, t, name, ruleOptions) => {
553
555
  rmFixture(`${full}-fix`);
554
556
 
555
557
  const rule = parseRule(options);
556
-
557
558
  const rules = {
558
559
  [rule]: ['on', ruleOptions],
559
560
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/test",
3
- "version": "9.1.0",
3
+ "version": "11.0.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 ",
@@ -65,9 +65,9 @@
65
65
  "@putout/plugin-remove-console": "*",
66
66
  "@putout/plugin-remove-empty": "*",
67
67
  "@putout/plugin-remove-unused-variables": "*",
68
- "c8": "^9.0.0",
69
- "eslint": "^9.0.0-alpha.0",
70
- "eslint-plugin-n": "^17.0.0-0",
68
+ "c8": "^10.0.0",
69
+ "eslint": "^9.0.0",
70
+ "eslint-plugin-n": "^17.0.0",
71
71
  "eslint-plugin-putout": "^22.0.0",
72
72
  "lerna": "^6.0.1",
73
73
  "madrun": "^10.0.0",