@putout/test 3.7.3 → 4.0.1

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.
Files changed (3) hide show
  1. package/README.md +37 -36
  2. package/lib/test.js +57 -42
  3. package/package.json +12 -10
package/README.md CHANGED
@@ -1,11 +1,9 @@
1
- # @putout/test [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
1
+ # @putout/test [![NPM version][NPMIMGURL]][NPMURL]
2
2
 
3
3
  [NPMIMGURL]: https://img.shields.io/npm/v/@putout/test.svg?style=flat&longCache=true
4
4
  [NPMURL]: https://npmjs.org/package/@putout/test "npm"
5
- [DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/test-runner
6
- [DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/test-runner
7
5
 
8
- Test runner for `putout plugins`. Basically it is [supercharged `tape`](https://github.com/coderaiser/supertape) with aditional asseritions:
6
+ Test runner for [🐊`Putout`](https://github.com/coderaiser/putout#plugins-api). Basically it is [supercharged `tape`](https://github.com/coderaiser/supertape) with aditional asseritions:
9
7
 
10
8
  ## Install
11
9
 
@@ -23,9 +21,9 @@ UPDATE=1 tape test/*.js
23
21
 
24
22
  ## Plugins API
25
23
 
26
- ### report(filename, message)
24
+ ### `report(filename, message | []messages)`
27
25
 
28
- checks error message of a plugin
26
+ checks error message (or messages) of a plugin
29
27
 
30
28
  ```js
31
29
  test('remove usless variables: for-of', (t) => {
@@ -34,7 +32,7 @@ test('remove usless variables: for-of', (t) => {
34
32
  });
35
33
  ```
36
34
 
37
- ### reportCode(input, message)
35
+ ### `reportCode(input, message)`
38
36
 
39
37
  checks error message of a plugin from `input` code
40
38
 
@@ -45,7 +43,7 @@ test('remove debugger: report', (t) => {
45
43
  });
46
44
  ```
47
45
 
48
- ### transform(filename [, output, plugins])
46
+ ### `transform(filename [, output, plugins])`
49
47
 
50
48
  check transform of `filename.js` -> `filename-fix.js` in `test/fixtures` directory
51
49
 
@@ -58,7 +56,7 @@ test('remove usless variables: for-of', (t) => {
58
56
  });
59
57
  ```
60
58
 
61
- ### transformCode(input, output)
59
+ ### `transformCode(input, output)`
62
60
 
63
61
  check transform of `input` -> `output` code
64
62
 
@@ -69,7 +67,7 @@ test('remove-console: property identifier: code', (t) => {
69
67
  });
70
68
  ```
71
69
 
72
- ### reportWithOptions(filename, options)
70
+ ### `reportWithOptions(filename, options)`
73
71
 
74
72
  check report of `filename.js` with `options`
75
73
 
@@ -77,7 +75,7 @@ check report of `filename.js` with `options`
77
75
  test('putout: test: reportWithOptions', (t) => {
78
76
  const cache = new Map();
79
77
  cache.set('x', 'y');
80
-
78
+
81
79
  t.reportWithOptions('remove-import', 'avoid imports', {
82
80
  cache,
83
81
  });
@@ -85,14 +83,14 @@ test('putout: test: reportWithOptions', (t) => {
85
83
  });
86
84
  ```
87
85
 
88
- ### noReportWithOptions(filename, options)
86
+ ### `noReportWithOptions(filename, options)`
89
87
 
90
88
  check no report of `filename.js` with `options`
91
89
 
92
90
  ```js
93
91
  test('putout: test: noReportWithOptions', (t) => {
94
92
  const cache = new Map();
95
-
93
+
96
94
  t.noReportWithOptions('remove-import', {
97
95
  cache,
98
96
  });
@@ -100,7 +98,7 @@ test('putout: test: noReportWithOptions', (t) => {
100
98
  });
101
99
  ```
102
100
 
103
- ### transformWithOptions(filename, options)
101
+ ### `transformWithOptions(filename, options)`
104
102
 
105
103
  check transform of `filename.js` with `options`
106
104
 
@@ -109,12 +107,11 @@ test('putout: plugin: declare-undefined-variables: transform: parse', (t) => {
109
107
  t.transformWithOptions('parse', {
110
108
  dismiss: ['assign', 'stringify'],
111
109
  });
112
-
113
110
  t.end();
114
111
  });
115
112
  ```
116
113
 
117
- ### noTransformWithOptions(filename, options)
114
+ ### `noTransformWithOptions(filename, options)`
118
115
 
119
116
  When file should not be transformed:
120
117
 
@@ -125,7 +122,7 @@ test('test: declared', (t) => {
125
122
  });
126
123
  ```
127
124
 
128
- ### noTransformWithOptions(filename, options)
125
+ ### `noTransformWithOptions(filename, options)`
129
126
 
130
127
  check transform of `filename.js` with `options`
131
128
 
@@ -138,7 +135,7 @@ test('putout: plugin: declare-undefined-variables: transform: assign: dismiss',
138
135
  });
139
136
  ```
140
137
 
141
- ### noReport(filename)
138
+ ### `noReport(filename)`
142
139
 
143
140
  checks error message of a plugin not produces
144
141
 
@@ -149,9 +146,9 @@ test('plugin-putout: check-replace-code: no report: typescript', (t) => {
149
146
  });
150
147
  ```
151
148
 
152
- ### noReportAfterTransform(filename)
149
+ ### `noReportAfterTransform(filename)`
153
150
 
154
- checks error message of a plugin not produces
151
+ checks error message of a plugin not produced
155
152
 
156
153
  ```js
157
154
  test('test: no report after transform', (t) => {
@@ -160,9 +157,9 @@ test('test: no report after transform', (t) => {
160
157
  });
161
158
  ```
162
159
 
163
- ### noTransform(filename)
160
+ ### `noTransform(filename)`
164
161
 
165
- check transform of `filename.js` produce nothing new
162
+ check transform of `filename.js` produce nothing
166
163
 
167
164
  ```js
168
165
  test('plugin-apply-numeric-separators: no transform: hex', (t) => {
@@ -171,29 +168,33 @@ test('plugin-apply-numeric-separators: no transform: hex', (t) => {
171
168
  });
172
169
  ```
173
170
 
174
- ### format(formatter, filename)
171
+ ### `format(formatter, filename)`
175
172
 
176
173
  check file name formatting (pass `process.env.UPDATE=1` to save fixture)
177
174
 
178
- ### noFormat
175
+ ```js
176
+ test('formatter: codeframe', async ({format}) => {
177
+ await format(codeframe);
178
+ });
179
+ ```
180
+
181
+ ### `noFormat`
179
182
 
180
183
  check that there is no formatting for for such file
181
184
 
182
185
  ```js
183
- test('formatter: codeframe: no', (t) => {
184
- t.noFormat(codeframe, 'no');
185
- t.end();
186
+ test('formatter: codeframe: no', async ({noFormat}) => {
187
+ await noFormat(codeframe, 'no');
186
188
  });
187
189
  ```
188
190
 
189
- ### formatMany(formatter, [filename1, filename2])
191
+ ### `formatMany(formatter, [filename1, filename2])`
190
192
 
191
193
  check file name formatting (pass `process.env.UPDATE=1` to save fixture)
192
194
 
193
195
  ```js
194
- test('formatter: dump: many', (t) => {
195
- t.formatMany(dump, ['var', 'var']);
196
- t.end();
196
+ test('formatter: dump: many', async ({formatMany}) => {
197
+ await formatMany(dump, ['var', 'var']);
197
198
  });
198
199
  ```
199
200
 
@@ -244,7 +245,7 @@ const test = createTest(__dirname, {
244
245
 
245
246
  ```
246
247
 
247
- ### process(filename [, plugins, ])
248
+ ### `process(filename [, plugins, ])`
248
249
 
249
250
  Example:
250
251
 
@@ -258,19 +259,19 @@ test('putout: processor: json', async ({process}) => {
258
259
  });
259
260
  ```
260
261
 
261
- ### noProcess(filename [, plugins, processors])
262
+ ### `noProcess(filename [, plugins, processors])`
262
263
 
263
264
  Check that filename would not be processed.
264
265
 
265
266
  Example:
266
267
 
267
268
  ```js
268
- test('putout: process: json: no process', async (t) => {
269
- await t.noProcess('eslintrc', [], ['json']);
269
+ test('putout: process: json: no process', async ({noProcess}) => {
270
+ await noProcess('eslintrc', [], ['json']);
270
271
  });
271
272
  ```
272
273
 
273
- ### comparePlaces(filename, places)
274
+ ### `comparePlaces(filename, places)`
274
275
 
275
276
  ```js
276
277
  test('putout: processor: css: places', async ({comparePlaces}) => {
package/lib/test.js CHANGED
@@ -19,6 +19,15 @@ const {isArray} = Array;
19
19
  const {keys, entries} = Object;
20
20
 
21
21
  const {UPDATE} = process.env;
22
+ global.__putout_test_update = UPDATE;
23
+ global.__putout_test_fs = {
24
+ readFileSync,
25
+ writeFileSync,
26
+ existsSync,
27
+ };
28
+
29
+ const isUpdate = () => UPDATE || global.__putout_test_update;
30
+
22
31
  const TS = {
23
32
  ENABLED: true,
24
33
  DISABLED: false,
@@ -34,6 +43,8 @@ const readFixture = (name) => {
34
43
  };
35
44
 
36
45
  module.exports = (dir, plugin, rules) => {
46
+ const update = isUpdate();
47
+
37
48
  dir = join(dir, 'fixture');
38
49
  const plugins = getPlugins(plugin);
39
50
 
@@ -59,14 +70,14 @@ module.exports = (dir, plugin, rules) => {
59
70
  }),
60
71
 
61
72
  formatSave: formatSave({dir, plugins, rules}),
62
- format: (UPDATE ? formatSave : format)({dir, plugins, rules}),
73
+ format: (update ? formatSave : format)({dir, plugins, rules}),
63
74
  formatManySave: formatManySave({dir, plugins, rules}),
64
- formatMany: (UPDATE ? formatManySave : formatMany)({dir, plugins, rules}),
75
+ formatMany: (update ? formatManySave : formatMany)({dir, plugins, rules}),
65
76
  noFormat: noFormat({dir, plugins, rules}),
66
77
  });
67
78
  };
68
79
 
69
- const format = currify(({dir, plugins, rules}, t, formatter, name, formatterOptions = {}) => {
80
+ const format = currify(({dir, plugins, rules}, t) => async (formatter, name, formatterOptions = {}) => {
70
81
  const full = join(dir, name);
71
82
  const outputName = `${full}-format`;
72
83
  const [input, isTS] = readFixture(full);
@@ -75,7 +86,7 @@ const format = currify(({dir, plugins, rules}, t, formatter, name, formatterOpti
75
86
  const {places} = putout(input, {fixCount: 1, isTS, plugins, rules});
76
87
 
77
88
  const report = putout.initReport();
78
- const result = report(formatter, {
89
+ const result = await report(formatter, {
79
90
  formatterOptions,
80
91
  name,
81
92
  source: input,
@@ -87,14 +98,14 @@ const format = currify(({dir, plugins, rules}, t, formatter, name, formatterOpti
87
98
  return {is, output, result};
88
99
  });
89
100
 
90
- const noFormat = currify(({dir, plugins, rules}, t, formatter, name, formatterOptions = {}) => {
101
+ const noFormat = currify(({dir, plugins, rules}, t) => async (formatter, name, formatterOptions = {}) => {
91
102
  const full = join(dir, name);
92
103
  const [input] = readFixture(full);
93
104
 
94
105
  const {places} = putout(input, {plugins, rules});
95
106
 
96
107
  const report = putout.initReport();
97
- const result = report(formatter, {
108
+ const result = await report(formatter, {
98
109
  name,
99
110
  places,
100
111
  formatterOptions,
@@ -105,7 +116,7 @@ const noFormat = currify(({dir, plugins, rules}, t, formatter, name, formatterOp
105
116
  return {is, output, result};
106
117
  });
107
118
 
108
- const formatMany = currify(({dir, plugins, rules}, t, formatter, names, formatterOptions = {}) => {
119
+ const formatMany = currify(({dir, plugins, rules}, t) => async (formatter, names, formatterOptions = {}) => {
109
120
  const joinTwo = (a) => (b) => join(a, b);
110
121
  const fullNames = names.map(joinTwo(dir));
111
122
 
@@ -124,7 +135,7 @@ const formatMany = currify(({dir, plugins, rules}, t, formatter, names, formatte
124
135
  rules,
125
136
  });
126
137
 
127
- result += report(formatter, {
138
+ result += await report(formatter, {
128
139
  name,
129
140
  formatterOptions,
130
141
  source: input,
@@ -142,52 +153,54 @@ const formatMany = currify(({dir, plugins, rules}, t, formatter, names, formatte
142
153
  return {is, output, result};
143
154
  });
144
155
 
145
- const formatManySave = currify(({dir, plugins, rules}, t, formatter, names, options = {}) => {
156
+ const formatManySave = currify(({dir, plugins, rules}, t) => async (formatter, names, options = {}) => {
157
+ const {
158
+ existsSync,
159
+ writeFileSync,
160
+ } = global.__putout_test_fs;
161
+
146
162
  const name = `${names.join('-')}-format.js`;
147
163
  const outputName = join(dir, name);
148
164
 
149
165
  if (!existsSync(outputName))
150
166
  writeFileSync(outputName, '');
151
167
 
168
+ const runFormat = await formatMany({dir, plugins, rules}, t);
169
+
152
170
  const {
153
171
  is,
154
172
  output,
155
173
  result,
156
- } = formatMany(
157
- {dir,
158
- plugins,
159
- rules},
160
- t,
161
- formatter,
162
- names,
163
- options,
164
- );
174
+ } = await runFormat(formatter, names, options);
165
175
 
166
176
  writeFileSync(outputName, result);
167
177
 
168
178
  return {is, output, result};
169
179
  });
170
180
 
171
- const formatSave = currify(({dir, plugins, rules}, t, formatter, name, options = {}) => {
181
+ const formatSave = currify(({dir, plugins, rules}, t) => async (formatter, name, options = {}) => {
182
+ const {
183
+ existsSync,
184
+ writeFileSync,
185
+ } = global.__putout_test_fs;
186
+
172
187
  const full = join(dir, name);
173
188
  const outputName = `${full}-format.js`;
174
189
 
175
190
  if (!existsSync(outputName))
176
191
  writeFileSync(outputName, '');
177
192
 
193
+ const runFormat = format({
194
+ dir,
195
+ plugins,
196
+ rules,
197
+ }, t);
198
+
178
199
  const {
179
200
  is,
180
201
  output,
181
202
  result,
182
- } = format(
183
- {dir,
184
- plugins,
185
- rules},
186
- t,
187
- formatter,
188
- name,
189
- options,
190
- );
203
+ } = await runFormat(formatter, name, options);
191
204
 
192
205
  writeFileSync(outputName, result);
193
206
 
@@ -209,17 +222,19 @@ const transform = currify(({dir, plugins, rules}, t, name, transformed = null, a
209
222
 
210
223
  addons = addons || {};
211
224
 
212
- plugins[0] = {
213
- ...plugins[0],
214
- ...addons,
215
- };
216
-
217
- const {code} = putout(input, {isTS, plugins, rules});
225
+ const {code} = putout(input, {
226
+ isTS,
227
+ rules,
228
+ plugins: [{
229
+ ...plugins[0],
230
+ ...addons,
231
+ }],
232
+ });
218
233
 
219
- if (UPDATE)
234
+ if (isUpdate())
220
235
  writeFileSync(`${full}-fix.js`, code);
221
236
 
222
- return t.equal(code, output, 'should equal');
237
+ return t.equal(code, output);
223
238
  });
224
239
 
225
240
  const transformWithOptions = currify(({dir, plugins}, t, name, options) => {
@@ -236,10 +251,10 @@ const transformWithOptions = currify(({dir, plugins}, t, name, options) => {
236
251
 
237
252
  const {code} = putout(input, {isTS, plugins, rules});
238
253
 
239
- if (UPDATE)
254
+ if (isUpdate())
240
255
  writeFileSync(`${full}-fix.js`, code);
241
256
 
242
- return t.equal(code, output, 'should equal');
257
+ return t.equal(code, output);
243
258
  });
244
259
 
245
260
  const noTransformWithOptions = currify(({dir, plugins}, t, name, options) => {
@@ -255,7 +270,7 @@ const noTransformWithOptions = currify(({dir, plugins}, t, name, options) => {
255
270
 
256
271
  const {code} = putout(input, {isTS, plugins, rules});
257
272
 
258
- return t.equal(code, input, 'should equal');
273
+ return t.equal(code, input);
259
274
  });
260
275
 
261
276
  const noTransform = currify(({dir, plugins, rules}, t, name, addons = {}) => {
@@ -267,12 +282,12 @@ const noTransform = currify(({dir, plugins, rules}, t, name, addons = {}) => {
267
282
 
268
283
  const transformCode = currify(({plugins, rules}, t, input, output, isTS = false) => {
269
284
  const {code} = putout(input, {isTS, plugins, rules});
270
- return t.equal(code, output, 'should equal');
285
+ return t.equal(code, output);
271
286
  });
272
287
 
273
288
  const noTransformCode = currify(({plugins, rules}, t, input) => {
274
289
  const {code} = putout(input, {plugins, rules});
275
- return t.equal(code, input, 'should equal');
290
+ return t.equal(code, input);
276
291
  });
277
292
 
278
293
  const getMessage = ({message}) => message;
@@ -342,7 +357,7 @@ const reportCode = currify(({plugins, rules, isTS}, t, source, message) => {
342
357
  if (isArray(message))
343
358
  return t.deepEqual(resultMessages, message, 'should equal');
344
359
 
345
- return t.equal(resultMessages[0], message, 'should equal');
360
+ return t.equal(resultMessages[0], message);
346
361
  });
347
362
 
348
363
  const noReportCode = currify(({plugins, rules, isTS}, t, source) => {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@putout/test",
3
- "version": "3.7.3",
3
+ "version": "4.0.1",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
5
  "description": "test runner for putout plugins ",
6
- "homepage": "https://github.com/coderaiser/putout/tree/master/packages/test",
6
+ "homepage": "https://github.com/coderaiser/putout/tree/master/packages/test#readme",
7
7
  "main": "lib/test.js",
8
8
  "bin": {
9
9
  "tape": "bin/test.mjs"
@@ -44,20 +44,22 @@
44
44
  "runner"
45
45
  ],
46
46
  "devDependencies": {
47
- "@cloudcmd/stub": "^3.0.0",
48
- "@putout/formatter-dump": "^2.0.1",
49
- "@putout/formatter-progress": "^2.0.0",
50
- "@putout/plugin-remove-console": "^3.1.0",
51
- "@putout/plugin-remove-empty": "^5.1.0",
47
+ "@putout/formatter-dump": "*",
48
+ "@putout/formatter-progress": "*",
49
+ "@putout/plugin-extract-object-properties": "*",
50
+ "@putout/plugin-putout": "*",
51
+ "@putout/plugin-remove-console": "*",
52
+ "@putout/plugin-remove-empty": "*",
52
53
  "@putout/plugin-remove-unused-variables": "*",
53
54
  "c8": "^7.5.0",
54
- "eslint": "^8.0.0-beta.0",
55
+ "eslint": "^8.0.1",
55
56
  "eslint-plugin-node": "^11.0.0",
56
- "eslint-plugin-putout": "^9.0.0",
57
+ "eslint-plugin-putout": "^12.0.0",
57
58
  "lerna": "^4.0.0",
58
59
  "madrun": "^8.0.1",
59
60
  "mock-require": "^3.0.3",
60
- "nodemon": "^2.0.1"
61
+ "nodemon": "^2.0.1",
62
+ "simport": "^1.2.0"
61
63
  },
62
64
  "license": "MIT",
63
65
  "engines": {