@putout/test 7.3.0 → 7.5.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.
@@ -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,76 @@
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
+
12
+ module.exports.preTest = function preTest(test, plugin) {
13
+ const [name, {
14
+ report,
15
+ find,
16
+ traverse,
17
+ include,
18
+ exclude,
19
+ fix,
20
+ rules,
21
+ replace,
22
+ filter,
23
+ match,
24
+ declare,
25
+ }] = maybeEntries(plugin);
26
+
27
+ const options = {
28
+ checkDuplicates: false,
29
+ };
30
+
31
+ if (rules) {
32
+ test(`${name}: rules is an object`, (t) => {
33
+ t.equal(typeof rules, 'object', 'should export "rules" object');
34
+ t.end();
35
+ }, options);
36
+
37
+ const entries = Object.entries(rules);
38
+
39
+ for (const [entryName, pluginTuple] of entries) {
40
+ const [, plugin] = maybeTuple(pluginTuple);
41
+
42
+ preTest(test, {
43
+ [`${name}/${entryName}`]: plugin,
44
+ });
45
+ }
46
+
47
+ return;
48
+ }
49
+
50
+ if (!declare)
51
+ test(`${name}: report: is function`, (t) => {
52
+ t.equal(typeof report, 'function', `should export 'report' function`);
53
+ t.end();
54
+ }, options);
55
+
56
+ test(`${name}: plugins should be of type: replace, template, traverse or find`, (t) => {
57
+ const result = isCorrectPlugin({
58
+ find,
59
+ fix,
60
+
61
+ traverse,
62
+
63
+ include,
64
+ exclude,
65
+
66
+ filter,
67
+ match,
68
+ replace,
69
+
70
+ declare,
71
+ });
72
+
73
+ t.ok(result, `should export 'replace', 'find', 'traverse', 'include', 'exclude', or 'declare' function`);
74
+ t.end();
75
+ }, options);
76
+ };
@@ -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,13 +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;
23
+ const {keys} = Object;
24
24
 
25
25
  global.__putout_test_fs = {
26
26
  readFileSync,
@@ -529,67 +529,3 @@ function parseOptions(plugin) {
529
529
 
530
530
  return plugin;
531
531
  }
532
-
533
- function preTest(test, plugin) {
534
- const [name, {
535
- report,
536
- find,
537
- traverse,
538
- include,
539
- exclude,
540
- fix,
541
- rules,
542
- replace,
543
- filter,
544
- match,
545
- declare,
546
- }] = entries(plugin).pop();
547
-
548
- const options = {
549
- checkDuplicates: false,
550
- };
551
-
552
- if (rules) {
553
- test(`${name}: rules is an object`, (t) => {
554
- t.equal(typeof rules, 'object', 'should export "rules" object');
555
- t.end();
556
- }, options);
557
-
558
- const entries = Object.entries(rules);
559
-
560
- for (const [entryName, plugin] of entries) {
561
- preTest(test, {
562
- [`${name}/${entryName}`]: plugin,
563
- });
564
- }
565
-
566
- return;
567
- }
568
-
569
- if (!declare)
570
- test(`${name}: report: is function`, (t) => {
571
- t.equal(typeof report, 'function', 'should export "report" function');
572
- t.end();
573
- }, options);
574
-
575
- test(`${name}: plugins should be of type: replace, template, traverse or find`, (t) => {
576
- const result = isCorrectPlugin({
577
- find,
578
- fix,
579
-
580
- traverse,
581
-
582
- include,
583
- exclude,
584
-
585
- filter,
586
- match,
587
- replace,
588
-
589
- declare,
590
- });
591
-
592
- t.ok(result, 'should export "replace", "find", "traverse", "include", "exclude", or "declare" function');
593
- t.end();
594
- }, options);
595
- }
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.3.0",
3
+ "version": "7.5.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 ",
@@ -65,7 +65,7 @@
65
65
  "c8": "^8.0.0",
66
66
  "eslint": "^8.0.1",
67
67
  "eslint-plugin-n": "^16.0.0",
68
- "eslint-plugin-putout": "^20.0.0",
68
+ "eslint-plugin-putout": "^21.0.0",
69
69
  "lerna": "^6.0.1",
70
70
  "madrun": "^9.0.0",
71
71
  "mock-require": "^3.0.3",