@putout/test 7.4.0 → 7.6.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 CHANGED
@@ -209,6 +209,18 @@ test('test: no report after transform', (t) => {
209
209
  });
210
210
  ```
211
211
 
212
+
213
+ ### `noReportAfterTransformWithOptions(filename)`
214
+
215
+ Check error message of a plugin not produced with provided options:
216
+
217
+ ```js
218
+ test('test: no report', (t) => {
219
+ t.noReportAfterTransformWithOptions('file');
220
+ t.end();
221
+ });
222
+ ```
223
+
212
224
  ### `noTransform(filename)`
213
225
 
214
226
  Check transform of `filename.js` produce nothing
@@ -398,7 +410,7 @@ test('test: eslint: transform', (t) => {
398
410
  ### `report(filename, message | []messages)`
399
411
 
400
412
  ```js
401
- test('test: eslint: transform', (t) => {
413
+ test('test: eslint: report', (t) => {
402
414
  t.report('remove-debugger', `Avoid 'debugger' statement`);
403
415
  t.end();
404
416
  });
@@ -1,19 +1,20 @@
1
- import {readFile} from 'fs/promises';
1
+ import {readFile} from 'node:fs/promises';
2
2
  import {
3
3
  readFileSync,
4
4
  writeFileSync,
5
5
  unlinkSync,
6
- } from 'fs';
6
+ } from 'node:fs';
7
7
  import {
8
8
  join,
9
9
  extname,
10
10
  basename,
11
- } from 'path';
11
+ } from 'node:path';
12
12
  import eslint from '@putout/eslint';
13
13
  import tryToCatch from 'try-to-catch';
14
14
  import {extend} from 'supertape';
15
15
  import {lint} from '@putout/eslint/lint';
16
16
  import tryCatch from 'try-catch';
17
+ import process from 'node:process';
17
18
 
18
19
  const {keys} = Object;
19
20
  const {isArray} = Array;
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ const isCorrectPlugin = require('./is-correct-plugin');
4
+ const {entries} = Object;
5
+ const {isArray} = Array;
6
+
7
+ const maybeTuple = (a) => isArray(a) ? a : ['on', a];
8
+ const maybeEntries = (a) => isArray(a) ? a : entries(a).pop();
9
+
10
+ module.exports._maybeEntries = maybeEntries;
11
+ module.exports._maybeTuple = maybeTuple;
12
+
13
+ module.exports.preTest = function preTest(test, plugin) {
14
+ const [name, {
15
+ report,
16
+ find,
17
+ traverse,
18
+ include,
19
+ exclude,
20
+ fix,
21
+ rules,
22
+ replace,
23
+ filter,
24
+ match,
25
+ declare,
26
+ }] = maybeEntries(plugin);
27
+
28
+ const options = {
29
+ checkDuplicates: false,
30
+ };
31
+
32
+ if (rules) {
33
+ test(`${name}: rules is an object`, (t) => {
34
+ t.equal(typeof rules, 'object', 'should export "rules" object');
35
+ t.end();
36
+ }, options);
37
+
38
+ const entries = Object.entries(rules);
39
+
40
+ for (const [entryName, pluginTuple] of entries) {
41
+ const [, plugin] = maybeTuple(pluginTuple);
42
+
43
+ preTest(test, {
44
+ [`${name}/${entryName}`]: plugin,
45
+ });
46
+ }
47
+
48
+ return;
49
+ }
50
+
51
+ if (!declare)
52
+ test(`${name}: report: is function`, (t) => {
53
+ t.equal(typeof report, 'function', `should export 'report' function`);
54
+ t.end();
55
+ }, options);
56
+
57
+ test(`${name}: plugins should be of type: replace, template, traverse or find`, (t) => {
58
+ const result = isCorrectPlugin({
59
+ find,
60
+ fix,
61
+
62
+ traverse,
63
+
64
+ include,
65
+ exclude,
66
+
67
+ filter,
68
+ match,
69
+ replace,
70
+
71
+ declare,
72
+ });
73
+
74
+ t.ok(result, `should export 'replace', 'find', 'traverse', 'include', 'exclude', or 'declare' function`);
75
+ t.end();
76
+ }, options);
77
+ };
@@ -1,5 +1,5 @@
1
- import {dirname} from 'path';
2
- import {fileURLToPath} from 'url';
1
+ import {dirname} from 'node:path';
2
+ import {fileURLToPath} from 'node:url';
3
3
  import * as processor from './index.js';
4
4
 
