@j-o-r/sh 1.1.28 → 1.1.29
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 +119 -154
- package/TODO.md +18 -0
- package/lib/AsyncTracker.js +126 -107
- package/lib/SH.js +158 -154
- package/lib/SHDispatch.js +105 -91
- package/lib/SHExecute.js +83 -41
- package/lib/Test.js +153 -123
- package/package.json +1 -1
- package/types/AsyncTracker.d.ts +65 -31
- package/types/SH.d.ts +157 -164
- package/types/SHDispatch.d.ts +55 -78
- package/types/SHExecute.d.ts +44 -23
- package/types/Test.d.ts +66 -30
package/types/Test.d.ts
CHANGED
|
@@ -1,68 +1,104 @@
|
|
|
1
1
|
export default Test;
|
|
2
|
-
export type AsyncFunction = (
|
|
3
|
-
export type
|
|
2
|
+
export type AsyncFunction = () => Promise<any>;
|
|
3
|
+
export type TestDefinition = {
|
|
4
|
+
/**
|
|
5
|
+
* - Test name/description.
|
|
6
|
+
*/
|
|
4
7
|
description: string;
|
|
5
8
|
/**
|
|
6
|
-
* -
|
|
9
|
+
* - Sync/async test function.
|
|
7
10
|
*/
|
|
8
11
|
callback: Function | AsyncFunction;
|
|
9
12
|
};
|
|
10
|
-
export type
|
|
13
|
+
export type TestReport = {
|
|
14
|
+
/**
|
|
15
|
+
* - Test description.
|
|
16
|
+
*/
|
|
11
17
|
description: string;
|
|
12
18
|
/**
|
|
13
|
-
* -
|
|
19
|
+
* - Execution duration (ms).
|
|
14
20
|
*/
|
|
15
21
|
duration: number;
|
|
16
22
|
/**
|
|
17
|
-
* -
|
|
23
|
+
* - Whether the test ran.
|
|
18
24
|
*/
|
|
19
25
|
executed: boolean;
|
|
20
26
|
};
|
|
21
|
-
export type
|
|
27
|
+
export type TestReportSummary = {
|
|
28
|
+
/**
|
|
29
|
+
* - Total tests defined.
|
|
30
|
+
*/
|
|
22
31
|
tests: number;
|
|
23
32
|
/**
|
|
24
|
-
* -
|
|
33
|
+
* - Total execution time (ms).
|
|
25
34
|
*/
|
|
26
35
|
duration: number;
|
|
27
36
|
/**
|
|
28
|
-
* -
|
|
37
|
+
* - Number of failures.
|
|
29
38
|
*/
|
|
30
39
|
errors: number;
|
|
31
40
|
/**
|
|
32
|
-
* -
|
|
41
|
+
* - Number of tests run.
|
|
33
42
|
*/
|
|
34
43
|
executed: number;
|
|
35
44
|
};
|
|
36
45
|
declare class Test {
|
|
37
46
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
* Creates a test runner instance.
|
|
48
|
+
*
|
|
49
|
+
* Tracks tests, errors, unresolved promises via {@link AsyncTracker}.
|
|
50
|
+
* Supports sync/async callbacks; detects global errors.
|
|
51
|
+
*
|
|
52
|
+
* @param {boolean} [quiet=false] - Suppress console reports.
|
|
53
|
+
* @example
|
|
54
|
+
* const t = new Test();
|
|
55
|
+
* t.add('basic', () => { throw new Error('fail'); });
|
|
56
|
+
* const report = await t.run();
|
|
57
|
+
*/
|
|
40
58
|
constructor(quiet?: boolean);
|
|
41
59
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
60
|
+
* Sets timeout for settling async in sync tests (hack for late errors).
|
|
61
|
+
*
|
|
62
|
+
* @param {number} timeout - Timeout (ms); default 50.
|
|
63
|
+
* @example
|
|
64
|
+
* t.syncTimeout(100);
|
|
65
|
+
*/
|
|
47
66
|
syncTimeout(timeout: number): void;
|
|
48
67
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
68
|
+
* Adds a test case.
|
|
69
|
+
*
|
|
70
|
+
* @param {string} description - Test name.
|
|
71
|
+
* @param {Function | AsyncFunction} callback - Test function.
|
|
72
|
+
* @returns {Test} Self for chaining.
|
|
73
|
+
* @throws {Error} Invalid description (non-string) or callback (not function).
|
|
74
|
+
* @example
|
|
75
|
+
* t.add('check 1+1', () => expect(1+1).toBe(2));
|
|
76
|
+
*/
|
|
55
77
|
add(description: string, callback: Function | AsyncFunction): Test;
|
|
56
78
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
79
|
+
* Runs tests (all or selected); returns summary.
|
|
80
|
+
*
|
|
81
|
+
* Prints progress/errors; checks unresolved promises post-run.
|
|
82
|
+
*
|
|
83
|
+
* @param {number[]} [execute] - Indices of tests to run (default: all).
|
|
84
|
+
* @returns {Promise<TestReportSummary>} Summary stats.
|
|
85
|
+
* @example
|
|
86
|
+
* await t.run([0, 2]); // Run tests 0 and 2
|
|
87
|
+
*/
|
|
88
|
+
run(execute?: number[]): Promise<TestReportSummary>;
|
|
89
|
+
/**
|
|
90
|
+
* Prints unresolved promises report (if any).
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* t.unresolved();
|
|
94
|
+
*/
|
|
62
95
|
unresolved(): void;
|
|
63
96
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
97
|
+
* Resets all tests, reports, errors, tracker.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* t.reset();
|
|
101
|
+
*/
|
|
66
102
|
reset(): void;
|
|
67
103
|
#private;
|
|
68
104
|
}
|