@w-lfpup/jackrabbit 0.1.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 (98) 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 +42 -0
  5. package/README.md +151 -8
  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 +62 -28
  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 +73 -29
  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/{cli → nodejs}/tsconfig.json +2 -1
  36. package/nodejs/tsconfig.tsbuildinfo +1 -0
  37. package/package.json +9 -6
  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/{nodejs_cli → webdriver}/tsconfig.json +1 -0
  72. package/webdriver/tsconfig.tsbuildinfo +1 -0
  73. package/.github/workflows/build_and_test.yml +0 -18
  74. package/cli/dist/cli.d.ts +0 -3
  75. package/cli/dist/cli.js +0 -8
  76. package/cli/dist/cli_types.d.ts +0 -7
  77. package/cli/dist/config.d.ts +0 -5
  78. package/cli/dist/config.js +0 -27
  79. package/cli/dist/importer.d.ts +0 -7
  80. package/cli/dist/importer.js +0 -16
  81. package/cli/dist/logger.d.ts +0 -7
  82. package/cli/dist/logger.js +0 -88
  83. package/cli/dist/mod.d.ts +0 -6
  84. package/cli/dist/mod.js +0 -4
  85. package/cli/src/cli.ts +0 -17
  86. package/cli/src/cli_types.ts +0 -9
  87. package/cli/src/config.ts +0 -36
  88. package/cli/src/importer.ts +0 -25
  89. package/cli/src/logger.ts +0 -126
  90. package/cli/src/mod.ts +0 -7
  91. package/cli/tsconfig.tsbuildinfo +0 -1
  92. package/nodejs_cli/dist/mod.d.ts +0 -2
  93. package/nodejs_cli/dist/mod.js +0 -20
  94. package/nodejs_cli/src/mod.ts +0 -25
  95. package/nodejs_cli/tsconfig.tsbuildinfo +0 -1
  96. package/test_guide.md +0 -114
  97. /package/{nodejs_cli → nodejs}/package.json +0 -0
  98. /package/{cli/dist/cli_types.js → webdriver/dist/results.js} +0 -0
package/tests/dist/mod.js CHANGED
@@ -1,30 +1,50 @@
1
1
  import * as FailTests from "./test_fail.test.js";
2
2
  import * as PassTests from "./test_pass.test.js";
3
- import { startRun } from "../../core/dist/mod.js";
3
+ import * as ErrorTests from "./test_error.test.js";
4
+ import { runCollection } from "../../core/dist/mod.js";
4
5
  import { TestLogger } from "./test_logger.js";
5
- // Test pass and fail behavior
6
- const failTestModules = [FailTests];
7
- const passTestModules = [PassTests];
8
6
  // jackrabbit test run won't pass failing tests
9
7
  async function testsFail() {
10
8
  let logger = new TestLogger();
11
- await startRun(logger, failTestModules);
9
+ await runCollection(logger, [FailTests], 0, "test_pass.tests.js");
10
+ if (logger.errored)
11
+ throw new Error("an error occured");
12
12
  if (!logger.failed)
13
13
  return "fail tests failed to fail";
14
14
  }
15
15
  // jackrabbit test run won't fail passing tests
16
16
  async function testsPass() {
17
17
  let logger = new TestLogger();
18
- await startRun(logger, passTestModules);
18
+ await runCollection(logger, [PassTests], 1, "test_fail.tests.js");
19
+ if (logger.errored)
20
+ throw new Error("an error occured");
19
21
  if (logger.failed)
20
22
  return "passing tests failed to pass";
21
23
  }
