@w-lfpup/jackrabbit 0.2.0 → 0.3.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.
Files changed (96) hide show
  1. package/.github/workflows/browsers.json +45 -0
  2. package/.github/workflows/browsers.macos.json +51 -0
  3. package/.github/workflows/browsers.windows.json +19 -0
  4. package/.github/workflows/tests.yml +24 -0
  5. package/README.md +41 -1
  6. package/browser/dist/logger.js +43 -0
  7. package/browser/dist/mod.js +26 -0
  8. package/browser/dist/queue.js +27 -0
  9. package/browser/dist/runner.js +20 -0
  10. package/{cli → browser}/package.json +1 -1
  11. package/browser/src/logger.ts +57 -0
  12. package/browser/src/mod.ts +30 -0
  13. package/browser/src/runner.ts +22 -0
  14. package/browser/tsconfig.json +11 -0
  15. package/browser/tsconfig.tsbuildinfo +1 -0
  16. package/browsers.json +38 -0
  17. package/core/dist/jackrabbit_types.d.ts +61 -27
  18. package/core/dist/mod.d.ts +2 -2
  19. package/core/dist/mod.js +1 -1
  20. package/core/dist/run_steps.d.ts +2 -2
  21. package/core/dist/run_steps.js +83 -67
  22. package/core/src/jackrabbit_types.ts +72 -28
  23. package/core/src/mod.ts +2 -8
  24. package/core/src/run_steps.ts +111 -80
  25. package/examples/hello_world/goodbye_world.ts +1 -1
  26. package/examples/hello_world/hello_world.ts +1 -1
  27. package/nodejs/dist/logger.js +161 -0
  28. package/nodejs/dist/mod.js +31 -0
  29. package/nodejs/dist/results.js +139 -0
  30. package/nodejs/dist/results_str.js +147 -0
  31. package/nodejs/dist/runner.js +17 -0
  32. package/nodejs/src/logger.ts +193 -0
  33. package/nodejs/src/mod.ts +37 -0
  34. package/nodejs/src/results_str.ts +234 -0
  35. package/{nodejs_cli → nodejs}/tsconfig.json +2 -1
  36. package/nodejs/tsconfig.tsbuildinfo +1 -0
  37. package/package.json +6 -4
  38. package/tests/dist/mod.d.ts +14 -3
  39. package/tests/dist/mod.js +33 -13
  40. package/tests/dist/test_error.test.d.ts +9 -0
  41. package/tests/dist/test_error.test.js +27 -0
  42. package/tests/dist/test_errors.test.d.ts +9 -0
  43. package/tests/dist/test_errors.test.js +27 -0
  44. package/tests/dist/test_logger.d.ts +3 -2
  45. package/tests/dist/test_logger.js +5 -1
  46. package/tests/src/mod.ts +31 -15
  47. package/tests/src/test_error.test.ts +32 -0
  48. package/tests/src/test_logger.ts +6 -1
  49. package/tests/tsconfig.tsbuildinfo +1 -1
  50. package/tsconfig.json +1 -1
  51. package/webdriver/dist/config.js +57 -0
  52. package/webdriver/dist/eventbus.js +18 -0
  53. package/webdriver/dist/listeners.js +21 -0
  54. package/webdriver/dist/logger.js +203 -0
  55. package/webdriver/dist/mod.js +36 -0
  56. package/webdriver/dist/results_str.js +167 -0
  57. package/webdriver/dist/routes.js +172 -0
  58. package/webdriver/dist/routes2.js +163 -0
  59. package/webdriver/dist/test_hangar.js +20 -0
  60. package/webdriver/dist/webdriver.js +273 -0
  61. package/webdriver/package.json +8 -0
  62. package/webdriver/src/config.ts +89 -0
  63. package/webdriver/src/eventbus.ts +104 -0
  64. package/webdriver/src/logger.ts +247 -0
  65. package/webdriver/src/mod.ts +43 -0
  66. package/webdriver/src/results.ts +56 -0
  67. package/webdriver/src/results_str.ts +222 -0
  68. package/webdriver/src/routes.ts +211 -0
  69. package/webdriver/src/test_hangar.ts +25 -0
  70. package/webdriver/src/webdriver.ts +372 -0
  71. package/{cli → webdriver}/tsconfig.json +1 -0
  72. package/webdriver/tsconfig.tsbuildinfo +1 -0
  73. package/cli/dist/cli.d.ts +0 -3
  74. package/cli/dist/cli.js +0 -8
  75. package/cli/dist/cli_types.d.ts +0 -7
  76. package/cli/dist/config.d.ts +0 -5
  77. package/cli/dist/config.js +0 -6
  78. package/cli/dist/importer.d.ts +0 -7
  79. package/cli/dist/importer.js +0 -16
  80. package/cli/dist/logger.d.ts +0 -7
  81. package/cli/dist/logger.js +0 -88
  82. package/cli/dist/mod.d.ts +0 -6
  83. package/cli/dist/mod.js +0 -4
  84. package/cli/src/cli.ts +0 -17
  85. package/cli/src/cli_types.ts +0 -9
  86. package/cli/src/config.ts +0 -9
  87. package/cli/src/importer.ts +0 -25
  88. package/cli/src/logger.ts +0 -126
  89. package/cli/src/mod.ts +0 -7
  90. package/cli/tsconfig.tsbuildinfo +0 -1
  91. package/nodejs_cli/dist/mod.d.ts +0 -2
  92. package/nodejs_cli/dist/mod.js +0 -20
  93. package/nodejs_cli/src/mod.ts +0 -25
  94. package/nodejs_cli/tsconfig.tsbuildinfo +0 -1
  95. /package/{nodejs_cli → nodejs}/package.json +0 -0
  96. /package/{cli/dist/cli_types.js → webdriver/dist/results.js} +0 -0