5
5
  export const createTest = (url, plugins) => {
package/lib/test.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const process = require('node:process');
3
4
  const {join} = require('path');
4
5
 
5
6
  const {
@@ -14,14 +15,12 @@ const test = require('supertape');
14
15
  const putout = require('putout');
15
16
  const currify = require('currify');
16
17
 
17
- const isCorrectPlugin = require('./is-correct-plugin');
18
-
18
+ const {preTest} = require('./pre-test');
19
+ const {isArray} = Array;
19
20
  const isString = (a) => typeof a === 'string';
20
21
  const isObject = (a) => typeof a === 'object';
21
- const {isArray} = Array;
22
22
 
23
- const {keys, entries} = Object;
24
- const maybeEntries = (a) => isArray(a) ? a : entries(a).pop();
23
+ const {keys} = Object;
25
24
 
26
25
  global.__putout_test_fs = {
27
26
  readFileSync,
@@ -83,7 +82,6 @@ const rmFixture = (name) => {
83
82
 
84
83
  module.exports = createTest;
85
84
  module.exports.createTest = createTest;
86
- module.exports._maybeEntries = maybeEntries;
87
85
 
88
86
  const parsePlugin = (plugins) => {
89
87
  if (isArray(plugins))
@@ -112,6 +110,7 @@ function createTest(dir, maybeOptions) {
112
110
  report: report(dir, options),
113
111
  noReport: noReport(dir, options),
114
112
  noReportAfterTransform: noReportAfterTransform(dir, options),
113
+ noReportAfterTransformWithOptions: noReportAfterTransformWithOptions(dir, options),
115
114
  reportWithOptions: reportWithOptions(dir, options),
116
115
  noReportWithOptions: noReportWithOptions(dir, options),
117
116
  reportCode: reportCode(options),
@@ -261,9 +260,8 @@ const toObject = (array) => {
261
260
  const result = {};
262
261
  const first = parsePlugin(array);
263
262
 
264
- if (isObject(first) && !isArray(first)) {
263
+ if (isObject(first) && !isArray(first))
265
264
  return first;
266
- }
267
265
 
268
266
  for (const [name, value] of array) {
269
267
  result[name] = value;
@@ -455,6 +453,27 @@ const noReportAfterTransform = currify((dir, options, t, name) => {
455
453
 
456
454
  module.exports._createNoReportAfterTransform = noReportAfterTransform;
457
455
 
456
+ const noReportAfterTransformWithOptions = currify((dir, options, t, name, ruleOptions) => {
457
+ const full = join(dir, name);
458
+ const [source, isTS] = readFixture(full);
459
+ const rule = parseRule(options);
460
+
461
+ const rules = {
462
+ [rule]: ['on', ruleOptions],
463
+ };
464
+
465
+ return noReportCodeAfterTransform({
466
+ isTS,
467
+ ...options,
468
+ rules: {
469
+ ...options.rules,
470
+ ...rules,
471
+ },
472
+ }, t, source);
473
+ });
474
+
475
+ module.exports._createNoReportAfterTransformWithOptions = noReportAfterTransformWithOptions;
476
+
458
477
  const reportWithOptions = currify((dir, options, t, name, message, ruleOptions) => {
459
478
  const full = join(dir, name);
460
479
  const [source, isTS] = readFixture(full);
@@ -531,67 +550,3 @@ function parseOptions(plugin) {
531
550
 
532
551
  return plugin;
533
552
  }
534
-
535
- function preTest(test, plugin) {
536
- const [name, {
537
- report,
538
- find,
539
- traverse,
540
- include,
541
- exclude,
542
- fix,
543
- rules,
544
- replace,
545
- filter,
546
- match,
547
- declare,
548
- }] = maybeEntries(plugin);
549
-
550
- const options = {
551
- checkDuplicates: false,
552
- };
553
-
554
- if (rules) {
555
- test(`${name}: rules is an object`, (t) => {
556
- t.equal(typeof rules, 'object', 'should export "rules" object');
557
- t.end();
558
- }, options);
559
-
560
- const entries = Object.entries(rules);
561
-
562
- for (const [entryName, plugin] of entries) {
563
- preTest(test, {
564
- [`${name}/${entryName}`]: plugin,
565
- });
566
- }
567
-
568
- return;
569
- }
570
-
571
- if (!declare)
572
- test(`${name}: report: is function`, (t) => {
573
- t.equal(typeof report, 'function', `should export 'report' function`);
574
- t.end();
575
- }, options);
576
-
577
- test(`${name}: plugins should be of type: replace, template, traverse or find`, (t) => {
578
- const result = isCorrectPlugin({
579
- find,
580
- fix,
581
-
582
- traverse,
583
-
584
- include,
585
- exclude,
586
-
587
- filter,
588
- match,
589
- replace,
590
-
591
- declare,
592
- });
593
-
594
- t.ok(result, `should export 'replace', 'find', 'traverse', 'include', 'exclude', or 'declare' function`);
595
- t.end();
596
- }, options);
597
- }
package/lib/test.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import {dirname} from 'path';
2
- import {fileURLToPath} from 'url';
1
+ import {dirname} from 'node:path';
2
+ import {fileURLToPath} from 'node:url';
3
3
  import create from './test.js';
4
4
 
5
5
  export default create;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/test",
3
- "version": "7.4.0",
3
+ "version": "7.6.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 ",