@putout/test 13.2.0 → 13.2.2

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
@@ -62,7 +62,7 @@ You can also pass extensions to read from `fixture` directory:
62
62
 
63
63
  ```js
64
64
  const test = createTest(import.meta.url, {
65
- ext: '.wast',
65
+ extension: 'wast',
66
66
  lint: putout,
67
67
  plugins: [
68
68
  ['remove-unused-variables', rmVars],
package/lib/fixture.js ADDED
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ const process = require('node:process');
4
+ const tryCatch = require('try-catch');
5
+
6
+ const isUpdate = () => Boolean(Number(process.env.UPDATE));
7
+ const TS = {
8
+ ENABLED: true,
9
+ DISABLED: false,
10
+ };
11
+
12
+ module.exports.readFixture = (name, extension) => {
13
+ const {readFileSync} = global.__putout_test_fs;
14
+ const [eTS, dataTS] = tryCatch(readFileSync, `${name}.ts`, 'utf8');
15
+
16
+ if (!eTS)
17
+ return [
18
+ dataTS,
19
+ TS.ENABLED,
20
+ 'ts',
21
+ ];
22
+
23
+ const [eJS, dataJS] = tryCatch(readFileSync, `${name}.js`, 'utf8');
24
+
25
+ if (!eJS)
26
+ return [
27
+ dataJS,
28
+ TS.DISABLED,
29
+ 'js',
30
+ ];
31
+
32
+ if (extension) {
33
+ const [e, data] = tryCatch(readFileSync, `${name}.${extension}`, 'utf8');
34
+
35
+ if (!e)
36
+ return [
37
+ data,
38
+ TS.DISABLED,
39
+ extension,
40
+ ];
41
+ }
42
+
43
+ throw eJS;
44
+ };
45
+
46
+ module.exports.writeFixture = ({full, code, extension}) => {
47
+ const {writeFileSync} = global.__putout_test_fs;
48
+ writeFileSync(`${full}-fix.${extension}`, code);
49
+ };
50
+
51
+ module.exports.rmFixture = (name) => {
52
+ const {unlinkSync} = global.__putout_test_fs;
53
+
54
+ if (!isUpdate())
55
+ return;
56
+
57
+ tryCatch(unlinkSync, `${name}.js`);
58
+ tryCatch(unlinkSync, `${name}.ts`);
59
+ };
package/lib/test.js CHANGED
@@ -11,7 +11,6 @@ const {
11
11
  unlinkSync,
12
12
  } = require('node:fs');
13
13
 
14
- const tryCatch = require('try-catch');
15
14
  const test = require('supertape');
16
15
  const putout = require('putout');
17
16
  const currify = require('currify');
@@ -19,7 +18,13 @@ const {createProgress} = require('@putout/engine-runner/progress');
19
18
 
20
19
  const {createError} = require('./create-error');
21
20
  const {preTest} = require('./pre-test');
22
- const maybeArray = (a) => isArray(a) ? a : [a];
21
+
22
+ const {
23
+ readFixture,
24
+ writeFixture,
25
+ rmFixture,
26
+ } = require('./fixture');
27
+
23
28
  const {isArray} = Array;
24
29
  const isString = (a) => typeof a === 'string';
25
30
  const isObject = (a) => typeof a === 'object';
@@ -43,68 +48,6 @@ const fail = (t, message) => {
43
48
  return __putout_test_fail(message);
44
49
  };
45
50
 
46
- const TS = {
47
- ENABLED: true,
48
- DISABLED: false,
49
- };
50
-
51
- const readFixture = (name, ext) => {
52
- const {readFileSync} = global.__putout_test_fs;
53
- const [eTS, dataTS] = tryCatch(readFileSync, `${name}.ts`, 'utf8');
54
-
55
- if (!eTS)
56
- return [
57
- dataTS,
58
- TS.ENABLED,
59
- '.ts',
60
- ];
61
-
62
- const [eJS, dataJS] = tryCatch(readFileSync, `${name}.js`, 'utf8');
63
-
64
- if (!eJS)
65
- return [
66
- dataJS,
67
- TS.DISABLED,
68
- '.js',
69
- ];
70
-
71
- for (const currentExt of maybeArray(ext)) {
72
- const [e, data] = tryCatch(readFileSync, `${name}${currentExt}`, 'utf8');
73
-
74
- if (!e)
75
- return [
76
- data,
77
- TS.DISABLED,
78
- currentExt,
79
- ];
80
- }
81
-
82
- throw eJS;
83
- };
84
-
85
- const writeFixture = ({full, code, currentExt}) => {
86
- writeSourceFixture({
87
- full: `${full}-fix`,
88
- code,
89
- currentExt,
90
- });
91
- };
92
-
93
- const writeSourceFixture = ({full, code, currentExt}) => {
94
- const {writeFileSync} = global.__putout_test_fs;
95
- writeFileSync(`${full}${currentExt}`, code);
96
- };
97
-
98
- const rmFixture = (name) => {
99
- const {unlinkSync} = global.__putout_test_fs;
100
-
101
- if (!isUpdate())
102
- return;
103
-
104
- tryCatch(unlinkSync, `${name}.js`);
105
- tryCatch(unlinkSync, `${name}.ts`);
106
- };
107
-
108
51
  module.exports = createTest;
109
52
  module.exports.createTest = createTest;
110
53
 
@@ -119,7 +62,7 @@ function createTest(dir, maybeOptions) {
119
62
  dir = join(dir, 'fixture');
120
63
 
121
64
  const {
122
- ext = [],
65
+ extension = [],
123
66
  lint = putout,
124
67
  ...options
125
68
  } = parseOptions(maybeOptions);
@@ -128,7 +71,7 @@ function createTest(dir, maybeOptions) {
128
71
 
129
72
  const linterOptions = {
130
73
  lint,
131
- ext,
74
+ extension,
132
75
  };
133
76
 
134
77
  preTest(test, plugin);
@@ -353,11 +296,11 @@ const progressWithOptions = (dir, options) => (t) => async (name, pluginOptions,
353
296
  };
354
297
 
355
298
  const transform = currify((dir, linterOptions, options, t, name, transformed = null, addons = {}) => {
356
- const {lint, ext} = linterOptions;
299
+ const {lint, extension} = linterOptions;
357
300
  const {plugins} = options;
358
301
  const full = join(dir, name);
359
302
  const isStr = isString(transformed);
360
- const [input, isTS, currentExt] = readFixture(full, ext);
303
+ const [input, isTS, currentExtension] = readFixture(full, extension);
361
304
 
362
305
  if (!isStr)
363
306
  addons = transformed;
@@ -380,22 +323,21 @@ const transform = currify((dir, linterOptions, options, t, name, transformed = n
380
323
  writeFixture({
381
324
  full,
382
325
  code,
383
-
384
- currentExt,
326
+ extension: currentExtension,
385
327
  });
386
328
  return t.pass('fixed fixture updated');
387
329
  }
388
330
 
389
- const [output] = isStr ? [transformed] : readFixture(`${full}-fix`, ext);
331
+ const [output] = isStr ? [transformed] : readFixture(`${full}-fix`, extension);
390
332
 
391
333
  return t.equal(code, output);
392
334
  });
393
335
 
394
336
  const transformWithOptions = currify((dir, linterOptions, options, t, name, pluginOptions) => {
395
- const {lint, ext} = linterOptions;
337
+ const {lint, extension} = linterOptions;
396
338
 
397
339
  const full = join(dir, name);
398
- const [input, isTS, currentExt] = readFixture(full, ext);
340
+ const [input, isTS, currentExtension] = readFixture(full, extension);
399
341
 
400
342
  const rule = parseRule(options);
401
343
 
@@ -413,12 +355,12 @@ const transformWithOptions = currify((dir, linterOptions, options, t, name, plug
413
355
  writeFixture({
414
356
  full,
415
357
  code,
416
- currentExt,
358
+ extension: currentExtension,
417
359
  });
418
360
  return t.pass('fixed fixture updated');
419
361
  }
420
362
 
421
- const [output] = readFixture(`${full}-fix`, ext);
363
+ const [output] = readFixture(`${full}-fix`, extension);
422
364
 
423
365
  return t.equal(code, output);
424
366
  });
@@ -430,9 +372,9 @@ const parseRule = ({plugins}) => {
430
372
  };
431
373
 
432
374
  const noTransformWithOptions = currify((dir, linterOptions, options, t, name, ruleOptions) => {
433
- const {lint, ext} = linterOptions;
375
+ const {lint, extension} = linterOptions;
434
376
  const full = join(dir, name);
435
- const [input, isTS, currentExt] = readFixture(full, ext);
377
+ const [input, isTS, currentExtension] = readFixture(full, extension);
436
378
 
437
379
  rmFixture(`${full}-fix`);
438
380
 
@@ -448,11 +390,10 @@ const noTransformWithOptions = currify((dir, linterOptions, options, t, name, ru
448
390
  });
449
391
 
450
392
  if (isUpdate()) {
451
- writeSourceFixture({
393
+ writeFixture({
452
394
  full,
453
395
  code,
454
-
455
- currentExt,
396
+ extension: currentExtension,
456
397
  });
457
398
 
458
399
  return t.pass('source fixture updated');
@@ -462,14 +403,14 @@ const noTransformWithOptions = currify((dir, linterOptions, options, t, name, ru
462
403
  });
463
404
 
464
405
  const noTransform = currify((dir, linterOptions, options, t, name, addons = {}) => {
465
- const {lint, ext} = linterOptions;
406
+ const {lint, extension} = linterOptions;
466
407
  const full = join(dir, name);
467
- const [fixture] = readFixture(full, ext);
408
+ const [fixture] = readFixture(full, extension);
468
409
 
469
410
  rmFixture(`${full}-fix`);
470
411
 
471
412
  const {plugins} = options;
472
- const [input, isTS, currentExt] = readFixture(full, ext);
413
+ const [input, isTS] = readFixture(full, extension);
473
414
 
474
415
  const {code} = lint(input, {
475
416
  isTS,
@@ -481,10 +422,10 @@ const noTransform = currify((dir, linterOptions, options, t, name, addons = {})
481
422
  });
482
423
 
483
424
  if (isUpdate()) {
484
- writeSourceFixture({
425
+ writeFixture({
485
426
  full,
486
427
  code,
487
- currentExt,
428
+ extension,
488
429
  });
489
430
 
490
431
  return t.pass('source fixture updated');
@@ -513,11 +454,11 @@ const noTransformCode = currify((linterOptions, options, t, input) => {
513
454
  const getMessage = ({message}) => message;
514
455
 
515
456
  const report = (dir, linterOptions, options) => (t) => (name, message, plugins) => {
516
- const {lint, ext} = linterOptions;
457
+ const {lint, extension} = linterOptions;
517
458
  checkReport(name, message);
518
459
 
519
460
  const full = join(dir, name);
520
- const [source, isTS] = readFixture(full, ext);
461
+ const [source, isTS] = readFixture(full, extension);
521
462
 
522
463
  const addT = reportCode(lint, {
523
464
  isTS,
@@ -530,9 +471,9 @@ const report = (dir, linterOptions, options) => (t) => (name, message, plugins)
530
471
  };
531
472
 
532
473
  const noReport = currify((dir, linterOptions, options, t, name) => {
533
- const {lint, ext} = linterOptions;
474
+ const {lint, extension} = linterOptions;
534
475
  const full = join(dir, name);
535
- const [source, isTS] = readFixture(full, ext);
476
+ const [source, isTS] = readFixture(full, extension);
536
477
 
537
478
  rmFixture(`${full}-fix`);
538
479
 
@@ -545,9 +486,9 @@ const noReport = currify((dir, linterOptions, options, t, name) => {
545
486
  module.exports._createNoReport = noReport;
546
487
 
547
488
  const noReportAfterTransform = currify((dir, linterOptions, options, t, name, addons = {}) => {
548
- const {lint, ext} = linterOptions;
489
+ const {lint, extension} = linterOptions;
549
490
  const full = join(dir, name);
550
- const [source, isTS] = readFixture(full, ext);
491
+ const [source, isTS] = readFixture(full, extension);
551
492
 
552
493
  return noReportCodeAfterTransform(lint, {
553
494
  isTS,
@@ -558,9 +499,9 @@ const noReportAfterTransform = currify((dir, linterOptions, options, t, name, ad
558
499
  module.exports._createNoReportAfterTransform = noReportAfterTransform;
559
500
 
560
501
  const noReportAfterTransformWithOptions = currify((dir, linterOptions, options, t, name, ruleOptions) => {
561
- const {lint, ext} = linterOptions;
502
+ const {lint, extension} = linterOptions;
562
503
  const full = join(dir, name);
563
- const [source, isTS] = readFixture(full, ext);
504
+ const [source, isTS] = readFixture(full, extension);
564
505
  const rule = parseRule(options);
565
506
 
566
507
  const rules = {
@@ -580,9 +521,9 @@ const noReportAfterTransformWithOptions = currify((dir, linterOptions, options,
580
521
  module.exports._createNoReportAfterTransformWithOptions = noReportAfterTransformWithOptions;
581
522
 
582
523
  const reportWithOptions = currify((dir, linterOptions, options, t, name, message, ruleOptions) => {
583
- const {lint, ext} = linterOptions;
524
+ const {lint, extension} = linterOptions;
584
525
  const full = join(dir, name);
585
- const [source, isTS] = readFixture(full, ext);
526
+ const [source, isTS] = readFixture(full, extension);
586
527
 
587
528
  const rule = parseRule(options);
588
529
 
@@ -602,9 +543,9 @@ const reportWithOptions = currify((dir, linterOptions, options, t, name, message
602
543
  });
603
544
 
604
545
  const noReportWithOptions = currify((dir, linterOptions, options, t, name, ruleOptions) => {
605
- const {lint, ext} = linterOptions;
546
+ const {lint, extension} = linterOptions;
606
547
  const full = join(dir, name);
607
- const [source, isTS] = readFixture(full, ext);
548
+ const [source, isTS] = readFixture(full, extension);
608
549
 
609
550
  rmFixture(`${full}-fix`);
610
551
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/test",
3
- "version": "13.2.0",
3
+ "version": "13.2.2",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Test runner for 🐊Putout plugins ",
@@ -66,7 +66,7 @@
66
66
  "@putout/plugin-putout": "*",
67
67
  "@putout/plugin-remove-console": "*",
68
68
  "@putout/plugin-remove-unused-variables": "*",
69
- "@putout/processor-wasm": "^3.0.0",
69
+ "@putout/processor-wasm": "*",
70
70
  "c8": "^10.0.0",
71
71
  "eslint": "^9.0.0",
72
72
  "eslint-plugin-n": "^17.0.0",