@putout/test 8.1.1 → 8.2.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 +19 -0
- package/lib/test.js +28 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -245,6 +245,25 @@ test('remove usless variables: for-of', async ({progress}) => {
|
|
|
245
245
|
});
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
+
### `progressWithOptions(filename, options, expected)`
|
|
249
|
+
|
|
250
|
+
Check progress of `filename.js`;
|
|
251
|
+
|
|
252
|
+
```js
|
|
253
|
+
test('remove usless variables: for-of', async ({progressWithOptions}) => {
|
|
254
|
+
const options = {
|
|
255
|
+
from: '/home/coderaiser',
|
|
256
|
+
to: '/',
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
await progressWithOptions('progress', options, {
|
|
260
|
+
i: 0,
|
|
261
|
+
n: 2,
|
|
262
|
+
rule: 'read-all-files',
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
|
|
248
267
|
## Formatters API
|
|
249
268
|
|
|
250
269
|
First you need to create test with:
|
package/lib/test.js
CHANGED
|
@@ -107,6 +107,7 @@ function createTest(dir, maybeOptions) {
|
|
|
107
107
|
noTransformCode: noTransformCode(options),
|
|
108
108
|
|
|
109
109
|
progress: progress(dir, options),
|
|
110
|
+
progressWithOptions: progressWithOptions(dir, options),
|
|
110
111
|
|
|
111
112
|
transformWithOptions: transformWithOptions(dir, options),
|
|
112
113
|
noTransformWithOptions: noTransformWithOptions(dir, options),
|
|
@@ -292,6 +293,31 @@ const progress = (dir, options) => (t) => async (name, expected) => {
|
|
|
292
293
|
return t.deepEqual(result, expected);
|
|
293
294
|
};
|
|
294
295
|
|
|
296
|
+
const progressWithOptions = (dir, options) => (t) => async (name, pluginOptions, expected) => {
|
|
297
|
+
const full = join(dir, name);
|
|
298
|
+
const [input, isTS] = readFixture(full);
|
|
299
|
+
|
|
300
|
+
const rule = parseRule(options);
|
|
301
|
+
const rules = {
|
|
302
|
+
[rule]: ['on', pluginOptions],
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const progress = createProgress();
|
|
306
|
+
|
|
307
|
+
const [[result]] = await Promise.all([
|
|
308
|
+
once(progress, 'file'),
|
|
309
|
+
putout(input, {
|
|
310
|
+
rules,
|
|
311
|
+
progress,
|
|
312
|
+
printer: getPrinter(),
|
|
313
|
+
isTS,
|
|
314
|
+
...options,
|
|
315
|
+
}),
|
|
316
|
+
]);
|
|
317
|
+
|
|
318
|
+
return t.deepEqual(result, expected);
|
|
319
|
+
};
|
|
320
|
+
|
|
295
321
|
const transform = currify((dir, options, t, name, transformed = null, addons = {}) => {
|
|
296
322
|
const {plugins} = options;
|
|
297
323
|
const full = join(dir, name);
|
|
@@ -328,7 +354,7 @@ const transform = currify((dir, options, t, name, transformed = null, addons = {
|
|
|
328
354
|
return t.equal(code, output);
|
|
329
355
|
});
|
|
330
356
|
|
|
331
|
-
const transformWithOptions = currify((dir, options, t, name,
|
|
357
|
+
const transformWithOptions = currify((dir, options, t, name, pluginOptions) => {
|
|
332
358
|
const {writeFileSync} = global.__putout_test_fs;
|
|
333
359
|
const full = join(dir, name);
|
|
334
360
|
const [input, isTS] = readFixture(full);
|
|
@@ -336,7 +362,7 @@ const transformWithOptions = currify((dir, options, t, name, additionalOptions)
|
|
|
336
362
|
const rule = parseRule(options);
|
|
337
363
|
|
|
338
364
|
const rules = {
|
|
339
|
-
[rule]: ['on',
|
|
365
|
+
[rule]: ['on', pluginOptions],
|
|
340
366
|
};
|
|
341
367
|
|
|
342
368
|
const {code} = putout(input, {
|