@putout/test 8.2.1 → 8.4.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/lib/create-error.js +29 -0
- package/lib/test.js +34 -2
- package/package.json +6 -4
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {codeframe} = require('putout');
|
|
4
|
+
const {stringify} = JSON;
|
|
5
|
+
const {entries} = Object;
|
|
6
|
+
|
|
7
|
+
module.exports.createError = (help, source, values) => {
|
|
8
|
+
const argsBoxStart = '\n ╔══\n';
|
|
9
|
+
const argsBoxLine = ' ║';
|
|
10
|
+
const argsBoxEnd = '\n ╚══\n';
|
|
11
|
+
|
|
12
|
+
const args = [];
|
|
13
|
+
|
|
14
|
+
for (const [name, value] of entries(values)) {
|
|
15
|
+
args.push(`${argsBoxLine} ${name} = ${stringify(value) || typeof value}`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const error = Error(`${help}${argsBoxStart}${args.join('\n')}${argsBoxEnd}`);
|
|
19
|
+
|
|
20
|
+
error.loc = {
|
|
21
|
+
line: 1,
|
|
22
|
+
column: 1,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
throw Error('\n' + codeframe({
|
|
26
|
+
source,
|
|
27
|
+
error,
|
|
28
|
+
}));
|
|
29
|
+
};
|
package/lib/test.js
CHANGED
|
@@ -17,7 +17,9 @@ const putout = require('putout');
|
|
|
17
17
|
const currify = require('currify');
|
|
18
18
|
const {createProgress} = require('@putout/engine-runner/progress');
|
|
19
19
|
|
|
20
|
+
const {createError} = require('./create-error');
|
|
20
21
|
const {preTest} = require('./pre-test');
|
|
22
|
+
|
|
21
23
|
const {isArray} = Array;
|
|
22
24
|
const isString = (a) => typeof a === 'string';
|
|
23
25
|
const isObject = (a) => typeof a === 'object';
|
|
@@ -276,6 +278,8 @@ const toObject = (array) => {
|
|
|
276
278
|
};
|
|
277
279
|
|
|
278
280
|
const progress = (dir, options) => (t) => async (name, expected) => {
|
|
281
|
+
checkProgress(name, expected);
|
|
282
|
+
|
|
279
283
|
const full = join(dir, name);
|
|
280
284
|
const [input, isTS] = readFixture(full);
|
|
281
285
|
|
|
@@ -466,7 +470,9 @@ const noTransformCode = currify((options, t, input) => {
|
|
|
466
470
|
|
|
467
471
|
const getMessage = ({message}) => message;
|
|
468
472
|
|
|
469
|
-
const report =
|
|
473
|
+
const report = (dir, options) => (t) => (name, message) => {
|
|
474
|
+
checkReport(name, message);
|
|
475
|
+
|
|
470
476
|
const full = join(dir, name);
|
|
471
477
|
const [source, isTS] = readFixture(full);
|
|
472
478
|
|
|
@@ -474,7 +480,7 @@ const report = currify((dir, options, t, name, message) => {
|
|
|
474
480
|
isTS,
|
|
475
481
|
...options,
|
|
476
482
|
}, t, source, message);
|
|
477
|
-
}
|
|
483
|
+
};
|
|
478
484
|
|
|
479
485
|
const noReport = currify((dir, options, t, name) => {
|
|
480
486
|
const full = join(dir, name);
|
|
@@ -599,3 +605,29 @@ function parseOptions(plugin) {
|
|
|
599
605
|
|
|
600
606
|
return plugin;
|
|
601
607
|
}
|
|
608
|
+
|
|
609
|
+
function checkReport(name, message) {
|
|
610
|
+
if (!message) {
|
|
611
|
+
const help = `☝️ Looks like you forget to pass the 'message' for 'report()' operator`;
|
|
612
|
+
const source = `report(name: string, message: string): Operator`;
|
|
613
|
+
const values = {
|
|
614
|
+
name,
|
|
615
|
+
message,
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
throw Error(createError(help, source, values));
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function checkProgress(name, expected) {
|
|
623
|
+
if (!isString(name)) {
|
|
624
|
+
const message = `☝️ Looks like you forget to pass the 'name' of a fixture for 'progress()' operator.`;
|
|
625
|
+
const signature = 'await progress(name: string, expected: ExpectedProgress): Operator';
|
|
626
|
+
const values = {
|
|
627
|
+
name,
|
|
628
|
+
expected,
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
throw Error(message, signature, values);
|
|
632
|
+
}
|
|
633
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/test",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.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 ",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@putout/eslint": "^3.0.0",
|
|
45
45
|
"@putout/plugin-filesystem": "*",
|
|
46
46
|
"currify": "^4.0.0",
|
|
47
|
+
"montag": "^1.2.1",
|
|
47
48
|
"putout": "*",
|
|
48
49
|
"supertape": "^9.0.0",
|
|
49
50
|
"try-catch": "^3.0.0",
|
|
@@ -64,14 +65,15 @@
|
|
|
64
65
|
"@putout/plugin-remove-console": "*",
|
|
65
66
|
"@putout/plugin-remove-empty": "*",
|
|
66
67
|
"@putout/plugin-remove-unused-variables": "*",
|
|
67
|
-
"c8": "^
|
|
68
|
-
"eslint": "^
|
|
68
|
+
"c8": "^9.0.0",
|
|
69
|
+
"eslint": "^9.0.0-alpha.0",
|
|
69
70
|
"eslint-plugin-n": "^16.0.0",
|
|
70
71
|
"eslint-plugin-putout": "^22.0.0",
|
|
71
72
|
"lerna": "^6.0.1",
|
|
72
73
|
"madrun": "^10.0.0",
|
|
73
74
|
"mock-require": "^3.0.3",
|
|
74
|
-
"nodemon": "^3.0.1"
|
|
75
|
+
"nodemon": "^3.0.1",
|
|
76
|
+
"strip-ansi": "^7.1.0"
|
|
75
77
|
},
|
|
76
78
|
"license": "MIT",
|
|
77
79
|
"engines": {
|