@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.
- package/.github/workflows/browsers.json +45 -0
- package/.github/workflows/browsers.macos.json +51 -0
- package/.github/workflows/browsers.windows.json +19 -0
- package/.github/workflows/tests.yml +24 -0
- package/README.md +41 -1
- package/browser/dist/logger.js +43 -0
- package/browser/dist/mod.js +26 -0
- package/browser/dist/queue.js +27 -0
- package/browser/dist/runner.js +20 -0
- package/{cli → browser}/package.json +1 -1
- package/browser/src/logger.ts +57 -0
- package/browser/src/mod.ts +30 -0
- package/browser/src/runner.ts +22 -0
- package/browser/tsconfig.json +11 -0
- package/browser/tsconfig.tsbuildinfo +1 -0
- package/browsers.json +38 -0
- package/core/dist/jackrabbit_types.d.ts +61 -27
- package/core/dist/mod.d.ts +2 -2
- package/core/dist/mod.js +1 -1
- package/core/dist/run_steps.d.ts +2 -2
- package/core/dist/run_steps.js +83 -67
- package/core/src/jackrabbit_types.ts +72 -28
- package/core/src/mod.ts +2 -8
- package/core/src/run_steps.ts +111 -80
- package/examples/hello_world/goodbye_world.ts +1 -1
- package/examples/hello_world/hello_world.ts +1 -1
- package/nodejs/dist/logger.js +161 -0
- package/nodejs/dist/mod.js +31 -0
- package/nodejs/dist/results.js +139 -0
- package/nodejs/dist/results_str.js +147 -0
- package/nodejs/dist/runner.js +17 -0
- package/nodejs/src/logger.ts +193 -0
- package/nodejs/src/mod.ts +37 -0
- package/nodejs/src/results_str.ts +234 -0
- package/{nodejs_cli → nodejs}/tsconfig.json +2 -1
- package/nodejs/tsconfig.tsbuildinfo +1 -0
- package/package.json +6 -4
- package/tests/dist/mod.d.ts +14 -3
- package/tests/dist/mod.js +33 -13
- package/tests/dist/test_error.test.d.ts +9 -0
- package/tests/dist/test_error.test.js +27 -0
- package/tests/dist/test_errors.test.d.ts +9 -0
- package/tests/dist/test_errors.test.js +27 -0
- package/tests/dist/test_logger.d.ts +3 -2
- package/tests/dist/test_logger.js +5 -1
- package/tests/src/mod.ts +31 -15
- package/tests/src/test_error.test.ts +32 -0
- package/tests/src/test_logger.ts +6 -1
- package/tests/tsconfig.tsbuildinfo +1 -1
- package/tsconfig.json +1 -1
- package/webdriver/dist/config.js +57 -0
- package/webdriver/dist/eventbus.js +18 -0
- package/webdriver/dist/listeners.js +21 -0
- package/webdriver/dist/logger.js +203 -0
- package/webdriver/dist/mod.js +36 -0
- package/webdriver/dist/results_str.js +167 -0
- package/webdriver/dist/routes.js +172 -0
- package/webdriver/dist/routes2.js +163 -0
- package/webdriver/dist/test_hangar.js +20 -0
- package/webdriver/dist/webdriver.js +273 -0
- package/webdriver/package.json +8 -0
- package/webdriver/src/config.ts +89 -0
- package/webdriver/src/eventbus.ts +104 -0
- package/webdriver/src/logger.ts +247 -0
- package/webdriver/src/mod.ts +43 -0
- package/webdriver/src/results.ts +56 -0
- package/webdriver/src/results_str.ts +222 -0
- package/webdriver/src/routes.ts +211 -0
- package/webdriver/src/test_hangar.ts +25 -0
- package/webdriver/src/webdriver.ts +372 -0
- package/{cli → webdriver}/tsconfig.json +1 -0
- package/webdriver/tsconfig.tsbuildinfo +1 -0
- package/cli/dist/cli.d.ts +0 -3
- package/cli/dist/cli.js +0 -8
- package/cli/dist/cli_types.d.ts +0 -7
- package/cli/dist/config.d.ts +0 -5
- package/cli/dist/config.js +0 -6
- package/cli/dist/importer.d.ts +0 -7
- package/cli/dist/importer.js +0 -16
- package/cli/dist/logger.d.ts +0 -7
- package/cli/dist/logger.js +0 -88
- package/cli/dist/mod.d.ts +0 -6
- package/cli/dist/mod.js +0 -4
- package/cli/src/cli.ts +0 -17
- package/cli/src/cli_types.ts +0 -9
- package/cli/src/config.ts +0 -9
- package/cli/src/importer.ts +0 -25
- package/cli/src/logger.ts +0 -126
- package/cli/src/mod.ts +0 -7
- package/cli/tsconfig.tsbuildinfo +0 -1
- package/nodejs_cli/dist/mod.d.ts +0 -2
- package/nodejs_cli/dist/mod.js +0 -20
- package/nodejs_cli/src/mod.ts +0 -25
- package/nodejs_cli/tsconfig.tsbuildinfo +0 -1
- /package/{nodejs_cli → nodejs}/package.json +0 -0
- /package/{cli/dist/cli_types.js → webdriver/dist/results.js} +0 -0
|
@@ -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();
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const SPACE = " ";
|
|
2
|
+
export function getResultsAsString(sessionResults) {
|
|
3
|
+
const output = [];
|
|
4
|
+
// Lots of nested loops because results a nested structure.
|
|
5
|
+
// I'd rather see composition nested in one function
|
|
6
|
+
// than have for loops spread across each function.
|
|
7
|
+
logSessionErrors(output, sessionResults);
|
|
8
|
+
for (let [, result] of sessionResults.runs) {
|
|
9
|
+
if (logRunResults(output, result))
|
|
10
|
+
continue;
|
|
11
|
+
for (const collection of result.collections) {
|
|
12
|
+
if (logCollectionResult(output, collection))
|
|
13
|
+
continue;
|
|
14
|
+
if (collection)
|
|
15
|
+
for (const moduleResult of collection.modules) {
|
|
16
|
+
if (logModuleResult(output, moduleResult))
|
|
17
|
+
continue;
|
|
18
|
+
if (moduleResult)
|
|
19
|
+
for (const testResult of moduleResult.testResults) {
|
|
20
|
+
logTest(output, testResult);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
logSummary(output, sessionResults);
|
|
26
|
+
return output.join("\n");
|
|
27
|
+
}
|
|
28
|
+
function logSessionErrors(output, sessionResults) {
|
|
29
|
+
for (let [, result] of sessionResults.runs) {
|
|
30
|
+
for (let errorAction of result.errorLogs) {
|
|
31
|
+
if ("session_error" === errorAction.type) {
|
|
32
|
+
output.push(`\n[${result.webdriverParams.title}:session_error] ${errorAction.error}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function logRunResults(output, result) {
|
|
38
|
+
output.push(`
|
|
39
|
+
${result.webdriverParams.title}`);
|
|
40
|
+
for (let errorAction of result.errorLogs) {
|
|
41
|
+
if ("log" === errorAction.type) {
|
|
42
|
+
if ("run_error" === errorAction.loggerAction.type) {
|
|
43
|
+
output.push(`${SPACE}[run_error] ${errorAction.loggerAction.error}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!result.expectedTests) {
|
|
48
|
+
output.push(` No test runs occured.`);
|
|
49
|
+
}
|
|
50
|
+
// When everything goes right :3
|
|
51
|
+
if (!result.fails &&
|
|
52
|
+
!result.errors &&
|
|
53
|
+
result.expectedTests === result.completedTests &&
|
|
54
|
+
result.expectedModules === result.completedModules &&
|
|
55
|
+
result.expectedCollections === result.completedCollections) {
|
|
56
|
+
output.push(`${SPACE}${result.completedTests} tests
|
|
57
|
+
${SPACE}${result.completedModules} modules
|
|
58
|
+
${SPACE}${result.completedCollections} collections`);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
function logCollectionResult(output, collection) {
|
|
64
|
+
if (!collection)
|
|
65
|
+
return true;
|
|
66
|
+
let { loggerAction } = collection;
|
|
67
|
+
if ("start_collection" !== loggerAction.type)
|
|
68
|
+
return true;
|
|
69
|
+
output.push(`${SPACE}${loggerAction.collection_url}`);
|
|
70
|
+
// when everything in the collection goes right
|
|
71
|
+
if (!collection.fails &&
|
|
72
|
+
!collection.errors &&
|
|
73
|
+
collection.expectedTests === collection.completedTests &&
|
|
74
|
+
collection.expectedModules === collection.completedModules) {
|
|
75
|
+
output.push(`${SPACE.repeat(2)}${collection.expectedTests} tests
|
|
76
|
+
${SPACE.repeat(2)}${loggerAction.expected_module_count} modules`);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
for (let errorAction of collection.errorLogs) {
|
|
80
|
+
if ("collection_error" !== errorAction.type)
|
|
81
|
+
continue;
|
|
82
|
+
output.push(`${SPACE.repeat(2)}[collection_error] ${errorAction.error}`);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
function logModuleResult(output, module) {
|
|
87
|
+
if (!module)
|
|
88
|
+
return true;
|
|
89
|
+
let { loggerAction } = module;
|
|
90
|
+
if ("start_module" !== loggerAction.type)
|
|
91
|
+
return true;
|
|
92
|
+
output.push(`${SPACE.repeat(2)}${loggerAction.module_name}`);
|
|
93
|
+
// when everything in the module goes right
|
|
94
|
+
if (!module.fails &&
|
|
95
|
+
!module.errors &&
|
|
96
|
+
module.expectedTests === module.completedTests) {
|
|
97
|
+
output.push(`${SPACE.repeat(3)}${module.expectedTests} tests`);
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
for (let errorAction of module.errorLogs) {
|
|
101
|
+
if ("collection_error" !== errorAction.type)
|
|
102
|
+
continue;
|
|
103
|
+
output.push(`${SPACE.repeat(2)}[module_error] ${errorAction.error}`);
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
function logTest(output, test) {
|
|
108
|
+
if (!test)
|
|
109
|
+
return;
|
|
110
|
+
let { loggerStartAction, loggerEndAction } = test;
|
|
111
|
+
if ("start_test" !== loggerStartAction.type)
|
|
112
|
+
return;
|
|
113
|
+
if ("test_error" === loggerEndAction?.type) {
|
|
114
|
+
let { test_name } = loggerStartAction;
|
|
115
|
+
output.push(`${SPACE.repeat(3)}${test_name}
|
|
116
|
+
${SPACE.repeat(4)}[error] ${loggerEndAction.error}`);
|
|
117
|
+
}
|
|
118
|
+
if ("end_test" === loggerEndAction?.type) {
|
|
119
|
+
let { assertions } = loggerEndAction;
|
|
120
|
+
const isAssertionArray = Array.isArray(assertions) && assertions.length;
|
|
121
|
+
const isAssertion = !Array.isArray(assertions) &&
|
|
122
|
+
undefined !== assertions &&
|
|
123
|
+
null !== assertions;
|
|
124
|
+
if (isAssertion || isAssertionArray) {
|
|
125
|
+
let { test_name } = loggerStartAction;
|
|
126
|
+
output.push(`${SPACE.repeat(3)}${test_name}`);
|
|
127
|
+
}
|
|
128
|
+
if (isAssertion) {
|
|
129
|
+
output.push(`${SPACE.repeat(4)}- ${assertions}`);
|
|
130
|
+
}
|
|
131
|
+
if (isAssertionArray) {
|
|
132
|
+
for (const assertion of assertions) {
|
|
133
|
+
output.push(`${SPACE.repeat(4)}- ${assertion}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function logSummary(output, sessionResults) {
|
|
139
|
+
let status_with_color = blue("\u{2714} passed");
|
|
140
|
+
if (sessionResults.fails)
|
|
141
|
+
status_with_color = yellow("\u{2717} failed");
|
|
142
|
+
if (sessionResults.errors)
|
|
143
|
+
status_with_color = gray("\u{2717} errored");
|
|
144
|
+
// expected tests
|
|
145
|
+
let totalTime = 0;
|
|
146
|
+
let testTime = 0;
|
|
147
|
+
for (let [, run] of sessionResults.runs) {
|
|
148
|
+
totalTime += run.endTime - run.startTime;
|
|
149
|
+
testTime += run.testTime;
|
|
150
|
+
}
|
|
151
|
+
output.push(`
|
|
152
|
+
${status_with_color}
|
|
153
|
+
duration: ${testTime.toFixed(4)} mS
|
|
154
|
+
total: ${totalTime.toFixed(4)} mS
|
|
155
|
+
`);
|
|
156
|
+
}
|
|
157
|
+
// 39 - default foreground color
|
|
158
|
+
// 49 - default background color
|
|
159
|
+
function blue(text) {
|
|
160
|
+
return `\x1b[44m\x1b[97m${text}\x1b[0m`;
|
|
161
|
+
}
|
|
162
|
+
function yellow(text) {
|
|
163
|
+
return `\x1b[43m\x1b[97m${text}\x1b[0m`;
|
|
164
|
+
}
|
|
165
|
+
function gray(text) {
|
|
166
|
+
return `\x1b[100m\x1b[97m${text}\x1b[0m`;
|
|
167
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { testHanger } from "./test_hangar.js";
|
|
4
|
+
let cwd = process.cwd();
|
|
5
|
+
// better done with URL? feels weird
|
|
6
|
+
let corePath = path.join(import.meta.url.substring(5), "../../../core/dist/");
|
|
7
|
+
let browserPath = path.join(import.meta.url.substring(5), "../../../browser/dist/");
|
|
8
|
+
const MIME_TYPES = {
|
|
9
|
+
octet: "application/octet-stream",
|
|
10
|
+
html: "text/html; charset=UTF-8",
|
|
11
|
+
js: "text/javascript",
|
|
12
|
+
json: "application/json",
|
|
13
|
+
css: "text/css",
|
|
14
|
+
png: "image/png",
|
|
15
|
+
jpg: "image/jpeg",
|
|
16
|
+
ico: "image/x-icon",
|
|
17
|
+
svg: "image/svg+xml",
|
|
18
|
+
};
|
|
19
|
+
export class Router {
|
|
20
|
+
#config;
|
|
21
|
+
#eventbus;
|
|
22
|
+
constructor(config, eventbus) {
|
|
23
|
+
this.#config = config;
|
|
24
|
+
this.#eventbus = eventbus;
|
|
25
|
+
}
|
|
26
|
+
get route() {
|
|
27
|
+
return this.#boundRoute;
|
|
28
|
+
}
|
|
29
|
+
#boundRoute = this.#route.bind(this);
|
|
30
|
+
async #route(req, res) {
|
|
31
|
+
if (serveBadRequest(req, res))
|
|
32
|
+
return;
|
|
33
|
+
if (servePing(req, res))
|
|
34
|
+
return;
|
|
35
|
+
if (serveTestPage(req, res, this.#config))
|
|
36
|
+
return;
|
|
37
|
+
if (logAction(req, res, this.#eventbus))
|
|
38
|
+
return;
|
|
39
|
+
await serveFile(req, res);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function serveBadRequest(req, res) {
|
|
43
|
+
let { url } = req;
|
|
44
|
+
if (url)
|
|
45
|
+
return false;
|
|
46
|
+
res.setHeader("Content-Type", "text/html");
|
|
47
|
+
res.writeHead(400);
|
|
48
|
+
res.end();
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
function servePing(req, res) {
|
|
52
|
+
let { url, method } = req;
|
|
53
|
+
if (url !== "/ping" || "GET" !== method)
|
|
54
|
+
return false;
|
|
55
|
+
res.setHeader("Content-Type", "text/html");
|
|
56
|
+
res.writeHead(200);
|
|
57
|
+
res.end("The cookie train has arrived!");
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
function serveTestPage(req, res, config) {
|
|
61
|
+
let { url, method } = req;
|
|
62
|
+
if (url !== "/" || "GET" !== method)
|
|
63
|
+
return false;
|
|
64
|
+
let hangar = testHanger({
|
|
65
|
+
jackrabbit_url: config.hostAndPort,
|
|
66
|
+
test_collections: process.argv.slice(3),
|
|
67
|
+
});
|
|
68
|
+
res.setHeader("Content-Type", "text/html");
|
|
69
|
+
res.writeHead(200);
|
|
70
|
+
res.end(hangar);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
function logAction(req, res, eventbus) {
|
|
74
|
+
let { url, method } = req;
|
|
75
|
+
if (!url?.startsWith("/log/") || "POST" !== method)
|
|
76
|
+
return false;
|
|
77
|
+
let id;
|
|
78
|
+
let cookies = req.headers.cookie?.split(";") ?? [];
|
|
79
|
+
for (const cookieLine of cookies) {
|
|
80
|
+
if (cookieLine.startsWith("jackrabbit=")) {
|
|
81
|
+
let [_name, value] = cookieLine.split("=");
|
|
82
|
+
id = value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (id) {
|
|
86
|
+
getLoggerActionFromRequestBody(req)
|
|
87
|
+
.then(function (loggerAction) {
|
|
88
|
+
eventbus.dispatchAction({
|
|
89
|
+
type: "log",
|
|
90
|
+
loggerAction,
|
|
91
|
+
id,
|
|
92
|
+
});
|
|
93
|
+
res.writeHead(201);
|
|
94
|
+
})
|
|
95
|
+
.catch(function () {
|
|
96
|
+
res.writeHead(401);
|
|
97
|
+
})
|
|
98
|
+
.finally(function () {
|
|
99
|
+
res.end();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
res.writeHead(401);
|
|
104
|
+
res.end();
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
async function serveFile(req, res) {
|
|
109
|
+
let { url, method } = req;
|
|
110
|
+
if (!url) {
|
|
111
|
+
res.setHeader("Content-Type", MIME_TYPES["html"]);
|
|
112
|
+
res.writeHead(400);
|
|
113
|
+
res.end();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
let ext = "";
|
|
117
|
+
if (url.endsWith("/"))
|
|
118
|
+
ext = "index.html";
|
|
119
|
+
let urlNoPrefix = url;
|
|
120
|
+
if (url.startsWith("/jackrabbit"))
|
|
121
|
+
urlNoPrefix = url.substring(11);
|
|
122
|
+
let filePath = path.join(cwd, urlNoPrefix, ext);
|
|
123
|
+
let stream;
|
|
124
|
+
if (url.startsWith("/jackrabbit/core/") && "GET" === method) {
|
|
125
|
+
stream = await getDirectoryScopedFile(filePath, corePath);
|
|
126
|
+
}
|
|
127
|
+
if (url.startsWith("/jackrabbit/browser/") && "GET" === method) {
|
|
128
|
+
stream = await getDirectoryScopedFile(filePath, browserPath);
|
|
129
|
+
}
|
|
130
|
+
if (!url.startsWith("/jackrabbit") && "GET" === method) {
|
|
131
|
+
stream = await getDirectoryScopedFile(filePath, cwd);
|
|
132
|
+
}
|
|
133
|
+
if (stream) {
|
|
134
|
+
// throws errors if not a string
|
|
135
|
+
// filepath is always a string
|
|
136
|
+
const ext = path.extname(filePath).substring(1).toLowerCase();
|
|
137
|
+
let mimeType = MIME_TYPES[ext] ?? MIME_TYPES["octet"];
|
|
138
|
+
res.setHeader("Content-Type", mimeType);
|
|
139
|
+
res.writeHead(200);
|
|
140
|
+
stream.pipe(res);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
res.setHeader("Content-Type", MIME_TYPES["html"]);
|
|
144
|
+
res.writeHead(404);
|
|
145
|
+
res.end();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function getLoggerActionFromRequestBody(req) {
|
|
149
|
+
return new Promise(function (resolve, reject) {
|
|
150
|
+
let data = [];
|
|
151
|
+
req.addListener("data", function (chunk) {
|
|
152
|
+
data.push(chunk);
|
|
153
|
+
});
|
|
154
|
+
req.addListener("end", function () {
|
|
155
|
+
let actionStr = Buffer.concat(data).toString();
|
|
156
|
+
let action = JSON.parse(actionStr);
|
|
157
|
+
resolve(action);
|
|
158
|
+
});
|
|
159
|
+
req.addListener("error", function (err) {
|
|
160
|
+
reject(err);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
async function getDirectoryScopedFile(filePath, basePath) {
|
|
165
|
+
if (!filePath.startsWith(basePath))
|
|
166
|
+
return;
|
|
167
|
+
try {
|
|
168
|
+
await fs.promises.access(filePath);
|
|
169
|
+
return fs.createReadStream(filePath);
|
|
170
|
+
}
|
|
171
|
+
catch { }
|
|
172
|
+
}
|