@putout/test 13.1.0 → 13.2.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.
package/README.md CHANGED
@@ -58,6 +58,18 @@ const test = createTest(import.meta.url, {
58
58
  });
59
59
  ```
60
60
 
61
+ You can also pass extensions to read from `fixture` directory:
62
+
63
+ ```js
64
+ const test = createTest(import.meta.url, {
65
+ extension: 'wast',
66
+ lint: putout,
67
+ plugins: [
68
+ ['remove-unused-variables', rmVars],
69
+ ],
70
+ });
71
+ ```
72
+
61
73
  ### `report(filename, message: string | string[], plugins?: PutoutPlugin[])`
62
74
 
63
75
  Check error message (or messages) of a plugin:
package/lib/fixture.js ADDED
@@ -0,0 +1,56 @@
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
+ ];
21
+
22
+ const [eJS, dataJS] = tryCatch(readFileSync, `${name}.js`, 'utf8');
23
+
24
+ if (!eJS)
25
+ return [
26
+ dataJS,
27
+ TS.DISABLED,
28
+ ];
29
+
30
+ if (extension) {
31
+ const [e, data] = tryCatch(readFileSync, `${name}.${extension}`, 'utf8');
32
+
33
+ if (!e)
34
+ return [
35
+ data,
36
+ TS.DISABLED,
37
+ ];
38
+ }
39
+
40
+ throw eJS;
41
+ };
42
+
43
+ module.exports.writeFixture = ({full, code, extension}) => {
44
+ const {writeFileSync} = global.__putout_test_fs;
45
+ writeFileSync(`${full}-fix.${extension}`, code);
46
+ };
47
+
48
+ module.exports.rmFixture = (name) => {
49
+ const {unlinkSync} = global.__putout_test_fs;
50
+
51
+ if (!isUpdate())
52
+ return;
53
+
54
+ tryCatch(unlinkSync, `${name}.js`);
55
+ tryCatch(unlinkSync, `${name}.ts`);
56
+ };
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');
@@ -20,6 +19,12 @@ const {createProgress} = require('@putout/engine-runner/progress');
20
19
  const {createError} = require('./create-error');
21
20
  const {preTest} = require('./pre-test');
22
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,54 +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) => {
52
- const {readFileSync} = global.__putout_test_fs;
53
- const [e, data] = tryCatch(readFileSync, `${name}.ts`, 'utf8');
54
-
55
- if (!e)
56
- return [
57
- data,
58
- TS.ENABLED,
59
- ];
60
-
61
- return [
62
- readFileSync(`${name}.js`, 'utf8'),
63
- TS.DISABLED,
64
- ];
65
- };
66
-
67
- const writeFixture = ({full, code, isTS}) => {
68
- writeSourceFixture({
69
- full: `${full}-fix`,
70
- code,
71
- isTS,
72
- });
73
- };
74
-
75
- const writeSourceFixture = ({full, code, isTS}) => {
76
- const {writeFileSync} = global.__putout_test_fs;
77
-
78
- if (!isTS)
79
- return writeFileSync(`${full}.js`, code);
80
-
81
- writeFileSync(`${full}.ts`, code);
82
- };
83
-
84
- const rmFixture = (name) => {
85
- const {unlinkSync} = global.__putout_test_fs;
86
-
87
- if (!isUpdate())
88
- return;
89
-
90
- tryCatch(unlinkSync, `${name}.js`);
91
- tryCatch(unlinkSync, `${name}.ts`);
92
- };
93
-
94
51
  module.exports = createTest;
95
52
  module.exports.createTest = createTest;
96
53
 
@@ -104,30 +61,39 @@ const parsePlugin = (plugins) => {
104
61
  function createTest(dir, maybeOptions) {
105
62
  dir = join(dir, 'fixture');
106
63
 
107
- const {lint = putout, ...options} = parseOptions(maybeOptions);
64
+ const {
65
+ extension = [],
66
+ lint = putout,
67
+ ...options
68
+ } = parseOptions(maybeOptions);
108
69
 
109
70
  const plugin = parsePlugin(options.plugins);
110
71
 
72
+ const linterOptions = {
73
+ lint,
74
+ extension,
75
+ };
76
+
111
77
  preTest(test, plugin);
112
78
 
113
79
  return test.extend({
114
- transform: transform(dir, lint, options),
115
- noTransform: noTransform(dir, lint, options),
116
- transformCode: transformCode(lint, options),
117
- noTransformCode: noTransformCode(lint, options),
80
+ transform: transform(dir, linterOptions, options),
81
+ noTransform: noTransform(dir, linterOptions, options),
82
+ transformCode: transformCode(linterOptions, options),
83
+ noTransformCode: noTransformCode(linterOptions, options),
118
84
 
119
85
  progress: progress(dir, options),
120
86
  progressWithOptions: progressWithOptions(dir, options),
121
87
 
122
- transformWithOptions: transformWithOptions(dir, lint, options),
123
- noTransformWithOptions: noTransformWithOptions(dir, lint, options),
88
+ transformWithOptions: transformWithOptions(dir, linterOptions, options),
89
+ noTransformWithOptions: noTransformWithOptions(dir, linterOptions, options),
124
90
 
125
- report: report(dir, lint, options),
126
- noReport: noReport(dir, lint, options),
127
- noReportAfterTransform: noReportAfterTransform(dir, lint, options),
128
- noReportAfterTransformWithOptions: noReportAfterTransformWithOptions(dir, lint, options),
129
- reportWithOptions: reportWithOptions(dir, lint, options),
130
- noReportWithOptions: noReportWithOptions(dir, lint, options),
91
+ report: report(dir, linterOptions, options),
92
+ noReport: noReport(dir, linterOptions, options),
93
+ noReportAfterTransform: noReportAfterTransform(dir, linterOptions, options),
94
+ noReportAfterTransformWithOptions: noReportAfterTransformWithOptions(dir, linterOptions, options),
95
+ reportWithOptions: reportWithOptions(dir, linterOptions, options),
96
+ noReportWithOptions: noReportWithOptions(dir, linterOptions, options),
131
97
  reportCode: reportCode(lint, options),
132
98
  noReportCode: noReportCode(lint, options),
133
99
  format: formatSave(dir, options),
@@ -329,12 +295,12 @@ const progressWithOptions = (dir, options) => (t) => async (name, pluginOptions,
329
295
  return t.deepEqual(result, expected);
330
296
  };
331
297
 
332
- const transform = currify((dir, lint, options, t, name, transformed = null, addons = {}) => {
298
+ const transform = currify((dir, linterOptions, options, t, name, transformed = null, addons = {}) => {
299
+ const {lint, extension} = linterOptions;
333
300
  const {plugins} = options;
334
301
  const full = join(dir, name);
335
302
  const isStr = isString(transformed);
336
-
337
- const [input, isTS] = readFixture(full);
303
+ const [input, isTS] = readFixture(full, extension);
338
304
 
339
305
  if (!isStr)
340
306
  addons = transformed;
@@ -357,20 +323,21 @@ const transform = currify((dir, lint, options, t, name, transformed = null, addo
357
323
  writeFixture({
358
324
  full,
359
325
  code,
360
- isTS,
326
+ extension,
361
327
  });
362
328
  return t.pass('fixed fixture updated');
363
329
  }
364
330
 
365
- const [output] = isStr ? [transformed] : readFixture(`${full}-fix`);
331
+ const [output] = isStr ? [transformed] : readFixture(`${full}-fix`, extension);
366
332
 
367
333
  return t.equal(code, output);
368
334
  });
369
335
 
370
- const transformWithOptions = currify((dir, lint, options, t, name, pluginOptions) => {
371
- const {writeFileSync} = global.__putout_test_fs;
336
+ const transformWithOptions = currify((dir, linterOptions, options, t, name, pluginOptions) => {
337
+ const {lint, extension} = linterOptions;
338
+
372
339
  const full = join(dir, name);
373
- const [input, isTS] = readFixture(full);
340
+ const [input, isTS] = readFixture(full, extension);
374
341
 
375
342
  const rule = parseRule(options);
376
343
 
@@ -385,11 +352,15 @@ const transformWithOptions = currify((dir, lint, options, t, name, pluginOptions
385
352
  });
386
353
 
387
354
  if (isUpdate()) {
388
- writeFileSync(`${full}-fix.js`, code);
355
+ writeFixture({
356
+ full,
357
+ code,
358
+ extension,
359
+ });
389
360
  return t.pass('fixed fixture updated');
390
361
  }
391
362
 
392
- const [output] = readFixture(`${full}-fix`);
363
+ const [output] = readFixture(`${full}-fix`, extension);
393
364
 
394
365
  return t.equal(code, output);
395
366
  });
@@ -400,9 +371,10 @@ const parseRule = ({plugins}) => {
400
371
  return plugin[0] || keys(plugin)[0];
401
372
  };
402
373
 
403
- const noTransformWithOptions = currify((dir, lint, options, t, name, ruleOptions) => {
374
+ const noTransformWithOptions = currify((dir, linterOptions, options, t, name, ruleOptions) => {
375
+ const {lint, extension} = linterOptions;
404
376
  const full = join(dir, name);
405
- const [input, isTS] = readFixture(full);
377
+ const [input, isTS] = readFixture(full, extension);
406
378
 
407
379
  rmFixture(`${full}-fix`);
408
380
 
@@ -418,10 +390,10 @@ const noTransformWithOptions = currify((dir, lint, options, t, name, ruleOptions
418
390
  });
419
391
 
420
392
  if (isUpdate()) {
421
- writeSourceFixture({
393
+ writeFixture({
422
394
  full,
423
395
  code,
424
- isTS,
396
+ extension,
425
397
  });
426
398
 
427
399
  return t.pass('source fixture updated');
@@ -430,14 +402,15 @@ const noTransformWithOptions = currify((dir, lint, options, t, name, ruleOptions
430
402
  return t.equal(code, input);
431
403
  });
432
404
 
433
- const noTransform = currify((dir, lint, options, t, name, addons = {}) => {
405
+ const noTransform = currify((dir, linterOptions, options, t, name, addons = {}) => {
406
+ const {lint, extension} = linterOptions;
434
407
  const full = join(dir, name);
435
- const [fixture] = readFixture(full);
408
+ const [fixture] = readFixture(full, extension);
436
409
 
437
410
  rmFixture(`${full}-fix`);
438
411
 
439
412
  const {plugins} = options;
440
- const [input, isTS] = readFixture(full);
413
+ const [input, isTS] = readFixture(full, extension);
441
414
 
442
415
  const {code} = lint(input, {
443
416
  isTS,
@@ -449,10 +422,10 @@ const noTransform = currify((dir, lint, options, t, name, addons = {}) => {
449
422
  });
450
423
 
451
424
  if (isUpdate()) {
452
- writeSourceFixture({
425
+ writeFixture({
453
426
  full,
454
427
  code,
455
- isTS,
428
+ extension,
456
429
  });
457
430
 
458
431
  return t.pass('source fixture updated');
@@ -461,7 +434,8 @@ const noTransform = currify((dir, lint, options, t, name, addons = {}) => {
461
434
  return t.equal(code, fixture);
462
435
  });
463
436
 
464
- const transformCode = currify((lint, options, t, input, output, isTS = false) => {
437
+ const transformCode = currify((linterOptions, options, t, input, output, isTS = false) => {
438
+ const {lint} = linterOptions;
465
439
  const {code} = lint(input, {
466
440
  isTS,
467
441
  ...options,
@@ -470,18 +444,21 @@ const transformCode = currify((lint, options, t, input, output, isTS = false) =>
470
444
  return t.equal(code, output);
471
445
  });
472
446
 
473
- const noTransformCode = currify((lint, options, t, input) => {
447
+ const noTransformCode = currify((linterOptions, options, t, input) => {
448
+ const {lint} = linterOptions;
474
449
  const {code} = lint(input, options);
450
+
475
451
  return t.equal(code, input);
476
452
  });
477
453
 
478
454
  const getMessage = ({message}) => message;
479
455
 
480
- const report = (dir, lint, options) => (t) => (name, message, plugins) => {
456
+ const report = (dir, linterOptions, options) => (t) => (name, message, plugins) => {
457
+ const {lint, extension} = linterOptions;
481
458
  checkReport(name, message);
482
459
 
483
460
  const full = join(dir, name);
484
- const [source, isTS] = readFixture(full);
461
+ const [source, isTS] = readFixture(full, extension);
485
462
 
486
463
  const addT = reportCode(lint, {
487
464
  isTS,
@@ -493,9 +470,10 @@ const report = (dir, lint, options) => (t) => (name, message, plugins) => {
493
470
  return run(source, message, plugins);
494
471
  };
495
472
 
496
- const noReport = currify((dir, lint, options, t, name) => {
473
+ const noReport = currify((dir, linterOptions, options, t, name) => {
474
+ const {lint, extension} = linterOptions;
497
475
  const full = join(dir, name);
498
- const [source, isTS] = readFixture(full);
476
+ const [source, isTS] = readFixture(full, extension);
499
477
 
500
478
  rmFixture(`${full}-fix`);
501
479
 
@@ -507,9 +485,10 @@ const noReport = currify((dir, lint, options, t, name) => {
507
485
 
508
486
  module.exports._createNoReport = noReport;
509
487
 
510
- const noReportAfterTransform = currify((dir, lint, options, t, name, addons = {}) => {
488
+ const noReportAfterTransform = currify((dir, linterOptions, options, t, name, addons = {}) => {
489
+ const {lint, extension} = linterOptions;
511
490
  const full = join(dir, name);
512
- const [source, isTS] = readFixture(full);
491
+ const [source, isTS] = readFixture(full, extension);
513
492
 
514
493
  return noReportCodeAfterTransform(lint, {
515
494
  isTS,
@@ -519,9 +498,10 @@ const noReportAfterTransform = currify((dir, lint, options, t, name, addons = {}
519
498
 
520
499
  module.exports._createNoReportAfterTransform = noReportAfterTransform;
521
500
 
522
- const noReportAfterTransformWithOptions = currify((dir, lint, options, t, name, ruleOptions) => {
501
+ const noReportAfterTransformWithOptions = currify((dir, linterOptions, options, t, name, ruleOptions) => {
502
+ const {lint, extension} = linterOptions;
523
503
  const full = join(dir, name);
524
- const [source, isTS] = readFixture(full);
504
+ const [source, isTS] = readFixture(full, extension);
525
505
  const rule = parseRule(options);
526
506
 
527
507
  const rules = {
@@ -540,9 +520,10 @@ const noReportAfterTransformWithOptions = currify((dir, lint, options, t, name,
540
520
 
541
521
  module.exports._createNoReportAfterTransformWithOptions = noReportAfterTransformWithOptions;
542
522
 
543
- const reportWithOptions = currify((dir, lint, options, t, name, message, ruleOptions) => {
523
+ const reportWithOptions = currify((dir, linterOptions, options, t, name, message, ruleOptions) => {
524
+ const {lint, extension} = linterOptions;
544
525
  const full = join(dir, name);
545
- const [source, isTS] = readFixture(full);
526
+ const [source, isTS] = readFixture(full, extension);
546
527
 
547
528
  const rule = parseRule(options);
548
529
 
@@ -561,9 +542,10 @@ const reportWithOptions = currify((dir, lint, options, t, name, message, ruleOpt
561
542
  return run(source, message);
562
543
  });
563
544
 
564
- const noReportWithOptions = currify((dir, lint, options, t, name, ruleOptions) => {
545
+ const noReportWithOptions = currify((dir, linterOptions, options, t, name, ruleOptions) => {
546
+ const {lint, extension} = linterOptions;
565
547
  const full = join(dir, name);
566
- const [source, isTS] = readFixture(full);
548
+ const [source, isTS] = readFixture(full, extension);
567
549
 
568
550
  rmFixture(`${full}-fix`);
569
551
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/test",
3
- "version": "13.1.0",
3
+ "version": "13.2.1",
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,6 +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
70
  "c8": "^10.0.0",
70
71
  "eslint": "^9.0.0",
71
72
  "eslint-plugin-n": "^17.0.0",