@putout/test 15.6.1 → 15.8.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/fixture.js +12 -11
- package/lib/test.d.ts +94 -0
- package/package.json +4 -1
package/lib/fixture.js
CHANGED
|
@@ -11,6 +11,18 @@ const TS = {
|
|
|
11
11
|
|
|
12
12
|
export const readFixture = (name, extension, extensionFix = env.UPDATE_EXTENSION) => {
|
|
13
13
|
const {readFileSync} = globalThis.__putout_test_fs;
|
|
14
|
+
|
|
15
|
+
if (extension) {
|
|
16
|
+
const [e, data] = tryCatch(readFileSync, `${name}.${extension}`, 'utf8');
|
|
17
|
+
|
|
18
|
+
if (!e)
|
|
19
|
+
return [
|
|
20
|
+
data,
|
|
21
|
+
TS.DISABLED,
|
|
22
|
+
extensionFix || extension,
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
|
|
14
26
|
const [eTS, dataTS] = tryCatch(readFileSync, `${name}.ts`, 'utf8');
|
|
15
27
|
|
|
16
28
|
if (!eTS)
|
|
@@ -29,17 +41,6 @@ export const readFixture = (name, extension, extensionFix = env.UPDATE_EXTENSION
|
|
|
29
41
|
'js',
|
|
30
42
|
];
|
|
31
43
|
|
|
32
|
-
if (extension) {
|
|
33
|
-
const [e, data] = tryCatch(readFileSync, `${name}.${extension}`, 'utf8');
|
|
34
|
-
|
|
35
|
-
if (!e)
|
|
36
|
-
return [
|
|
37
|
-
data,
|
|
38
|
-
TS.DISABLED,
|
|
39
|
-
extensionFix || extension,
|
|
40
|
-
];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
44
|
throw eJS;
|
|
44
45
|
};
|
|
45
46
|
|
package/lib/test.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Test,
|
|
3
|
+
OperationResult,
|
|
4
|
+
OperatorFactory,
|
|
5
|
+
} from 'supertape';
|
|
6
|
+
|
|
7
|
+
type TestOptions = {
|
|
8
|
+
checkAssertionsCount?: boolean;
|
|
9
|
+
checkScopes?: boolean;
|
|
10
|
+
checkDuplicates?: boolean;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
};
|
|
13
|
+
type CustomOperator = Record<string, OperatorFactory>;
|
|
14
|
+
type OperatorsToMethods<T> = {
|
|
15
|
+
[K in keyof T]:
|
|
16
|
+
T[K] extends OperatorFactory
|
|
17
|
+
? ReturnType<T[K]>
|
|
18
|
+
: never;
|
|
19
|
+
};
|
|
20
|
+
type TestFunction<T extends Test = Test> = ((message: string, fn: (t: T) => void, options?: TestOptions) => void) & {
|
|
21
|
+
skip: TestFunction<T>;
|
|
22
|
+
only: TestFunction<T>;
|
|
23
|
+
extend<U extends CustomOperator = {}>(operators?: U): TestFunction<T & OperatorsToMethods<U>>;
|
|
24
|
+
};
|
|
25
|
+
type Formatter = (...args: unknown[]) => unknown;
|
|
26
|
+
type FormatterOptions = Record<string, unknown>;
|
|
27
|
+
type Addons = Record<string, unknown>;
|
|
28
|
+
type PluginOptions = Record<string, unknown>;
|
|
29
|
+
|
|
30
|
+
export type TransformOperator = (name: string, transformed?: string | Addons, addons?: Addons) => OperationResult;
|
|
31
|
+
|
|
32
|
+
export type NoTransformOperator = (name: string, addons?: Addons) => OperationResult;
|
|
33
|
+
|
|
34
|
+
export type TransformCodeOperator = (input: string, output: string, isTS?: boolean) => OperationResult;
|
|
35
|
+
|
|
36
|
+
export type NoTransformCodeOperator = (input: string) => OperationResult;
|
|
37
|
+
|
|
38
|
+
export type TransformWithOptionsOperator = (name: string, pluginOptions: PluginOptions) => OperationResult;
|
|
39
|
+
|
|
40
|
+
export type NoTransformWithOptionsOperator = (name: string, pluginOptions: PluginOptions) => OperationResult;
|
|
41
|
+
|
|
42
|
+
export type ReportOperator = (name: string, message: string | string[], plugins?: unknown) => OperationResult;
|
|
43
|
+
|
|
44
|
+
export type NoReportOperator = (name: string, addons?: unknown[]) => OperationResult;
|
|
45
|
+
|
|
46
|
+
export type NoReportAfterTransformOperator = (name: string, addons?: Addons) => OperationResult;
|
|
47
|
+
|
|
48
|
+
export type NoReportAfterTransformWithOptionsOperator = (name: string, pluginOptions: PluginOptions) => OperationResult;
|
|
49
|
+
|
|
50
|
+
export type ReportWithOptionsOperator = (name: string, message: string, pluginOptions: PluginOptions) => OperationResult;
|
|
51
|
+
|
|
52
|
+
export type NoReportWithOptionsOperator = (name: string, pluginOptions: PluginOptions) => OperationResult;
|
|
53
|
+
|
|
54
|
+
export type ReportCodeOperator = (source: string, message: string | string[], addons?: unknown) => OperationResult;
|
|
55
|
+
|
|
56
|
+
export type NoReportCodeOperator = (source: string) => OperationResult;
|
|
57
|
+
|
|
58
|
+
export type FormatOperator = (formatter: Formatter, name: string, formatterOptions?: FormatterOptions) => Promise<OperationResult>;
|
|
59
|
+
|
|
60
|
+
export type FormatManyOperator = (formatter: Formatter, names: string[], formatterOptions?: FormatterOptions) => Promise<OperationResult>;
|
|
61
|
+
|
|
62
|
+
export type NoFormatOperator = (formatter: Formatter, name: string, formatterOptions?: FormatterOptions) => Promise<OperationResult>;
|
|
63
|
+
|
|
64
|
+
export type ProgressOperator = (name: string, expected: unknown) => Promise<OperationResult>;
|
|
65
|
+
|
|
66
|
+
export type ProgressWithOptionsOperator = (name: string, pluginOptions: PluginOptions, expected: unknown) => Promise<OperationResult>;
|
|
67
|
+
|
|
68
|
+
export interface PutoutTest extends Test {
|
|
69
|
+
transform: TransformOperator;
|
|
70
|
+
noTransform: NoTransformOperator;
|
|
71
|
+
transformCode: TransformCodeOperator;
|
|
72
|
+
noTransformCode: NoTransformCodeOperator;
|
|
73
|
+
progress: ProgressOperator;
|
|
74
|
+
progressWithOptions: ProgressWithOptionsOperator;
|
|
75
|
+
transformWithOptions: TransformWithOptionsOperator;
|
|
76
|
+
noTransformWithOptions: NoTransformWithOptionsOperator;
|
|
77
|
+
report: ReportOperator;
|
|
78
|
+
noReport: NoReportOperator;
|
|
79
|
+
noReportAfterTransform: NoReportAfterTransformOperator;
|
|
80
|
+
noReportAfterTransformWithOptions: NoReportAfterTransformWithOptionsOperator;
|
|
81
|
+
reportWithOptions: ReportWithOptionsOperator;
|
|
82
|
+
noReportWithOptions: NoReportWithOptionsOperator;
|
|
83
|
+
reportCode: ReportCodeOperator;
|
|
84
|
+
noReportCode: NoReportCodeOperator;
|
|
85
|
+
format: FormatOperator;
|
|
86
|
+
formatMany: FormatManyOperator;
|
|
87
|
+
noFormat: NoFormatOperator;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type PutoutTestFunction = TestFunction<PutoutTest>;
|
|
91
|
+
|
|
92
|
+
export function createTest(url: string, options: unknown, maybeExtends?: Record<string, unknown>): PutoutTestFunction;
|
|
93
|
+
|
|
94
|
+
export default createTest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/test",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Test runner for 🐊Putout plugins ",
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
"url": "git+https://github.com/coderaiser/putout.git"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
+
"wisdom": "madrun wisdom",
|
|
26
27
|
"test": "madrun test",
|
|
28
|
+
"test:dts": "madrun test:dts",
|
|
27
29
|
"watch:test": "madrun watch:test",
|
|
28
30
|
"lint": "madrun lint",
|
|
29
31
|
"fresh:lint": "madrun fresh:lint",
|
|
@@ -68,6 +70,7 @@
|
|
|
68
70
|
"@putout/plugin-remove-console": "*",
|
|
69
71
|
"@putout/plugin-variables": "*",
|
|
70
72
|
"@putout/processor-wasm": "*",
|
|
73
|
+
"check-dts": "^1.0.0",
|
|
71
74
|
"eslint": "^10.0.0",
|
|
72
75
|
"eslint-plugin-putout": "^31.0.0",
|
|
73
76
|
"madrun": "^13.0.0",
|