@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/types/Test.d.ts CHANGED
@@ -1,68 +1,104 @@
1
1
  export default Test;
2
- export type AsyncFunction = (() => Promise<any>);
3
- export type testDefinition = {
2
+ export type AsyncFunction = () => Promise<any>;
3
+ export type TestDefinition = {
4
+ /**
5
+ * - Test name/description.
6
+ */
4
7
  description: string;
5
8
  /**
6
- * - syc/ async function
9
+ * - Sync/async test function.
7
10
  */
8
11
  callback: Function | AsyncFunction;
9
12
  };
10
- export type testReport = {
13
+ export type TestReport = {
14
+ /**
15
+ * - Test description.
16
+ */
11
17
  description: string;
12
18
  /**
13
- * - start time in MS
19
+ * - Execution duration (ms).
14
20
  */
15
21
  duration: number;
16
22
  /**
17
- * - Has it been called?
23
+ * - Whether the test ran.
18
24
  */
19
25
  executed: boolean;
20
26
  };
21
- export type Report = {
27
+ export type TestReportSummary = {
28
+ /**
29
+ * - Total tests defined.
30
+ */
22
31
  tests: number;
23
32
  /**
24
- * - start time in MS
33
+ * - Total execution time (ms).
25
34
  */
26
35
  duration: number;
27
36
  /**
28
- * - number of errors
37
+ * - Number of failures.
29
38
  */
30
39
  errors: number;
31
40
  /**
32
- * - number of tests executed
41
+ * - Number of tests run.
33
42
  */
34
43
  executed: number;
35
44
  };
36
45
  declare class Test {
37
46
  /**
38
- * @param {boolean} [quiet] - does not output a report when true, default `false`
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
- * Set the timeout when a synced function is called.
43
- * This settles async code used in a sync function
44
- * and give some time to catch errors (#HACK)
45
- * @param {number} timeout - in MS, default 50
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
- * @param {string} description
51
- * @param {Function|AsyncFunction} callback - sync / async function
52
- * @throws Error when conditions are not met
53
- * @returns {Test}
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
- * Execute tests
58
- * @param {number[]} [execute] - limit the execution tests
59
- * @returns {Promise<Report>}
60
- */
61
- run(execute?: number[]): Promise<Report>;
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
- * Empty tests
65
- */
97
+ * Resets all tests, reports, errors, tracker.
98
+ *
99
+ * @example
100
+ * t.reset();
101
+ */
66
102
  reset(): void;
67
103
  #private;
68
104
  }