22
- const tests = [testsFail, testsPass];
23
- const options = {
24
- title: "Failures and Successes",
24
+ async function testsError() {
25
+ let logger = new TestLogger();
26
+ await runCollection(logger, [ErrorTests], 2, "test_error.tests.js");
27
+ if (!logger.errored)
28
+ return "tests failed to error";
29
+ if (logger.failed)
30
+ return "tests should error not fail";
31
+ }
32
+ const testFailures = {
33
+ tests: [testsFail],
34
+ options: {
35
+ title: "Failures",
36
+ },
37
+ };
38
+ const testSuccesses = {
39
+ tests: [testsPass],
40
+ options: {
41
+ title: "Sucesses",
42
+ },
25
43
  };
26
- const testModule = {
27
- tests,
28
- options,
44
+ const testErrors = {
45
+ tests: [testsError],
46
+ options: {
47
+ title: "Errors",
48
+ },
29
49
  };
30
- export const testModules = [testModule];
50
+ export const testModules = [testFailures, testSuccesses, testErrors];
@@ -0,0 +1,9 @@
1
+ declare function testStuffAndError(): undefined;
2
+ declare function testMoreStuffAndError(): string[];
3
+ declare function testStuffAndErrorAsync(): Promise<undefined>;
4
+ declare function testMoreStuffAndErrorAsync(): Promise<string[]>;
5
+ export declare const tests: (typeof testStuffAndError | typeof testMoreStuffAndError | typeof testStuffAndErrorAsync | typeof testMoreStuffAndErrorAsync)[];
6
+ export declare const options: {
7
+ title: string;
8
+ };
9
+ export {};
@@ -0,0 +1,27 @@
1
+ function testStuffAndError() {
2
+ throw Error("yo");
3
+ return;
4
+ }
5
+ function testMoreStuffAndError() {
6
+ throw Error("bro");
7
+ return ["bro"];
8
+ }
9
+ async function testStuffAndErrorAsync() {
10
+ throw Error("what's");
11
+ return;
12
+ }
13
+ async function testMoreStuffAndErrorAsync() {
14
+ throw Error("good");
15
+ return ["good"];
16
+ }
17
+ // export tests
18
+ export const tests = [
19
+ testStuffAndError,
20
+ testMoreStuffAndError,
21
+ testStuffAndErrorAsync,
22
+ testMoreStuffAndErrorAsync,
23
+ ];
24
+ // export optional test details
25
+ export const options = {
26
+ title: import.meta.url,
27
+ };
@@ -0,0 +1,9 @@
1
+ declare function testStuffAndError(): undefined;
2
+ declare function testMoreStuffAndError(): string[];
3
+ declare function testStuffAndErrorAsync(): Promise<undefined>;
4
+ declare function testMoreStuffAndErrorAsync(): Promise<string[]>;
5
+ export declare const tests: (typeof testStuffAndError | typeof testMoreStuffAndError | typeof testStuffAndErrorAsync | typeof testMoreStuffAndErrorAsync)[];
6
+ export declare const options: {
7
+ title: string;
8
+ };
9
+ export {};
@@ -0,0 +1,27 @@
1
+ function testStuffAndError() {
2
+ throw Error("yo");
3
+ return;
4
+ }
5
+ function testMoreStuffAndError() {
6
+ throw Error("bro");
7
+ return ["bro"];
8
+ }
9
+ async function testStuffAndErrorAsync() {
10
+ throw Error("what's");
11
+ return;
12
+ }
13
+ async function testMoreStuffAndErrorAsync() {
14
+ throw Error("good");
15
+ return ["good"];
16
+ }
17
+ // export tests
18
+ export const tests = [
19
+ testStuffAndError,
20
+ testMoreStuffAndError,
21
+ testStuffAndErrorAsync,
22
+ testMoreStuffAndErrorAsync,
23
+ ];
24
+ // export optional test details
25
+ export const options = {
26
+ title: import.meta.url,
27
+ };
@@ -1,7 +1,8 @@
1
- import type { LoggerAction, LoggerInterface, TestModule } from "../../core/dist/mod.ts";
1
+ import type { LoggerAction, LoggerInterface } from "../../core/dist/mod.ts";
2
2
  declare class TestLogger implements LoggerInterface {
3
3
  cancelled: boolean;
4
+ errored: boolean;
4
5
  failed: boolean;
5
- log(_testModule: TestModule[], action: LoggerAction): void;
6
+ log(action: LoggerAction): void;
6
7
  }
7
8
  export { TestLogger };
@@ -1,10 +1,14 @@
1
1
  class TestLogger {
2
2
  cancelled = false;
3
+ errored = false;
3
4
  failed = false;
4
- log(_testModule, action) {
5
+ log(action) {
5
6
  if (hasTestFailed(action)) {
6
7
  this.failed = true;
7
8
  }
9
+ if ("test_error" === action.type) {
10
+ this.errored = true;
11
+ }
8
12
  }
9
13
  }
10
14
  function hasTestFailed(action) {
package/tests/src/mod.ts CHANGED
@@ -1,39 +1,55 @@
1
1
  import * as FailTests from "./test_fail.test.js";
2
2
  import * as PassTests from "./test_pass.test.js";
3
+ import * as ErrorTests from "./test_error.test.js";
3
4
 
4
- import { startRun } from "../../core/dist/mod.js";
5
+ import { runCollection } from "../../core/dist/mod.js";
5
6
  import { TestLogger } from "./test_logger.js";
6
7
 
7
- // Test pass and fail behavior
8
-
9
- const failTestModules = [FailTests];
10
- const passTestModules = [PassTests];
11
-
12
8
  // jackrabbit test run won't pass failing tests
13
9
  async function testsFail() {
14
10
  let logger = new TestLogger();
15
- await startRun(logger, failTestModules);
11
+ await runCollection(logger, [FailTests], 0, "test_pass.tests.js");
16
12
 
13
+ if (logger.errored) throw new Error("an error occured");
17
14
  if (!logger.failed) return "fail tests failed to fail";
18
15
  }
19
16
 
20
17
  // jackrabbit test run won't fail passing tests
21
18
  async function testsPass() {
22
19
  let logger = new TestLogger();
23
- await startRun(logger, passTestModules);
20
+ await runCollection(logger, [PassTests], 1, "test_fail.tests.js");
24
21
 
22
+ if (logger.errored) throw new Error("an error occured");
25
23
  if (logger.failed) return "passing tests failed to pass";
26
24
  }
27
25
 
28
- const tests = [testsFail, testsPass];
26
+ async function testsError() {
27
+ let logger = new TestLogger();
28
+ await runCollection(logger, [ErrorTests], 2, "test_error.tests.js");
29
+
30
+ if (!logger.errored) return "tests failed to error";
31
+ if (logger.failed) return "tests should error not fail";
32
+ }
33
+
34
+ const testFailures = {
35
+ tests: [testsFail],
36
+ options: {
37
+ title: "Failures",
38
+ },
39
+ };
29
40
 
30
- const options = {
31
- title: "Failures and Successes",
41
+ const testSuccesses = {
42
+ tests: [testsPass],
43
+ options: {
44
+ title: "Sucesses",
45
+ },
32
46
  };
33
47
 
34
- const testModule = {
35
- tests,
36
- options,
48
+ const testErrors = {
49
+ tests: [testsError],
50
+ options: {
51
+ title: "Errors",
52
+ },
37
53
  };
38
54
 
39
- export const testModules = [testModule];
55
+ export const testModules = [testFailures, testSuccesses, testErrors];
@@ -0,0 +1,32 @@
1
+ function testStuffAndError(): undefined {
2
+ throw Error("yo");
3
+ return;
4
+ }
5
+
6
+ function testMoreStuffAndError() {
7
+ throw Error("bro");
8
+ return ["bro"];
9
+ }
10
+
11
+ async function testStuffAndErrorAsync(): Promise<undefined> {
12
+ throw Error("what's");
13
+ return;
14
+ }
15
+
16
+ async function testMoreStuffAndErrorAsync(): Promise<string[]> {
17
+ throw Error("good");
18
+ return ["good"];
19
+ }
20
+
21
+ // export tests
22
+ export const tests = [
23
+ testStuffAndError,
24
+ testMoreStuffAndError,
25
+ testStuffAndErrorAsync,
26
+ testMoreStuffAndErrorAsync,
27
+ ];
28
+
29
+ // export optional test details
30
+ export const options = {
31
+ title: import.meta.url,
32
+ };
@@ -6,12 +6,17 @@ import type {
6
6
 
7
7
  class TestLogger implements LoggerInterface {
8
8
  cancelled: boolean = false;
9
+ errored: boolean = false;
9
10
  failed: boolean = false;
10
11
 
11
- log(_testModule: TestModule[], action: LoggerAction) {
12
+ log(action: LoggerAction) {
12
13
  if (hasTestFailed(action)) {
13
14
  this.failed = true;
14
15
  }
16
+
17
+ if ("test_error" === action.type) {
18
+ this.errored = true;
19
+ }
15
20
  }
16
21
  }
17
22
 
@@ -1 +1 @@
1
- {"root":["./src/mod.ts","./src/test_fail.test.ts","./src/test_logger.ts","./src/test_pass.test.ts"],"version":"5.9.3"}
1
+ {"root":["./src/mod.ts","./src/test_error.test.ts","./src/test_fail.test.ts","./src/test_logger.ts","./src/test_pass.test.ts"],"version":"5.9.3"}
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "lib": ["ESNext"],
3
+ "lib": ["ESNext", "DOM"],
4
4
  "module": "nodenext",
5
5
  "target": "esnext",
6
6
  "strict": true,
@@ -0,0 +1,57 @@
1
+ import * as path from "path";
2
+ export async function createConfig(args) {
3
+ let configFilepath = args[0];
4
+ let relPath = path.resolve(process.cwd(), configFilepath);
5
+ try {
6
+ // windows might need a "file://<relPath>" situation
7
+ let { default: json } = await import(`file://${relPath}`, {
8
+ with: { type: "json" },
9
+ });
10
+ let hostAndPort = URL.parse(json.host_and_port);
11
+ if (!hostAndPort)
12
+ throw new Error(`Config: invalid host_and_port json property`);
13
+ let { run_asynchronously: runAsynchronously } = json;
14
+ if (typeof runAsynchronously !== "boolean" &&
15
+ undefined !== runAsynchronously)
16
+ throw new Error("Config: the property runAsynchronously is not a boolean or undefined");
17
+ let webdrivers = [];
18
+ if (Array.isArray(json.webdrivers))
19
+ for (const [index, webdriverParams] of json.webdrivers.entries()) {
20
+ let params = createWebdriverParams(webdriverParams);
21
+ if (params instanceof Error)
22
+ return params;
23
+ let session = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
24
+ let jrId = `${index}:${session.toString(32)}`;
25
+ webdrivers.push({ ...params, jrId });
26
+ }
27
+ return {
28
+ hostAndPort,
29
+ runAsynchronously,
30
+ webdrivers,
31
+ };
32
+ }
33
+ catch (e) {
34
+ if (e instanceof Error)
35
+ return e;
36
+ return new Error("Config: failed to parse config params from string");
37
+ }
38
+ }
39
+ export function createWebdriverParams(json) {
40
+ let { command, url, title, timeout_ms, capabilities } = json;
41
+ if (typeof command !== "string")
42
+ return new Error("WebdriverParams: command is not a string");
43
+ let parsedUrl = URL.parse(url);
44
+ if (null === parsedUrl)
45
+ return new Error("WebdriverParams: url is not a valid URL");
46
+ if (typeof title !== "string")
47
+ return new Error("WebdriverParams: title is not a string");
48
+ if (typeof timeout_ms !== "number")
49
+ return new Error("WebdriverParams: timeout_ms is not a number");
50
+ return {
51
+ command,
52
+ url: parsedUrl,
53
+ title,
54
+ timeoutMs: timeout_ms,
55
+ capabilities,
56
+ };
57
+ }
@@ -0,0 +1,18 @@
1
+ export class EventBus {
2
+ #eventMap = new Map();
3
+ addListener(type, cb) {
4
+ let listeners = this.#eventMap.get(type);
5
+ if (!listeners) {
6
+ listeners = [];
7
+ this.#eventMap.set(type, listeners);
8
+ }
9
+ listeners.push(cb);
10
+ }
11
+ dispatchAction(action) {
12
+ let listeners = this.#eventMap.get(action.type);
13
+ if (listeners)
14
+ for (const listener of listeners) {
15
+ listener(action);
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,21 @@
1
+ export class Listeners {
2
+ #eventMap = new Map();
3
+ addEventListener(eventName, cb) {
4
+ let eventListeners = this.#eventMap.get(eventName);
5
+ if (!eventListeners) {
6
+ eventListeners = [];
7
+ this.#eventMap.set(eventName, eventListeners);
8
+ }
9
+ eventListeners.push(cb);
10
+ }
11
+ dispatchEvent(event) {
12
+ let eventListeners = this.#eventMap.get(event.type);
13
+ if (eventListeners)
14
+ for (const listener of eventListeners) {
15
+ listener instanceof Function
16
+ ? listener(event)
17
+ : listener.handleEvent(event);
18
+ }
19
+ return event.cancelable || event.defaultPrevented;
20
+ }
21
+ }
@@ -0,0 +1,203 @@
1
+ import { getResultsAsString } from "./results_str.js";
2
+ export class Logger {
3
+ #eventbus;
4
+ #sessionResults = {
5
+ fails: 0,
6
+ errors: 0,
7
+ runs: new Map(),
8
+ };
9
+ constructor(config, eventbus) {
10
+ this.#eventbus = eventbus;
11
+ this.#eventbus.addListener("log", this.#boundLog);
12
+ this.#eventbus.addListener("session_error", this.#boundError);
13
+ for (let webdriverParams of config.webdrivers) {
14
+ this.#sessionResults.runs.set(webdriverParams.jrId, {
15
+ startTime: 0,
16
+ fails: 0,
17
+ errors: 0,
18
+ expectedTests: 0,
19
+ expectedModules: 0,
20
+ endTime: 0,
21
+ testTime: 0,
22
+ errorLogs: [],
23
+ completedTests: 0,
24
+ completedModules: 0,
25
+ expectedCollections: 0,
26
+ completedCollections: 0,
27
+ webdriverParams,
28
+ collections: [],
29
+ });
30
+ }
31
+ }
32
+ get failed() {
33
+ return this.#sessionResults.fails !== 0;
34
+ }
35
+ get errored() {
36
+ return this.#sessionResults.errors !== 0;
37
+ }
38
+ get compeleted() {
39
+ return false;
40
+ }
41
+ get results() {
42
+ return getResultsAsString(this.#sessionResults);
43
+ }
44
+ // get output
45
+ // output being a array of a string
46
+ #boundError = this.#onError.bind(this);
47
+ #onError(action) {
48
+ let runResults = this.#sessionResults.runs.get(action.id);
49
+ if (runResults) {
50
+ this.#sessionResults.errors += 1;
51
+ runResults.errors += 1;
52
+ runResults.errorLogs.push(action);
53
+ }
54
+ }
55
+ #boundLog = this.#onLog.bind(this);
56
+ #onLog(action) {
57
+ let { loggerAction, id } = action;
58
+ let runResults = this.#sessionResults.runs.get(id);
59
+ if (!runResults)
60
+ return;
61
+ if ("start_run" === loggerAction.type) {
62
+ runResults.startTime = loggerAction.time;
63
+ runResults.expectedCollections = loggerAction.expected_collection_count;
64
+ }
65
+ if ("end_run" === loggerAction.type) {
66
+ runResults.endTime = loggerAction.time;
67
+ this.#eventbus.dispatchAction({
68
+ type: "run_complete",
69
+ id,
70
+ });
71
+ }
72
+ if ("run_error" === loggerAction.type) {
73
+ this.#sessionResults.errors += 1;
74
+ runResults.errors += 1;
75
+ runResults.errorLogs.push(action);
76
+ }
77
+ if ("start_collection" === loggerAction.type) {
78
+ runResults.collections[loggerAction.collection_id] = {
79
+ completedModules: 0,
80
+ completedTests: 0,
81
+ errorLogs: [],
82
+ errors: 0,
83
+ expectedModules: loggerAction.expected_module_count,
84
+ expectedTests: 0,
85
+ fails: 0,
86
+ loggerAction,
87
+ modules: [],
88
+ };
89
+ runResults.expectedModules += loggerAction.expected_module_count;
90
+ }
91
+ if ("end_collection" === loggerAction.type) {
92
+ let collection = runResults.collections[loggerAction.collection_id];
93
+ if (!collection)
94
+ return;
95
+ runResults.completedCollections += 1;
96
+ }
97
+ if ("collection_error" === loggerAction.type) {
98
+ let collection = runResults.collections[loggerAction.collection_id];
99
+ if (!collection)
100
+ return;
101
+ this.#sessionResults.errors += 1;
102
+ runResults.errors += 1;
103
+ collection.errors += 1;
104
+ collection.errorLogs.push(loggerAction);
105
+ }
106
+ if ("start_module" === loggerAction.type) {
107
+ let collection = runResults.collections[loggerAction.collection_id];
108
+ if (!collection)
109
+ return;
110
+ collection.modules[loggerAction.module_id] = {
111
+ completedTests: 0,
112
+ errorLogs: [],
113
+ errors: 0,
114
+ expectedTests: loggerAction.expected_test_count,
115
+ fails: 0,
116
+ loggerAction,
117
+ testResults: [],
118
+ };
119
+ collection.expectedTests += loggerAction.expected_test_count;
120
+ runResults.expectedTests += loggerAction.expected_test_count;
121
+ }
122
+ if ("end_module" === loggerAction.type) {
123
+ let collection = runResults.collections[loggerAction.collection_id];
124
+ if (!collection)
125
+ return;
126
+ let module = collection.modules[loggerAction.module_id];
127
+ if (!module)
128
+ return;
129
+ runResults.completedModules += 1;
130
+ collection.completedModules += 1;
131
+ }
132
+ if ("module_error" === loggerAction.type) {
133
+ let collection = runResults.collections[loggerAction.collection_id];
134
+ if (!collection)
135
+ return;
136
+ let module = collection.modules[loggerAction.module_id];
137
+ if (!module)
138
+ return;
139
+ this.#sessionResults.errors += 1;
140
+ runResults.errors += 1;
141
+ collection.errors += 1;
142
+ module.errors += 1;
143
+ module.errorLogs.push(loggerAction);
144
+ }
145
+ if ("start_test" === loggerAction.type) {
146
+ let collection = runResults.collections[loggerAction.collection_id];
147
+ if (!collection)
148
+ return;
149
+ let module = collection.modules[loggerAction.module_id];
150
+ if (!module)
151
+ return;
152
+ module.testResults[loggerAction.test_id] = {
153
+ loggerStartAction: loggerAction,
154
+ loggerEndAction: undefined,
155
+ };
156
+ }
157
+ if ("end_test" === loggerAction.type) {
158
+ endTest(this.#sessionResults, runResults, loggerAction);
159
+ }
160
+ if ("test_error" === loggerAction.type) {
161
+ let collection = runResults.collections[loggerAction.collection_id];
162
+ if (!collection)
163
+ return;
164
+ let module = collection.modules[loggerAction.module_id];
165
+ if (!module)
166
+ return;
167
+ let testResult = module.testResults[loggerAction.test_id];
168
+ if (!testResult)
169
+ return;
170
+ testResult.loggerEndAction = loggerAction;
171
+ this.#sessionResults.errors += 1;
172
+ runResults.errors += 1;
173
+ collection.errors += 1;
174
+ module.errors += 1;
175
+ }
176
+ }
177
+ }
178
+ function endTest(sessionResults, runResults, loggerAction) {
179
+ let collection = runResults.collections[loggerAction.collection_id];
180
+ if (!collection)
181
+ return;
182
+ let module = collection.modules[loggerAction.module_id];
183
+ if (!module)
184
+ return;
185
+ let testResult = module.testResults[loggerAction.test_id];
186
+ if (!testResult)
187
+ return;
188
+ testResult.loggerEndAction = loggerAction;
189
+ runResults.completedTests += 1;
190
+ collection.completedTests += 1;
191
+ module.completedTests += 1;
192
+ let { assertions } = loggerAction;
193
+ const isAssertionArray = Array.isArray(assertions) && assertions.length;
194
+ // might be worth just sticking with language standard "none" like "" or 0 or false
195
+ const isAssertion = !Array.isArray(assertions) && undefined !== assertions;
196
+ if (isAssertion || isAssertionArray) {
197
+ sessionResults.fails += 1;
198
+ runResults.fails += 1;
199
+ collection.fails += 1;
200
+ module.fails += 1;
201
+ }
202
+ runResults.testTime += Math.max(0, loggerAction.end_time - loggerAction.start_time);
203
+ }
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import * as http from "http";
3
+ import { createConfig } from "./config.js";
4
+ import { Logger } from "./logger.js";
5
+ import { Router } from "./routes.js";
6
+ import { WebDrivers } from "./webdriver.js";
7
+ import { EventBus } from "./eventbus.js";
8
+ let args = process.argv.slice(2);
9
+ const config = await createConfig(args);
10
+ if (config instanceof Error) {
11
+ console.log(config);
12
+ process.exit(1);
13
+ }
14
+ let eventbus = new EventBus();
15
+ let logger = new Logger(config, eventbus);
16
+ let router = new Router(config, eventbus);
17
+ let webdrivers = new WebDrivers(config, eventbus);
18
+ // setup server
19
+ let server = http.createServer();
20
+ server.addListener("request", router.route);
21
+ server.addListener("close", function () {
22
+ console.log(logger.results);
23
+ logger.errored || logger.failed ? process.exit(1) : process.exit(0);
24
+ });
25
+ eventbus.addListener("end", function () {
26
+ server.closeAllConnections();
27
+ server.close();
28
+ });
29
+ // run server
30
+ let { port, hostname } = config.hostAndPort;
31
+ server.listen({
32
+ port,
33
+ hostname,
34
+ });
35
+ // start test run
36
+ config.runAsynchronously ? webdrivers.runAll() : webdrivers.run();