@putout/test 5.10.0 → 5.12.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.
@@ -1,6 +1,14 @@
1
1
  import {readFile} from 'fs/promises';
2
- import {readFileSync} from 'fs';
3
- import {join} from 'path';
2
+ import {
3
+ readFileSync,
4
+ writeFileSync,
5
+ unlinkSync,
6
+ } from 'fs';
7
+ import {
8
+ join,
9
+ extname,
10
+ basename,
11
+ } from 'path';
4
12
 
5
13
  import eslint from '@putout/eslint';
6
14
  import tryToCatch from 'try-to-catch';
@@ -12,6 +20,21 @@ import tryCatch from 'try-catch';
12
20
  const {keys} = Object;
13
21
  const {isArray} = Array;
14
22
 
23
+ const isUpdate = () => process.env.UPDATE === '1';
24
+ const update = (name, data) => {
25
+ const fn = global.writeFileSync || writeFileSync;
26
+ fn(name, data);
27
+ };
28
+
29
+ const remove = (name) => {
30
+ const ext = extname(name);
31
+ const base = basename(name, ext);
32
+ const fixtureName = name.replace(base, `${base}-fix`);
33
+
34
+ const fn = global.unlinkSync || unlinkSync;
35
+ tryCatch(fn, String(fixtureName));
36
+ };
37
+
15
38
  const getMessage = ({message}) => message;
16
39
  const config = {
17
40
  extends: [
@@ -46,7 +69,7 @@ export const createTest = (url, plugins = {}) => {
46
69
  process: (operator) => async (name, override) => {
47
70
  const full = join(fixtureDir, name);
48
71
  const [resolvedName, code] = await read(full);
49
- const [, fixture] = await read(`${full}-fix`);
72
+ const [fixturePath, fixture] = await read(`${full}-fix`);
50
73
  const fix = true;
51
74
 
52
75
  const [source] = await eslint({
@@ -60,6 +83,11 @@ export const createTest = (url, plugins = {}) => {
60
83
  },
61
84
  });
62
85
 
86
+ if (isUpdate()) {
87
+ update(fixturePath, source);
88
+ return operator.pass('fixture updated');
89
+ }
90
+
63
91
  return operator.equal(source, fixture);
64
92
  },
65
93
  noProcess: (operator) => async (name) => {
@@ -74,6 +102,11 @@ export const createTest = (url, plugins = {}) => {
74
102
  fix,
75
103
  });
76
104
 
105
+ if (isUpdate()) {
106
+ remove(resolvedName);
107
+ return operator.pass('fixture updated');
108
+ }
109
+
77
110
  return operator.equal(source, code);
78
111
  },
79
112
  comparePlaces: (operator) => async (name, expected, override) => {
package/lib/test.js CHANGED
@@ -219,18 +219,11 @@ const formatSave = currify(({dir, plugins, rules}, t) => async (formatter, name,
219
219
  rules,
220
220
  }, t);
221
221
 
222
- const {
223
- is,
224
- output,
225
- result,
226
- } = await runFormat(formatter, name, options);
222
+ const {result} = await runFormat(formatter, name, options);
227
223
 
228
224
  writeFileSync(outputName, result);
229
225
 
230
- return {
231
- is,
232
- output,
233
- };
226
+ return t.pass('fixture updated');
234
227
  });
235
228
 
236
229
  const transform = currify(({dir, plugins, rules}, t, name, transformed = null, addons = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/test",
3
- "version": "5.10.0",
3
+ "version": "5.12.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 ",
@@ -67,7 +67,7 @@
67
67
  "eslint": "^8.0.1",
68
68
  "eslint-plugin-n": "^15.2.4",
69
69
  "eslint-plugin-putout": "^16.0.0",
70
- "lerna": "^5.0.0",
70
+ "lerna": "^6.0.1",
71
71
  "madrun": "^9.0.0",
72
72
  "mock-require": "^3.0.3",
73
73
  "nodemon": "^2.0.1"