@@ -1,95 +1,111 @@
1
1
  const TIMEOUT_INTERVAL_MS = 10000;
2
- function sleep(time) {
2
+ export function sleep(time) {
3
3
  return new Promise((resolve) => {
4
4
  setTimeout(() => {
5
5
  resolve();
6
6
  }, time);
7
7
  });
8
8
  }
9
- async function createTimeout(timeoutMs = TIMEOUT_INTERVAL_MS) {
9
+ async function failAfterTimeout(timeoutMs) {
10
10
  await sleep(timeoutMs);
11
11
  return `timed out at ${performance.now()} after ${timeoutMs} ms.`;
12
12
  }
13
- async function execTest(testModules, logger, moduleId, testId) {
14
- if (logger.cancelled)
15
- return;
16
- logger.log(testModules, {
13
+ async function execTest(params) {
14
+ const { logger, options, jrTest, test_id, collection_id, module_id } = params;
15
+ const test_name = jrTest.name ?? test_id.toString();
16
+ logger.log({
17
+ collection_id,
18
+ module_id,
19
+ test_id,
20
+ test_name,
17
21
  type: "start_test",
18
- moduleId,
19
- testId,
20
- });
21
- const { tests, options } = testModules[moduleId];
22
- const testFunc = tests[testId];
23
- const startTime = performance.now();
24
- const assertions = await Promise.race([
25
- createTimeout(options.timeoutMs),
26
- testFunc(),
27
- ]);
28
- if (logger.cancelled)
29
- return;
30
- const endTime = performance.now();
31
- logger.log(testModules, {
32
- type: "end_test",
33
- assertions,
34
- endTime,
35
- moduleId,
36
- startTime,
37
- testId,
38
22
  });
23
+ let start_time = performance.now();
24
+ let assertions;
25
+ try {
26
+ assertions = await Promise.race([
27
+ failAfterTimeout(options?.timeoutMs ?? TIMEOUT_INTERVAL_MS),
28
+ jrTest(),
29
+ ]);
30
+ let end_time = performance.now();
31
+ logger.log({
32
+ assertions,
33
+ collection_id,
34
+ start_time,
35
+ end_time,
36
+ module_id,
37
+ test_id,
38
+ type: "end_test",
39
+ });
40
+ }
41
+ catch (e) {
42
+ return logger.log({
43
+ collection_id,
44
+ error: e?.toString() ?? "wild test error",
45
+ module_id,
46
+ test_id,
47
+ type: "test_error",
48
+ });
49
+ }
39
50
  }
40
- async function execCollection(testModules, logger, moduleId) {
41
- if (logger.cancelled)
42
- return;
43
- const { tests } = testModules[moduleId];
51
+ async function execCollection(logger, testModule, collection_id, module_id) {
52
+ const { tests, options } = testModule;
44
53
  const wrappedTests = [];
45
- for (let [testID] of tests.entries()) {
46
- wrappedTests.push(execTest(testModules, logger, moduleId, testID));
54
+ for (let [test_id, jrTest] of tests.entries()) {
55
+ wrappedTests.push(function () {
56
+ return execTest({
57
+ logger,
58
+ options,
59
+ jrTest,
60
+ collection_id,
61
+ module_id,
62
+ test_id,
63
+ });
64
+ });
47
65
  }
48
- if (logger.cancelled)
49
- return;
50
66
  await Promise.all(wrappedTests);
51
67
  }
52
- async function execCollectionOrdered(testModules, logger, moduleId) {
53
- const { tests } = testModules[moduleId];
54
- for (let [testID] of tests.entries()) {
55
- if (logger.cancelled)
56
- return;
57
- await execTest(testModules, logger, moduleId, testID);
68
+ async function execCollectionOrdered(logger, testModule, collection_id, module_id) {
69
+ const { tests, options } = testModule;
70
+ for (let [test_id, jrTest] of tests.entries()) {
71
+ await execTest({
72
+ logger,
73
+ options,
74
+ jrTest,
75
+ collection_id,
76
+ module_id,
77
+ test_id,
78
+ });
58
79
  }
59
80
  }
60
- export async function startRun(logger, testModules) {
61
- logger.log(testModules, {
62
- type: "start_run",
63
- time: performance.now(),
81
+ export async function runCollection(logger, testModules, collection_id, collection_url) {
82
+ logger.log({
83
+ collection_id,
84
+ collection_url,
85
+ expected_module_count: testModules.length,
86
+ type: "start_collection",
64
87
  });
65
- for (let [moduleId, testModule] of testModules.entries()) {
66
- if (logger.cancelled)
67
- return;
68
- logger.log(testModules, {
88
+ for (let [module_id, testModule] of testModules.entries()) {
89
+ const { options } = testModule;
90
+ const module_name = options?.title ?? module_id.toString();
91
+ logger.log({
69
92
  type: "start_module",
70
- moduleId,
93
+ module_id,
94
+ module_name,
95
+ collection_id,
96
+ expected_test_count: testModule.tests.length,
71
97
  });
72
- const { options } = testModule;
73
98
  options?.runAsynchronously
74
- ? await execCollection(testModules, logger, moduleId)
75
- : await execCollectionOrdered(testModules, logger, moduleId);
76
- if (logger.cancelled)
77
- return;
78
- logger.log(testModules, {
99
+ ? await execCollection(logger, testModule, collection_id, module_id)
100
+ : await execCollectionOrdered(logger, testModule, collection_id, module_id);
101
+ logger.log({
79
102
  type: "end_module",
80
- moduleId,
103
+ collection_id,
104
+ module_id,
81
105
  });
82
106
  }
83
- logger.log(testModules, {
84
- type: "end_run",
85
- time: performance.now(),
86
- });
87
- }
88
- export function cancelRun(logger, testModules) {
89
- if (logger.cancelled)
90
- return;
91
- logger.log(testModules, {
92
- type: "cancel_run",
93
- time: performance.now(),
107
+ logger.log({
108
+ type: "end_collection",
109
+ collection_id,
94
110
  });
95
111
  }
@@ -2,74 +2,118 @@ interface Stringable {
2
2
  toString: Object["toString"];
3
3
  }
4
4
 
5
- export type Assertions = Stringable | Stringable[] | undefined;
5
+ export type Assertions = Stringable | Stringable[] | undefined | null;
6
6
 
7
7
  type SyncTest = () => Assertions;
8
8
  type AsyncTest = () => Promise<Assertions>;
9
9
  export type Test = SyncTest | AsyncTest;
10
10
 
11
- export interface Options {
11
+ export interface TestOptions {
12
12
  runAsynchronously?: boolean;
13
13
  timeoutMs?: number;
14
14
  title?: string;
15
15
  }
16
16
 
17
17
  export interface TestModule {
18
+ options?: TestOptions;
18
19
  tests: Test[];
19
- options: Options;
20
20
  }
21
21
 
22
- interface StartRun {
23
- type: "start_run";
22
+ export interface StartRun {
23
+ expected_collection_count: number;
24
24
  time: number;
25
+ type: "start_run";
25
26
  }
26
27
 
27
- interface EndRun {
28
- type: "end_run";
28
+ export interface EndRun {
29
29
  time: number;
30
+ type: "end_run";
30
31
  }
31
32
 
32
- interface CancelRun {
33
- type: "cancel_run";
34
- time: number;
33
+ export interface RunError {
34
+ error: string;
35
+ type: "run_error";
36
+ }
37
+
38
+ export interface StartTestCollection {
39
+ collection_id: number;
40
+ collection_url: string;
41
+ expected_module_count: number;
42
+ type: "start_collection";
43
+ }
44
+
45
+ export interface EndTestCollection {
46
+ collection_id: number;
47
+ type: "end_collection";
35
48
  }
36
49
 
37
- interface StartModule {
50
+ export interface TestCollectionError {
51
+ collection_id: number;
52
+ error: string;
53
+ type: "collection_error";
54
+ }
55
+
56
+ export interface StartModule {
57
+ collection_id: number;
58
+ expected_test_count: number;
59
+ module_id: number;
60
+ module_name: string;
38
61
  type: "start_module";
39
- moduleId: number;
40
62
  }
41
63
 
42
- interface EndModule {
64
+ export interface EndModule {
65
+ collection_id: number;
66
+ module_id: number;
43
67
  type: "end_module";
44
- moduleId: number;
45
68
  }
46
69
 
47
- interface StartTest {
70
+ export interface ModuleError {
71
+ collection_id: number;
72
+ error: string;
73
+ module_id: number;
74
+ type: "module_error";
75
+ }
76
+
77
+ export interface StartTest {
78
+ collection_id: number;
79
+ module_id: number;
80
+ test_id: number;
81
+ test_name: string;
48
82
  type: "start_test";
49
- testId: number;
50
- moduleId: number;
51
83
  }
52
84
 
53
- interface EndTest {
54
- type: "end_test";
55
- testId: number;
56
- moduleId: number;
57
- startTime: number;
58
- endTime: number;
85
+ export interface EndTest {
59
86
  assertions: Assertions;
87
+ collection_id: number;
88
+ module_id: number;
89
+ test_id: number;
90
+ start_time: number;
91
+ end_time: number;
92
+ type: "end_test";
93
+ }
94
+
95
+ export interface TestError {
96
+ collection_id: number;
97
+ error: string;
98
+ module_id: number;
99
+ test_id: number;
100
+ type: "test_error";
60
101
  }
61
102
 
62
103
  export type LoggerAction =
63
104
  | StartRun
64
105
  | EndRun
65
- | CancelRun
106
+ | RunError
107
+ | StartTestCollection
108
+ | EndTestCollection
109
+ | TestCollectionError
66
110
  | StartModule
111
+ | ModuleError
67
112
  | EndModule
68
113
  | StartTest
69
- | EndTest;
114
+ | EndTest
115
+ | TestError;
70
116
 
71
117
  export interface LoggerInterface {
72
- readonly failed: boolean;
73
- readonly cancelled: boolean;
74
- log(testModules: TestModule[], action: LoggerAction): void;
118
+ log(action: LoggerAction): void;
75
119
  }
package/core/src/mod.ts CHANGED
@@ -1,9 +1,3 @@
1
- export type {
2
- LoggerAction,
3
- LoggerInterface,
4
- Test,
5
- Options,
6
- TestModule,
7
- } from "./jackrabbit_types.ts";
1
+ export type * from "./jackrabbit_types.ts";
8
2
 
9
- export { startRun, cancelRun } from "./run_steps.js";
3
+ export { runCollection, sleep } from "./run_steps.js";
@@ -2,11 +2,22 @@ import type {
2
2
  Assertions,
3
3
  LoggerInterface,
4
4
  TestModule,
5
+ Test,
6
+ TestOptions,
5
7
  } from "./jackrabbit_types.ts";
6
8
 
9
+ interface ExecTestParams {
10
+ logger: LoggerInterface;
11
+ options: TestOptions | undefined;
12
+ jrTest: Test;
13
+ collection_id: number;
14
+ module_id: number;
15
+ test_id: number;
16
+ }
17
+
7
18
  const TIMEOUT_INTERVAL_MS = 10000;
8
19
 
9
- function sleep(time: number): Promise<void> {
20
+ export function sleep(time: number): Promise<void> {
10
21
  return new Promise((resolve) => {
11
22
  setTimeout(() => {
12
23
  resolve();
@@ -14,125 +25,145 @@ function sleep(time: number): Promise<void> {
14
25
  });
15
26
  }
16
27
 
17
- async function createTimeout(
18
- timeoutMs: number = TIMEOUT_INTERVAL_MS,
19
- ): Promise<Assertions> {
28
+ async function failAfterTimeout(timeoutMs: number): Promise<Assertions> {
20
29
  await sleep(timeoutMs);
21
30
 
22
31
  return `timed out at ${performance.now()} after ${timeoutMs} ms.`;
23
32
  }
24
33
 
25
- async function execTest(
26
- testModules: TestModule[],
27
- logger: LoggerInterface,
28
- moduleId: number,
29
- testId: number,
30
- ) {
31
- if (logger.cancelled) return;
34
+ async function execTest(params: ExecTestParams) {
35
+ const { logger, options, jrTest, test_id, collection_id, module_id } = params;
36
+
37
+ const test_name = jrTest.name ?? test_id.toString();
32
38
 
33
- logger.log(testModules, {
39
+ logger.log({
40
+ collection_id,
41
+ module_id,
42
+ test_id,
43
+ test_name,
34
44
  type: "start_test",
35
- moduleId,
36
- testId,
37
45
  });
38
46
 
39
- const { tests, options } = testModules[moduleId];
40
-
41
- const testFunc = tests[testId];
42
- const startTime = performance.now();
43
- const assertions = await Promise.race([
44
- createTimeout(options.timeoutMs),
45
- testFunc(),
46
- ]);
47
-
48
- if (logger.cancelled) return;
49
-
50
- const endTime = performance.now();
51
-
52
- logger.log(testModules, {
53
- type: "end_test",
54
- assertions,
55
- endTime,
56
- moduleId,
57
- startTime,
58
- testId,
59
- });
47
+ let start_time = performance.now();
48
+
49
+ let assertions: Assertions;
50
+ try {
51
+ assertions = await Promise.race([
52
+ failAfterTimeout(options?.timeoutMs ?? TIMEOUT_INTERVAL_MS),
53
+ jrTest(),
54
+ ]);
55
+
56
+ let end_time = performance.now();
57
+
58
+ logger.log({
59
+ assertions,
60
+ collection_id,
61
+ start_time,
62
+ end_time,
63
+ module_id,
64
+ test_id,
65
+ type: "end_test",
66
+ });
67
+ } catch (e: unknown) {
68
+ return logger.log({
69
+ collection_id,
70
+ error: e?.toString() ?? "wild test error",
71
+ module_id,
72
+ test_id,
73
+ type: "test_error",
74
+ });
75
+ }
60
76
  }
61
77
 
62
78
  async function execCollection(
63
- testModules: TestModule[],
64
79
  logger: LoggerInterface,
65
- moduleId: number,
80
+ testModule: TestModule,
81
+ collection_id: number,
82
+ module_id: number,
66
83
  ) {
67
- if (logger.cancelled) return;
68
-
69
- const { tests } = testModules[moduleId];
84
+ const { tests, options } = testModule;
70
85
 
71
86
  const wrappedTests = [];
72
- for (let [testID] of tests.entries()) {
73
- wrappedTests.push(execTest(testModules, logger, moduleId, testID));
87
+ for (let [test_id, jrTest] of tests.entries()) {
88
+ wrappedTests.push(function () {
89
+ return execTest({
90
+ logger,
91
+ options,
92
+ jrTest,
93
+ collection_id,
94
+ module_id,
95
+ test_id,
96
+ });
97
+ });
74
98
  }
75
99
 
76
- if (logger.cancelled) return;
77
-
78
100
  await Promise.all(wrappedTests);
79
101
  }
80
102
 
81
103
  async function execCollectionOrdered(
82
- testModules: TestModule[],
83
104
  logger: LoggerInterface,
84
- moduleId: number,
105
+ testModule: TestModule,
106
+ collection_id: number,
107
+ module_id: number,
85
108
  ) {
86
- const { tests } = testModules[moduleId];
87
-
88
- for (let [testID] of tests.entries()) {
89
- if (logger.cancelled) return;
90
-
91
- await execTest(testModules, logger, moduleId, testID);
109
+ const { tests, options } = testModule;
110
+
111
+ for (let [test_id, jrTest] of tests.entries()) {
112
+ await execTest({
113
+ logger,
114
+ options,
115
+ jrTest,
116
+ collection_id,
117
+ module_id,
118
+ test_id,
119
+ });
92
120
  }
93
121
  }
94
122
 
95
- export async function startRun(
123
+ export async function runCollection(
96
124
  logger: LoggerInterface,
97
125
  testModules: TestModule[],
126
+ collection_id: number,
127
+ collection_url: string,
98
128
  ) {
99
- logger.log(testModules, {
100
- type: "start_run",
101
- time: performance.now(),
129
+ logger.log({
130
+ collection_id,
131
+ collection_url,
132
+ expected_module_count: testModules.length,
133
+ type: "start_collection",
102
134
  });
103
135
 
104
- for (let [moduleId, testModule] of testModules.entries()) {
105
- if (logger.cancelled) return;
136
+ for (let [module_id, testModule] of testModules.entries()) {
137
+ const { options } = testModule;
138
+
139
+ const module_name = options?.title ?? module_id.toString();
106
140
 
107
- logger.log(testModules, {
141
+ logger.log({
108
142
  type: "start_module",
109
- moduleId,
143
+ module_id,
144
+ module_name,
145
+ collection_id,
146
+ expected_test_count: testModule.tests.length,
110
147
  });
111
148
 
112
- const { options } = testModule;
113
149
  options?.runAsynchronously
114
- ? await execCollection(testModules, logger, moduleId)
115
- : await execCollectionOrdered(testModules, logger, moduleId);
116
-
117
- if (logger.cancelled) return;
118
-
119
- logger.log(testModules, {
150
+ ? await execCollection(logger, testModule, collection_id, module_id)
151
+ : await execCollectionOrdered(
152
+ logger,
153
+ testModule,
154
+ collection_id,
155
+ module_id,
156
+ );
157
+
158
+ logger.log({
120
159
  type: "end_module",
121
- moduleId,
160
+ collection_id,
161
+ module_id,
122
162
  });
123
163
  }
124
164
 
125
- logger.log(testModules, {
126
- type: "end_run",
127
- time: performance.now(),
128
- });
129
- }
130
-
131
- export function cancelRun(logger: LoggerInterface, testModules: TestModule[]) {
132
- if (logger.cancelled) return;
133
-
134
- logger.log(testModules, {
135
- type: "cancel_run",
136
- time: performance.now(),
165
+ logger.log({
166
+ type: "end_collection",
167
+ collection_id,
137
168
  });
138
169
  }
@@ -2,7 +2,7 @@ async function test_that_passes() {
2
2
  return [];
3
3
  }
4
4
 
5
- async function test_that_fails() {
5
+ function test_that_fails() {
6
6
  return ["this test will fail"];
7
7
  }
8
8
 
@@ -2,7 +2,7 @@ function test_will_pass() {
2
2
  return;
3
3
  }
4
4
 
5
- function test_will_fail() {
5
+ async function test_will_fail() {
6
6
  return "this test will fail";
7
7
  }
8
8