@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,247 @@
|
|
|
1
|
+
import type { EndTest } from "../../core/dist/jackrabbit_types.js";
|
|
2
|
+
import type { ConfigInterface } from "./config.js";
|
|
3
|
+
import type {
|
|
4
|
+
EventBus,
|
|
5
|
+
WebdriverLogAction,
|
|
6
|
+
WebdriverSessionErrorAction,
|
|
7
|
+
} from "./eventbus.js";
|
|
8
|
+
import type { SessionResults, RunResults } from "./results.js";
|
|
9
|
+
|
|
10
|
+
import { getResultsAsString } from "./results_str.js";
|
|
11
|
+
|
|
12
|
+
export class Logger {
|
|
13
|
+
#eventbus: EventBus;
|
|
14
|
+
|
|
15
|
+
#sessionResults: SessionResults = {
|
|
16
|
+
fails: 0,
|
|
17
|
+
errors: 0,
|
|
18
|
+
runs: new Map(),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
constructor(config: ConfigInterface, eventbus: EventBus) {
|
|
22
|
+
this.#eventbus = eventbus;
|
|
23
|
+
this.#eventbus.addListener("log", this.#boundLog);
|
|
24
|
+
this.#eventbus.addListener("session_error", this.#boundError);
|
|
25
|
+
|
|
26
|
+
for (let webdriverParams of config.webdrivers) {
|
|
27
|
+
this.#sessionResults.runs.set(webdriverParams.jrId, {
|
|
28
|
+
startTime: 0,
|
|
29
|
+
fails: 0,
|
|
30
|
+
errors: 0,
|
|
31
|
+
expectedTests: 0,
|
|
32
|
+
expectedModules: 0,
|
|
33
|
+
endTime: 0,
|
|
34
|
+
testTime: 0,
|
|
35
|
+
errorLogs: [],
|
|
36
|
+
completedTests: 0,
|
|
37
|
+
completedModules: 0,
|
|
38
|
+
expectedCollections: 0,
|
|
39
|
+
completedCollections: 0,
|
|
40
|
+
webdriverParams,
|
|
41
|
+
collections: [],
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get failed() {
|
|
47
|
+
return this.#sessionResults.fails !== 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get errored() {
|
|
51
|
+
return this.#sessionResults.errors !== 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get compeleted() {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get results(): string {
|
|
59
|
+
return getResultsAsString(this.#sessionResults);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// get output
|
|
63
|
+
// output being a array of a string
|
|
64
|
+
#boundError = this.#onError.bind(this);
|
|
65
|
+
#onError(action: WebdriverSessionErrorAction) {
|
|
66
|
+
let runResults = this.#sessionResults.runs.get(action.id);
|
|
67
|
+
if (runResults) {
|
|
68
|
+
this.#sessionResults.errors += 1;
|
|
69
|
+
runResults.errors += 1;
|
|
70
|
+
runResults.errorLogs.push(action);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#boundLog = this.#onLog.bind(this);
|
|
75
|
+
#onLog(action: WebdriverLogAction) {
|
|
76
|
+
let { loggerAction, id } = action;
|
|
77
|
+
|
|
78
|
+
let runResults = this.#sessionResults.runs.get(id);
|
|
79
|
+
if (!runResults) return;
|
|
80
|
+
|
|
81
|
+
if ("start_run" === loggerAction.type) {
|
|
82
|
+
runResults.startTime = loggerAction.time;
|
|
83
|
+
runResults.expectedCollections = loggerAction.expected_collection_count;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ("end_run" === loggerAction.type) {
|
|
87
|
+
runResults.endTime = loggerAction.time;
|
|
88
|
+
this.#eventbus.dispatchAction({
|
|
89
|
+
type: "run_complete",
|
|
90
|
+
id,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ("run_error" === loggerAction.type) {
|
|
95
|
+
this.#sessionResults.errors += 1;
|
|
96
|
+
runResults.errors += 1;
|
|
97
|
+
runResults.errorLogs.push(action);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if ("start_collection" === loggerAction.type) {
|
|
101
|
+
runResults.collections[loggerAction.collection_id] = {
|
|
102
|
+
completedModules: 0,
|
|
103
|
+
completedTests: 0,
|
|
104
|
+
errorLogs: [],
|
|
105
|
+
errors: 0,
|
|
106
|
+
expectedModules: loggerAction.expected_module_count,
|
|
107
|
+
expectedTests: 0,
|
|
108
|
+
fails: 0,
|
|
109
|
+
loggerAction,
|
|
110
|
+
modules: [],
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
runResults.expectedModules += loggerAction.expected_module_count;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if ("end_collection" === loggerAction.type) {
|
|
117
|
+
let collection = runResults.collections[loggerAction.collection_id];
|
|
118
|
+
if (!collection) return;
|
|
119
|
+
|
|
120
|
+
runResults.completedCollections += 1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if ("collection_error" === loggerAction.type) {
|
|
124
|
+
let collection = runResults.collections[loggerAction.collection_id];
|
|
125
|
+
if (!collection) return;
|
|
126
|
+
|
|
127
|
+
this.#sessionResults.errors += 1;
|
|
128
|
+
runResults.errors += 1;
|
|
129
|
+
collection.errors += 1;
|
|
130
|
+
|
|
131
|
+
collection.errorLogs.push(loggerAction);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if ("start_module" === loggerAction.type) {
|
|
135
|
+
let collection = runResults.collections[loggerAction.collection_id];
|
|
136
|
+
if (!collection) return;
|
|
137
|
+
|
|
138
|
+
collection.modules[loggerAction.module_id] = {
|
|
139
|
+
completedTests: 0,
|
|
140
|
+
errorLogs: [],
|
|
141
|
+
errors: 0,
|
|
142
|
+
expectedTests: loggerAction.expected_test_count,
|
|
143
|
+
fails: 0,
|
|
144
|
+
loggerAction,
|
|
145
|
+
testResults: [],
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
collection.expectedTests += loggerAction.expected_test_count;
|
|
149
|
+
runResults.expectedTests += loggerAction.expected_test_count;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if ("end_module" === loggerAction.type) {
|
|
153
|
+
let collection = runResults.collections[loggerAction.collection_id];
|
|
154
|
+
if (!collection) return;
|
|
155
|
+
|
|
156
|
+
let module = collection.modules[loggerAction.module_id];
|
|
157
|
+
if (!module) return;
|
|
158
|
+
|
|
159
|
+
runResults.completedModules += 1;
|
|
160
|
+
collection.completedModules += 1;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if ("module_error" === loggerAction.type) {
|
|
164
|
+
let collection = runResults.collections[loggerAction.collection_id];
|
|
165
|
+
if (!collection) return;
|
|
166
|
+
|
|
167
|
+
let module = collection.modules[loggerAction.module_id];
|
|
168
|
+
if (!module) return;
|
|
169
|
+
|
|
170
|
+
this.#sessionResults.errors += 1;
|
|
171
|
+
runResults.errors += 1;
|
|
172
|
+
collection.errors += 1;
|
|
173
|
+
module.errors += 1;
|
|
174
|
+
module.errorLogs.push(loggerAction);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if ("start_test" === loggerAction.type) {
|
|
178
|
+
let collection = runResults.collections[loggerAction.collection_id];
|
|
179
|
+
if (!collection) return;
|
|
180
|
+
|
|
181
|
+
let module = collection.modules[loggerAction.module_id];
|
|
182
|
+
if (!module) return;
|
|
183
|
+
|
|
184
|
+
module.testResults[loggerAction.test_id] = {
|
|
185
|
+
loggerStartAction: loggerAction,
|
|
186
|
+
loggerEndAction: undefined,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if ("end_test" === loggerAction.type) {
|
|
191
|
+
endTest(this.#sessionResults, runResults, loggerAction);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if ("test_error" === loggerAction.type) {
|
|
195
|
+
let collection = runResults.collections[loggerAction.collection_id];
|
|
196
|
+
if (!collection) return;
|
|
197
|
+
|
|
198
|
+
let module = collection.modules[loggerAction.module_id];
|
|
199
|
+
if (!module) return;
|
|
200
|
+
|
|
201
|
+
let testResult = module.testResults[loggerAction.test_id];
|
|
202
|
+
if (!testResult) return;
|
|
203
|
+
|
|
204
|
+
testResult.loggerEndAction = loggerAction;
|
|
205
|
+
this.#sessionResults.errors += 1;
|
|
206
|
+
runResults.errors += 1;
|
|
207
|
+
collection.errors += 1;
|
|
208
|
+
module.errors += 1;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function endTest(
|
|
214
|
+
sessionResults: SessionResults,
|
|
215
|
+
runResults: RunResults,
|
|
216
|
+
loggerAction: EndTest,
|
|
217
|
+
) {
|
|
218
|
+
let collection = runResults.collections[loggerAction.collection_id];
|
|
219
|
+
if (!collection) return;
|
|
220
|
+
|
|
221
|
+
let module = collection.modules[loggerAction.module_id];
|
|
222
|
+
if (!module) return;
|
|
223
|
+
|
|
224
|
+
let testResult = module.testResults[loggerAction.test_id];
|
|
225
|
+
if (!testResult) return;
|
|
226
|
+
|
|
227
|
+
testResult.loggerEndAction = loggerAction;
|
|
228
|
+
runResults.completedTests += 1;
|
|
229
|
+
collection.completedTests += 1;
|
|
230
|
+
module.completedTests += 1;
|
|
231
|
+
|
|
232
|
+
let { assertions } = loggerAction;
|
|
233
|
+
const isAssertionArray = Array.isArray(assertions) && assertions.length;
|
|
234
|
+
// might be worth just sticking with language standard "none" like "" or 0 or false
|
|
235
|
+
const isAssertion = !Array.isArray(assertions) && undefined !== assertions;
|
|
236
|
+
if (isAssertion || isAssertionArray) {
|
|
237
|
+
sessionResults.fails += 1;
|
|
238
|
+
runResults.fails += 1;
|
|
239
|
+
collection.fails += 1;
|
|
240
|
+
module.fails += 1;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
runResults.testTime += Math.max(
|
|
244
|
+
0,
|
|
245
|
+
loggerAction.end_time - loggerAction.start_time,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import * as http from "http";
|
|
4
|
+
import { createConfig } from "./config.js";
|
|
5
|
+
import { Logger } from "./logger.js";
|
|
6
|
+
import { Router } from "./routes.js";
|
|
7
|
+
import { WebDrivers } from "./webdriver.js";
|
|
8
|
+
import { EventBus } from "./eventbus.js";
|
|
9
|
+
|
|
10
|
+
let args = process.argv.slice(2);
|
|
11
|
+
|
|
12
|
+
const config = await createConfig(args);
|
|
13
|
+
if (config instanceof Error) {
|
|
14
|
+
console.log(config);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let eventbus = new EventBus();
|
|
19
|
+
let logger = new Logger(config, eventbus);
|
|
20
|
+
let router = new Router(config, eventbus);
|
|
21
|
+
let webdrivers = new WebDrivers(config, eventbus);
|
|
22
|
+
|
|
23
|
+
// setup server
|
|
24
|
+
let server = http.createServer();
|
|
25
|
+
server.addListener("request", router.route);
|
|
26
|
+
server.addListener("close", function () {
|
|
27
|
+
console.log(logger.results);
|
|
28
|
+
logger.errored || logger.failed ? process.exit(1) : process.exit(0);
|
|
29
|
+
});
|
|
30
|
+
eventbus.addListener("end", function () {
|
|
31
|
+
server.closeAllConnections();
|
|
32
|
+
server.close();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// run server
|
|
36
|
+
let { port, hostname } = config.hostAndPort;
|
|
37
|
+
server.listen({
|
|
38
|
+
port,
|
|
39
|
+
hostname,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// start test run
|
|
43
|
+
config.runAsynchronously ? webdrivers.runAll() : webdrivers.run();
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { LoggerAction } from "../../core/dist/jackrabbit_types.js";
|
|
2
|
+
import type { WebdriverParams } from "./config.js";
|
|
3
|
+
import type { WebdriverActions } from "./eventbus.js";
|
|
4
|
+
|
|
5
|
+
export interface TestResults {
|
|
6
|
+
loggerStartAction: LoggerAction;
|
|
7
|
+
loggerEndAction: LoggerAction | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// remove logger actions
|
|
11
|
+
export interface ModuleResults {
|
|
12
|
+
loggerAction: LoggerAction;
|
|
13
|
+
fails: number;
|
|
14
|
+
errors: number;
|
|
15
|
+
expectedTests: number;
|
|
16
|
+
completedTests: number;
|
|
17
|
+
errorLogs: LoggerAction[];
|
|
18
|
+
testResults: (TestResults | undefined)[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CollectionResults {
|
|
22
|
+
loggerAction: LoggerAction;
|
|
23
|
+
fails: number;
|
|
24
|
+
errors: number;
|
|
25
|
+
expectedTests: number;
|
|
26
|
+
completedTests: number;
|
|
27
|
+
expectedModules: number;
|
|
28
|
+
completedModules: number;
|
|
29
|
+
errorLogs: LoggerAction[];
|
|
30
|
+
modules: (ModuleResults | undefined)[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface RunResults {
|
|
34
|
+
fails: number;
|
|
35
|
+
errors: number;
|
|
36
|
+
startTime: number;
|
|
37
|
+
endTime: number;
|
|
38
|
+
testTime: number;
|
|
39
|
+
expectedTests: number;
|
|
40
|
+
completedTests: number;
|
|
41
|
+
expectedModules: number;
|
|
42
|
+
completedModules: number;
|
|
43
|
+
expectedCollections: number;
|
|
44
|
+
completedCollections: number;
|
|
45
|
+
errorLogs: WebdriverActions[];
|
|
46
|
+
webdriverParams: WebdriverParams;
|
|
47
|
+
collections: (CollectionResults | undefined)[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// track if session started or not
|
|
51
|
+
// if browser never launched
|
|
52
|
+
export interface SessionResults {
|
|
53
|
+
fails: number;
|
|
54
|
+
errors: number;
|
|
55
|
+
runs: Map<string, RunResults>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SessionResults,
|
|
3
|
+
RunResults,
|
|
4
|
+
CollectionResults,
|
|
5
|
+
ModuleResults,
|
|
6
|
+
TestResults,
|
|
7
|
+
} from "./results.js";
|
|
8
|
+
|
|
9
|
+
const SPACE = " ";
|
|
10
|
+
|
|
11
|
+
export function getResultsAsString(sessionResults: SessionResults): string {
|
|
12
|
+
const output: string[] = [];
|
|
13
|
+
|
|
14
|
+
// Lots of nested loops because results a nested structure.
|
|
15
|
+
// I'd rather see composition nested in one function
|
|
16
|
+
// than have for loops spread across each function.
|
|
17
|
+
|
|
18
|
+
logSessionErrors(output, sessionResults);
|
|
19
|
+
|
|
20
|
+
for (let [, result] of sessionResults.runs) {
|
|
21
|
+
if (logRunResults(output, result)) continue;
|
|
22
|
+
|
|
23
|
+
for (const collection of result.collections) {
|
|
24
|
+
if (logCollectionResult(output, collection)) continue;
|
|
25
|
+
|
|
26
|
+
if (collection)
|
|
27
|
+
for (const moduleResult of collection.modules) {
|
|
28
|
+
if (logModuleResult(output, moduleResult)) continue;
|
|
29
|
+
|
|
30
|
+
if (moduleResult)
|
|
31
|
+
for (const testResult of moduleResult.testResults) {
|
|
32
|
+
logTest(output, testResult);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
logSummary(output, sessionResults);
|
|
39
|
+
|
|
40
|
+
return output.join("\n");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function logSessionErrors(output: string[], sessionResults: SessionResults) {
|
|
44
|
+
for (let [, result] of sessionResults.runs) {
|
|
45
|
+
for (let errorAction of result.errorLogs) {
|
|
46
|
+
if ("session_error" === errorAction.type) {
|
|
47
|
+
output.push(
|
|
48
|
+
`\n[${result.webdriverParams.title}:session_error] ${errorAction.error}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function logRunResults(output: string[], result: RunResults): boolean {
|
|
56
|
+
output.push(`
|
|
57
|
+
${result.webdriverParams.title}`);
|
|
58
|
+
|
|
59
|
+
for (let errorAction of result.errorLogs) {
|
|
60
|
+
if ("log" === errorAction.type) {
|
|
61
|
+
if ("run_error" === errorAction.loggerAction.type) {
|
|
62
|
+
output.push(`${SPACE}[run_error] ${errorAction.loggerAction.error}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!result.expectedTests) {
|
|
68
|
+
output.push(` No test runs occured.`);
|
|
69
|
+
}
|
|
70
|
+
// When everything goes right :3
|
|
71
|
+
if (
|
|
72
|
+
!result.fails &&
|
|
73
|
+
!result.errors &&
|
|
74
|
+
result.expectedTests === result.completedTests &&
|
|
75
|
+
result.expectedModules === result.completedModules &&
|
|
76
|
+
result.expectedCollections === result.completedCollections
|
|
77
|
+
) {
|
|
78
|
+
output.push(`${SPACE}${result.completedTests} tests
|
|
79
|
+
${SPACE}${result.completedModules} modules
|
|
80
|
+
${SPACE}${result.completedCollections} collections`);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function logCollectionResult(
|
|
88
|
+
output: string[],
|
|
89
|
+
collection: CollectionResults | undefined,
|
|
90
|
+
): boolean {
|
|
91
|
+
if (!collection) return true;
|
|
92
|
+
|
|
93
|
+
let { loggerAction } = collection;
|
|
94
|
+
if ("start_collection" !== loggerAction.type) return true;
|
|
95
|
+
|
|
96
|
+
output.push(`${SPACE}${loggerAction.collection_url}`);
|
|
97
|
+
|
|
98
|
+
// when everything in the collection goes right
|
|
99
|
+
if (
|
|
100
|
+
!collection.fails &&
|
|
101
|
+
!collection.errors &&
|
|
102
|
+
collection.expectedTests === collection.completedTests &&
|
|
103
|
+
collection.expectedModules === collection.completedModules
|
|
104
|
+
) {
|
|
105
|
+
output.push(
|
|
106
|
+
`${SPACE.repeat(2)}${collection.expectedTests} tests
|
|
107
|
+
${SPACE.repeat(2)}${loggerAction.expected_module_count} modules`,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (let errorAction of collection.errorLogs) {
|
|
114
|
+
if ("collection_error" !== errorAction.type) continue;
|
|
115
|
+
output.push(`${SPACE.repeat(2)}[collection_error] ${errorAction.error}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function logModuleResult(
|
|
122
|
+
output: string[],
|
|
123
|
+
module: ModuleResults | undefined,
|
|
124
|
+
): boolean {
|
|
125
|
+
if (!module) return true;
|
|
126
|
+
|
|
127
|
+
let { loggerAction } = module;
|
|
128
|
+
if ("start_module" !== loggerAction.type) return true;
|
|
129
|
+
|
|
130
|
+
output.push(`${SPACE.repeat(2)}${loggerAction.module_name}`);
|
|
131
|
+
|
|
132
|
+
// when everything in the module goes right
|
|
133
|
+
if (
|
|
134
|
+
!module.fails &&
|
|
135
|
+
!module.errors &&
|
|
136
|
+
module.expectedTests === module.completedTests
|
|
137
|
+
) {
|
|
138
|
+
output.push(`${SPACE.repeat(3)}${module.expectedTests} tests`);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
for (let errorAction of module.errorLogs) {
|
|
143
|
+
if ("collection_error" !== errorAction.type) continue;
|
|
144
|
+
output.push(`${SPACE.repeat(2)}[module_error] ${errorAction.error}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function logTest(output: string[], test: TestResults | undefined) {
|
|
151
|
+
if (!test) return;
|
|
152
|
+
|
|
153
|
+
let { loggerStartAction, loggerEndAction } = test;
|
|
154
|
+
if ("start_test" !== loggerStartAction.type) return;
|
|
155
|
+
|
|
156
|
+
if ("test_error" === loggerEndAction?.type) {
|
|
157
|
+
let { test_name } = loggerStartAction;
|
|
158
|
+
output.push(
|
|
159
|
+
`${SPACE.repeat(3)}${test_name}
|
|
160
|
+
${SPACE.repeat(4)}[error] ${loggerEndAction.error}`,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if ("end_test" === loggerEndAction?.type) {
|
|
165
|
+
let { assertions } = loggerEndAction;
|
|
166
|
+
const isAssertionArray = Array.isArray(assertions) && assertions.length;
|
|
167
|
+
const isAssertion =
|
|
168
|
+
!Array.isArray(assertions) &&
|
|
169
|
+
undefined !== assertions &&
|
|
170
|
+
null !== assertions;
|
|
171
|
+
|
|
172
|
+
if (isAssertion || isAssertionArray) {
|
|
173
|
+
let { test_name } = loggerStartAction;
|
|
174
|
+
output.push(`${SPACE.repeat(3)}${test_name}`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (isAssertion) {
|
|
178
|
+
output.push(`${SPACE.repeat(4)}- ${assertions}`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (isAssertionArray) {
|
|
182
|
+
for (const assertion of assertions) {
|
|
183
|
+
output.push(`${SPACE.repeat(4)}- ${assertion}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function logSummary(output: string[], sessionResults: SessionResults) {
|
|
190
|
+
let status_with_color = blue("\u{2714} passed");
|
|
191
|
+
if (sessionResults.fails) status_with_color = yellow("\u{2717} failed");
|
|
192
|
+
if (sessionResults.errors) status_with_color = gray("\u{2717} errored");
|
|
193
|
+
|
|
194
|
+
// expected tests
|
|
195
|
+
|
|
196
|
+
let totalTime = 0;
|
|
197
|
+
let testTime = 0;
|
|
198
|
+
for (let [, run] of sessionResults.runs) {
|
|
199
|
+
totalTime += run.endTime - run.startTime;
|
|
200
|
+
testTime += run.testTime;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
output.push(`
|
|
204
|
+
${status_with_color}
|
|
205
|
+
duration: ${testTime.toFixed(4)} mS
|
|
206
|
+
total: ${totalTime.toFixed(4)} mS
|
|
207
|
+
`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 39 - default foreground color
|
|
211
|
+
// 49 - default background color
|
|
212
|
+
function blue(text: string) {
|
|
213
|
+
return `\x1b[44m\x1b[97m${text}\x1b[0m`;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function yellow(text: string) {
|
|
217
|
+
return `\x1b[43m\x1b[97m${text}\x1b[0m`;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function gray(text: string) {
|
|
221
|
+
return `\x1b[100m\x1b[97m${text}\x1b[0m`;
|
|
222
|
+
}
|