@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.
- 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 +42 -0
- package/README.md +151 -8
- 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 +62 -28
- 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 +73 -29
- 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/{cli → nodejs}/tsconfig.json +2 -1
- package/nodejs/tsconfig.tsbuildinfo +1 -0
- package/package.json +9 -6
- 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/{nodejs_cli → webdriver}/tsconfig.json +1 -0
- package/webdriver/tsconfig.tsbuildinfo +1 -0
- package/.github/workflows/build_and_test.yml +0 -18
- 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 -27
- 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 -36
- 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/test_guide.md +0 -114
- /package/{nodejs_cli → nodejs}/package.json +0 -0
- /package/{cli/dist/cli_types.js → webdriver/dist/results.js} +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
const SPACE = " ";
|
|
2
|
+
export function getResultsAsString(runResults) {
|
|
3
|
+
const output = [];
|
|
4
|
+
for (let errorAction of runResults.errorLogs) {
|
|
5
|
+
if ("run_error" !== errorAction.type)
|
|
6
|
+
continue;
|
|
7
|
+
output.push(`${SPACE}[session_error]\n${errorAction.error}`);
|
|
8
|
+
}
|
|
9
|
+
// Lots of nested loops because results a nested structure.
|
|
10
|
+
// I'd rather see composition nested in one function
|
|
11
|
+
// than have for loops spread across each function.
|
|
12
|
+
if (!logRunResults(output, runResults))
|
|
13
|
+
for (const collection of runResults.collections) {
|
|
14
|
+
if (logCollectionResult(output, collection))
|
|
15
|
+
continue;
|
|
16
|
+
if (collection)
|
|
17
|
+
for (const moduleResult of collection.modules) {
|
|
18
|
+
if (logModuleResult(output, moduleResult))
|
|
19
|
+
continue;
|
|
20
|
+
if (moduleResult)
|
|
21
|
+
for (const testResult of moduleResult.testResults) {
|
|
22
|
+
logTest(output, testResult);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
logSummary(output, runResults);
|
|
27
|
+
return output.join("\n");
|
|
28
|
+
}
|
|
29
|
+
function logRunResults(output, result) {
|
|
30
|
+
// When everything goes right :3
|
|
31
|
+
if (!result.fails &&
|
|
32
|
+
!result.errors &&
|
|
33
|
+
result.expectedTests === result.completedTests &&
|
|
34
|
+
result.expectedModules === result.completedModules &&
|
|
35
|
+
result.expectedCollections === result.completedCollections) {
|
|
36
|
+
output.push(`${result.completedTests} tests
|
|
37
|
+
${result.completedModules} modules
|
|
38
|
+
${result.completedCollections} collections`);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
for (let errorAction of result.errorLogs) {
|
|
42
|
+
if ("run_error" !== errorAction.type)
|
|
43
|
+
continue;
|
|
44
|
+
output.push(`[run_error] ${errorAction.error}`);
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
function logCollectionResult(output, collection) {
|
|
49
|
+
if (!collection)
|
|
50
|
+
return true;
|
|
51
|
+
let { loggerAction } = collection;
|
|
52
|
+
if ("start_collection" !== loggerAction.type)
|
|
53
|
+
return true;
|
|
54
|
+
output.push(`${SPACE}${loggerAction.collection_url}`);
|
|
55
|
+
// when everything in the collection goes right
|
|
56
|
+
if (!collection.fails &&
|
|
57
|
+
!collection.errors &&
|
|
58
|
+
collection.expectedTests === collection.completedTests &&
|
|
59
|
+
collection.expectedModules === collection.completedModules) {
|
|
60
|
+
output.push(`${collection.expectedTests} tests
|
|
61
|
+
${loggerAction.expected_module_count} modules`);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
for (let errorAction of collection.errorLogs) {
|
|
65
|
+
if ("collection_error" !== errorAction.type)
|
|
66
|
+
continue;
|
|
67
|
+
output.push(`[collection_error] ${errorAction.error}`);
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
function logModuleResult(output, module) {
|
|
72
|
+
if (!module)
|
|
73
|
+
return true;
|
|
74
|
+
let { loggerAction } = module;
|
|
75
|
+
if ("start_module" !== loggerAction.type)
|
|
76
|
+
return true;
|
|
77
|
+
output.push(`${SPACE}${loggerAction.module_name}`);
|
|
78
|
+
// when everything in the module goes right
|
|
79
|
+
if (!module.fails &&
|
|
80
|
+
!module.errors &&
|
|
81
|
+
module.expectedTests === module.completedTests) {
|
|
82
|
+
output.push(`${SPACE.repeat(2)}${module.expectedTests} tests`);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
for (let errorAction of module.errorLogs) {
|
|
86
|
+
if ("collection_error" !== errorAction.type)
|
|
87
|
+
continue;
|
|
88
|
+
output.push(`${SPACE}[module_error] ${errorAction.error}`);
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
function logTest(output, test) {
|
|
93
|
+
if (!test)
|
|
94
|
+
return;
|
|
95
|
+
let { loggerStartAction, loggerEndAction } = test;
|
|
96
|
+
if ("start_test" !== loggerStartAction.type)
|
|
97
|
+
return;
|
|
98
|
+
if ("test_error" === loggerEndAction?.type) {
|
|
99
|
+
let { test_name } = loggerStartAction;
|
|
100
|
+
output.push(`${SPACE.repeat(2)}${test_name}
|
|
101
|
+
${SPACE.repeat(3)}[error] ${loggerEndAction.error}`);
|
|
102
|
+
}
|
|
103
|
+
if ("end_test" === loggerEndAction?.type) {
|
|
104
|
+
let { assertions } = loggerEndAction;
|
|
105
|
+
const isAssertionArray = Array.isArray(assertions) && assertions.length;
|
|
106
|
+
const isAssertion = !Array.isArray(assertions) &&
|
|
107
|
+
undefined !== assertions &&
|
|
108
|
+
null !== assertions;
|
|
109
|
+
if (isAssertion || isAssertionArray) {
|
|
110
|
+
let { test_name } = loggerStartAction;
|
|
111
|
+
output.push(`${SPACE.repeat(2)}${test_name}`);
|
|
112
|
+
}
|
|
113
|
+
if (isAssertion) {
|
|
114
|
+
output.push(`${SPACE.repeat(3)}- ${assertions}`);
|
|
115
|
+
}
|
|
116
|
+
if (isAssertionArray) {
|
|
117
|
+
for (const assertion of assertions) {
|
|
118
|
+
output.push(`${SPACE.repeat(3)}- ${assertion}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function logSummary(output, runResults) {
|
|
124
|
+
let status_with_color = runResults.fails
|
|
125
|
+
? yellow("\u{2717} failed")
|
|
126
|
+
: blue("\u{2714} passed");
|
|
127
|
+
if (runResults.errors) {
|
|
128
|
+
status_with_color = gray("\u{2717} errored");
|
|
129
|
+
}
|
|
130
|
+
let totalTime = runResults.endTime - runResults.startTime;
|
|
131
|
+
output.push(`
|
|
132
|
+
${status_with_color}
|
|
133
|
+
duration: ${runResults.testTime.toFixed(4)} mS
|
|
134
|
+
total: ${totalTime.toFixed(4)} mS
|
|
135
|
+
`);
|
|
136
|
+
}
|
|
137
|
+
// 39 - default foreground color
|
|
138
|
+
// 49 - default background color
|
|
139
|
+
function blue(text) {
|
|
140
|
+
return `\x1b[44m\x1b[97m${text}\x1b[0m`;
|
|
141
|
+
}
|
|
142
|
+
function yellow(text) {
|
|
143
|
+
return `\x1b[43m\x1b[97m${text}\x1b[0m`;
|
|
144
|
+
}
|
|
145
|
+
function gray(text) {
|
|
146
|
+
return `\x1b[100m\x1b[97m${text}\x1b[0m`;
|
|
147
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import { startRun } from "../../core/dist/mod.js";
|
|
3
|
+
export async function run(logger, files) {
|
|
4
|
+
for (const file of files) {
|
|
5
|
+
let filepath = path.join(process.cwd(), file);
|
|
6
|
+
try {
|
|
7
|
+
const { testModules } = await import(filepath);
|
|
8
|
+
await startRun(logger, testModules);
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
logger.log({
|
|
12
|
+
type: "run_error",
|
|
13
|
+
error: e?.toString() ?? "wild horses error",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
LoggerAction,
|
|
3
|
+
LoggerInterface,
|
|
4
|
+
EndTest,
|
|
5
|
+
} from "../../core/dist/mod.js";
|
|
6
|
+
import type { RunResults } from "./results_str.js";
|
|
7
|
+
|
|
8
|
+
import { getResultsAsString } from "./results_str.js";
|
|
9
|
+
|
|
10
|
+
export class Logger implements LoggerInterface {
|
|
11
|
+
#results: RunResults = {
|
|
12
|
+
startTime: 0,
|
|
13
|
+
fails: 0,
|
|
14
|
+
errors: 0,
|
|
15
|
+
expectedTests: 0,
|
|
16
|
+
endTime: 0,
|
|
17
|
+
testTime: 0,
|
|
18
|
+
expectedModules: 0,
|
|
19
|
+
expectedCollections: 0,
|
|
20
|
+
completedModules: 0,
|
|
21
|
+
completedCollections: 0,
|
|
22
|
+
completedTests: 0,
|
|
23
|
+
errorLogs: [],
|
|
24
|
+
collections: [],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
get failed() {
|
|
28
|
+
return this.#results.fails !== 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get errored() {
|
|
32
|
+
return this.#results.errors !== 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get results(): string {
|
|
36
|
+
return getResultsAsString(this.#results);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
log(action: LoggerAction) {
|
|
40
|
+
if ("start_run" === action.type) {
|
|
41
|
+
this.#results.startTime = action.time;
|
|
42
|
+
this.#results.expectedCollections = action.expected_collection_count;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if ("end_run" === action.type) {
|
|
46
|
+
this.#results.endTime = action.time;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if ("run_error" === action.type) {
|
|
50
|
+
this.#results.errors += 1;
|
|
51
|
+
this.#results.errorLogs.push(action);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if ("start_collection" === action.type) {
|
|
55
|
+
this.#results.collections[action.collection_id] = {
|
|
56
|
+
completedModules: 0,
|
|
57
|
+
completedTests: 0,
|
|
58
|
+
errorLogs: [],
|
|
59
|
+
errors: 0,
|
|
60
|
+
expectedModules: action.expected_module_count,
|
|
61
|
+
expectedTests: 0,
|
|
62
|
+
fails: 0,
|
|
63
|
+
loggerAction: action,
|
|
64
|
+
modules: [],
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
this.#results.expectedModules += action.expected_module_count;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if ("end_collection" === action.type) {
|
|
71
|
+
let collection = this.#results.collections[action.collection_id];
|
|
72
|
+
if (!collection) return;
|
|
73
|
+
|
|
74
|
+
this.#results.completedCollections += 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if ("collection_error" === action.type) {
|
|
78
|
+
let collection = this.#results.collections[action.collection_id];
|
|
79
|
+
if (!collection) return;
|
|
80
|
+
|
|
81
|
+
this.#results.errors += 1;
|
|
82
|
+
collection.errors += 1;
|
|
83
|
+
|
|
84
|
+
collection.errorLogs.push(action);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if ("start_module" === action.type) {
|
|
88
|
+
let collection = this.#results.collections[action.collection_id];
|
|
89
|
+
if (!collection) return;
|
|
90
|
+
|
|
91
|
+
collection.modules[action.module_id] = {
|
|
92
|
+
completedTests: 0,
|
|
93
|
+
errorLogs: [],
|
|
94
|
+
errors: 0,
|
|
95
|
+
expectedTests: action.expected_test_count,
|
|
96
|
+
fails: 0,
|
|
97
|
+
loggerAction: action,
|
|
98
|
+
testResults: [],
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
collection.expectedTests += action.expected_test_count;
|
|
102
|
+
this.#results.expectedTests += action.expected_test_count;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if ("end_module" === action.type) {
|
|
106
|
+
let collection = this.#results.collections[action.collection_id];
|
|
107
|
+
if (!collection) return;
|
|
108
|
+
|
|
109
|
+
let module = collection.modules[action.module_id];
|
|
110
|
+
if (!module) return;
|
|
111
|
+
|
|
112
|
+
this.#results.completedModules += 1;
|
|
113
|
+
collection.completedModules += 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if ("module_error" === action.type) {
|
|
117
|
+
let collection = this.#results.collections[action.collection_id];
|
|
118
|
+
if (!collection) return;
|
|
119
|
+
|
|
120
|
+
let module = collection.modules[action.module_id];
|
|
121
|
+
if (!module) return;
|
|
122
|
+
|
|
123
|
+
this.#results.errors += 1;
|
|
124
|
+
collection.errors += 1;
|
|
125
|
+
module.errors += 1;
|
|
126
|
+
module.errorLogs.push(action);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if ("start_test" === action.type) {
|
|
130
|
+
let collection = this.#results.collections[action.collection_id];
|
|
131
|
+
if (!collection) return;
|
|
132
|
+
|
|
133
|
+
let module = collection.modules[action.module_id];
|
|
134
|
+
if (!module) return;
|
|
135
|
+
|
|
136
|
+
module.testResults[action.test_id] = {
|
|
137
|
+
loggerStartAction: action,
|
|
138
|
+
loggerEndAction: undefined,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if ("end_test" === action.type) {
|
|
143
|
+
endTest(this.#results, action);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if ("test_error" === action.type) {
|
|
147
|
+
let collection = this.#results.collections[action.collection_id];
|
|
148
|
+
if (!collection) return;
|
|
149
|
+
|
|
150
|
+
let module = collection.modules[action.module_id];
|
|
151
|
+
if (!module) return;
|
|
152
|
+
|
|
153
|
+
let testResult = module.testResults[action.test_id];
|
|
154
|
+
if (!testResult) return;
|
|
155
|
+
|
|
156
|
+
testResult.loggerEndAction = action;
|
|
157
|
+
this.#results.errors += 1;
|
|
158
|
+
collection.errors += 1;
|
|
159
|
+
module.errors += 1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function endTest(runResults: RunResults, loggerAction: EndTest) {
|
|
165
|
+
let collection = runResults.collections[loggerAction.collection_id];
|
|
166
|
+
if (!collection) return;
|
|
167
|
+
|
|
168
|
+
let module = collection.modules[loggerAction.module_id];
|
|
169
|
+
if (!module) return;
|
|
170
|
+
|
|
171
|
+
let testResult = module.testResults[loggerAction.test_id];
|
|
172
|
+
if (!testResult) return;
|
|
173
|
+
|
|
174
|
+
testResult.loggerEndAction = loggerAction;
|
|
175
|
+
runResults.completedTests += 1;
|
|
176
|
+
collection.completedTests += 1;
|
|
177
|
+
module.completedTests += 1;
|
|
178
|
+
|
|
179
|
+
let { assertions } = loggerAction;
|
|
180
|
+
const isAssertionArray = Array.isArray(assertions) && assertions.length;
|
|
181
|
+
// might be worth just sticking with language standard "none" like "" or 0 or false
|
|
182
|
+
const isAssertion = !Array.isArray(assertions) && undefined !== assertions;
|
|
183
|
+
if (isAssertion || isAssertionArray) {
|
|
184
|
+
runResults.fails += 1;
|
|
185
|
+
collection.fails += 1;
|
|
186
|
+
module.fails += 1;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
runResults.testTime += Math.max(
|
|
190
|
+
0,
|
|
191
|
+
loggerAction.end_time - loggerAction.start_time,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Logger } from "./logger.js";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
import { runCollection } from "../../core/dist/mod.js";
|
|
6
|
+
|
|
7
|
+
let filepaths = process.argv.slice(2);
|
|
8
|
+
|
|
9
|
+
const logger = new Logger();
|
|
10
|
+
|
|
11
|
+
logger.log({
|
|
12
|
+
type: "start_run",
|
|
13
|
+
time: performance.now(),
|
|
14
|
+
expected_collection_count: filepaths.length,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
for (const [collection_id, file] of filepaths.entries()) {
|
|
18
|
+
try {
|
|
19
|
+
let filepath = path.join(process.cwd(), file);
|
|
20
|
+
const { testModules } = await import(filepath);
|
|
21
|
+
await runCollection(logger, testModules, collection_id, filepath);
|
|
22
|
+
} catch (e: unknown) {
|
|
23
|
+
logger.log({
|
|
24
|
+
type: "collection_error",
|
|
25
|
+
collection_id,
|
|
26
|
+
error: e?.toString() ?? "wild horses error",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
logger.log({
|
|
32
|
+
type: "end_run",
|
|
33
|
+
time: performance.now(),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log(logger.results);
|
|
37
|
+
logger.failed || logger.errored ? process.exit(1) : process.exit(0);
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { LoggerAction } from "../../core/dist/mod.js";
|
|
2
|
+
|
|
3
|
+
export interface TestResults {
|
|
4
|
+
loggerStartAction: LoggerAction;
|
|
5
|
+
loggerEndAction: LoggerAction | undefined;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ModuleResults {
|
|
9
|
+
loggerAction: LoggerAction;
|
|
10
|
+
fails: number;
|
|
11
|
+
errors: number;
|
|
12
|
+
expectedTests: number;
|
|
13
|
+
completedTests: number;
|
|
14
|
+
errorLogs: LoggerAction[];
|
|
15
|
+
testResults: (TestResults | undefined)[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CollectionResults {
|
|
19
|
+
loggerAction: LoggerAction;
|
|
20
|
+
fails: number;
|
|
21
|
+
errors: number;
|
|
22
|
+
expectedTests: number;
|
|
23
|
+
completedTests: number;
|
|
24
|
+
expectedModules: number;
|
|
25
|
+
completedModules: number;
|
|
26
|
+
errorLogs: LoggerAction[];
|
|
27
|
+
modules: (ModuleResults | undefined)[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RunResults {
|
|
31
|
+
fails: number;
|
|
32
|
+
errors: number;
|
|
33
|
+
startTime: number;
|
|
34
|
+
endTime: number;
|
|
35
|
+
testTime: number;
|
|
36
|
+
expectedTests: number;
|
|
37
|
+
completedTests: number;
|
|
38
|
+
expectedModules: number;
|
|
39
|
+
completedModules: number;
|
|
40
|
+
expectedCollections: number;
|
|
41
|
+
completedCollections: number;
|
|
42
|
+
errorLogs: LoggerAction[];
|
|
43
|
+
collections: (CollectionResults | undefined)[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const SPACE = " ";
|
|
47
|
+
|
|
48
|
+
export function getResultsAsString(runResults: RunResults): string {
|
|
49
|
+
const output: string[] = [];
|
|
50
|
+
|
|
51
|
+
for (let errorAction of runResults.errorLogs) {
|
|
52
|
+
if ("run_error" !== errorAction.type) continue;
|
|
53
|
+
output.push(`${SPACE}[session_error]\n${errorAction.error}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Lots of nested loops because results a nested structure.
|
|
57
|
+
// I'd rather see composition nested in one function
|
|
58
|
+
// than have for loops spread across each function.
|
|
59
|
+
|
|
60
|
+
if (!logRunResults(output, runResults))
|
|
61
|
+
for (const collection of runResults.collections) {
|
|
62
|
+
if (logCollectionResult(output, collection)) continue;
|
|
63
|
+
|
|
64
|
+
if (collection)
|
|
65
|
+
for (const moduleResult of collection.modules) {
|
|
66
|
+
if (logModuleResult(output, moduleResult)) continue;
|
|
67
|
+
|
|
68
|
+
if (moduleResult)
|
|
69
|
+
for (const testResult of moduleResult.testResults) {
|
|
70
|
+
logTest(output, testResult);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
logSummary(output, runResults);
|
|
76
|
+
|
|
77
|
+
return output.join("\n");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function logRunResults(output: string[], result: RunResults): boolean {
|
|
81
|
+
// When everything goes right :3
|
|
82
|
+
if (
|
|
83
|
+
!result.fails &&
|
|
84
|
+
!result.errors &&
|
|
85
|
+
result.expectedTests === result.completedTests &&
|
|
86
|
+
result.expectedModules === result.completedModules &&
|
|
87
|
+
result.expectedCollections === result.completedCollections
|
|
88
|
+
) {
|
|
89
|
+
output.push(`${result.completedTests} tests
|
|
90
|
+
${result.completedModules} modules
|
|
91
|
+
${result.completedCollections} collections`);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (let errorAction of result.errorLogs) {
|
|
96
|
+
if ("run_error" !== errorAction.type) continue;
|
|
97
|
+
output.push(`[run_error] ${errorAction.error}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function logCollectionResult(
|
|
104
|
+
output: string[],
|
|
105
|
+
collection: CollectionResults | undefined,
|
|
106
|
+
): boolean {
|
|
107
|
+
if (!collection) return true;
|
|
108
|
+
|
|
109
|
+
let { loggerAction } = collection;
|
|
110
|
+
if ("start_collection" !== loggerAction.type) return true;
|
|
111
|
+
|
|
112
|
+
output.push(`${SPACE}${loggerAction.collection_url}`);
|
|
113
|
+
|
|
114
|
+
// when everything in the collection goes right
|
|
115
|
+
if (
|
|
116
|
+
!collection.fails &&
|
|
117
|
+
!collection.errors &&
|
|
118
|
+
collection.expectedTests === collection.completedTests &&
|
|
119
|
+
collection.expectedModules === collection.completedModules
|
|
120
|
+
) {
|
|
121
|
+
output.push(
|
|
122
|
+
`${collection.expectedTests} tests
|
|
123
|
+
${loggerAction.expected_module_count} modules`,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (let errorAction of collection.errorLogs) {
|
|
130
|
+
if ("collection_error" !== errorAction.type) continue;
|
|
131
|
+
output.push(`[collection_error] ${errorAction.error}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function logModuleResult(
|
|
138
|
+
output: string[],
|
|
139
|
+
module: ModuleResults | undefined,
|
|
140
|
+
): boolean {
|
|
141
|
+
if (!module) return true;
|
|
142
|
+
|
|
143
|
+
let { loggerAction } = module;
|
|
144
|
+
if ("start_module" !== loggerAction.type) return true;
|
|
145
|
+
|
|
146
|
+
output.push(`${SPACE}${loggerAction.module_name}`);
|
|
147
|
+
|
|
148
|
+
// when everything in the module goes right
|
|
149
|
+
if (
|
|
150
|
+
!module.fails &&
|
|
151
|
+
!module.errors &&
|
|
152
|
+
module.expectedTests === module.completedTests
|
|
153
|
+
) {
|
|
154
|
+
output.push(`${SPACE.repeat(2)}${module.expectedTests} tests`);
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
for (let errorAction of module.errorLogs) {
|
|
159
|
+
if ("collection_error" !== errorAction.type) continue;
|
|
160
|
+
output.push(`${SPACE}[module_error] ${errorAction.error}`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function logTest(output: string[], test: TestResults | undefined) {
|
|
167
|
+
if (!test) return;
|
|
168
|
+
|
|
169
|
+
let { loggerStartAction, loggerEndAction } = test;
|
|
170
|
+
if ("start_test" !== loggerStartAction.type) return;
|
|
171
|
+
|
|
172
|
+
if ("test_error" === loggerEndAction?.type) {
|
|
173
|
+
let { test_name } = loggerStartAction;
|
|
174
|
+
output.push(
|
|
175
|
+
`${SPACE.repeat(2)}${test_name}
|
|
176
|
+
${SPACE.repeat(3)}[error] ${loggerEndAction.error}`,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if ("end_test" === loggerEndAction?.type) {
|
|
181
|
+
let { assertions } = loggerEndAction;
|
|
182
|
+
const isAssertionArray = Array.isArray(assertions) && assertions.length;
|
|
183
|
+
const isAssertion =
|
|
184
|
+
!Array.isArray(assertions) &&
|
|
185
|
+
undefined !== assertions &&
|
|
186
|
+
null !== assertions;
|
|
187
|
+
|
|
188
|
+
if (isAssertion || isAssertionArray) {
|
|
189
|
+
let { test_name } = loggerStartAction;
|
|
190
|
+
output.push(`${SPACE.repeat(2)}${test_name}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (isAssertion) {
|
|
194
|
+
output.push(`${SPACE.repeat(3)}- ${assertions}`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (isAssertionArray) {
|
|
198
|
+
for (const assertion of assertions) {
|
|
199
|
+
output.push(`${SPACE.repeat(3)}- ${assertion}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function logSummary(output: string[], runResults: RunResults) {
|
|
206
|
+
let status_with_color = runResults.fails
|
|
207
|
+
? yellow("\u{2717} failed")
|
|
208
|
+
: blue("\u{2714} passed");
|
|
209
|
+
|
|
210
|
+
if (runResults.errors) {
|
|
211
|
+
status_with_color = gray("\u{2717} errored");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let totalTime = runResults.endTime - runResults.startTime;
|
|
215
|
+
output.push(`
|
|
216
|
+
${status_with_color}
|
|
217
|
+
duration: ${runResults.testTime.toFixed(4)} mS
|
|
218
|
+
total: ${totalTime.toFixed(4)} mS
|
|
219
|
+
`);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// 39 - default foreground color
|
|
223
|
+
// 49 - default background color
|
|
224
|
+
function blue(text: string) {
|
|
225
|
+
return `\x1b[44m\x1b[97m${text}\x1b[0m`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function yellow(text: string) {
|
|
229
|
+
return `\x1b[43m\x1b[97m${text}\x1b[0m`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function gray(text: string) {
|
|
233
|
+
return `\x1b[100m\x1b[97m${text}\x1b[0m`;
|
|
234
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/logger.ts","./src/mod.ts","./src/results_str.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w-lfpup/jackrabbit",
|
|
3
3
|
"description": "A test runner without dependencies",
|
|
4
|
+
"version": "0.3.0",
|
|
5
|
+
"license": "BSD-3-Clause",
|
|
4
6
|
"workspaces": [
|
|
5
7
|
"core",
|
|
6
8
|
"tests",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
+
"nodejs",
|
|
10
|
+
"browser",
|
|
11
|
+
"webdriver"
|
|
9
12
|
],
|
|
10
13
|
"bin": {
|
|
11
|
-
"jackrabbit": "
|
|
14
|
+
"jackrabbit": "nodejs/dist/mod.js",
|
|
15
|
+
"jackrabbit_webdriver": "webdriver/dist/mod.js"
|
|
12
16
|
},
|
|
13
17
|
"scripts": {
|
|
14
18
|
"prepare": "npm run build",
|
|
15
19
|
"build": "npm run --workspaces build",
|
|
16
20
|
"format": "npx prettier --write ./",
|
|
17
|
-
"test": "npx jackrabbit
|
|
21
|
+
"test": "npx jackrabbit ./tests/dist/mod.js"
|
|
18
22
|
},
|
|
19
|
-
"version": "0.1.0",
|
|
20
23
|
"repository": {
|
|
21
24
|
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/w-lfpup/
|
|
25
|
+
"url": "git+https://github.com/w-lfpup/jackrabbit-js.git"
|
|
23
26
|
},
|
|
24
27
|
"devDependencies": {
|
|
25
28
|
"@types/node": "^22.5.5",
|
package/tests/dist/mod.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
declare function testsFail(): Promise<"fail tests failed to fail" | undefined>;
|
|
2
2
|
declare function testsPass(): Promise<"passing tests failed to pass" | undefined>;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
declare function testsError(): Promise<"tests failed to error" | "tests should error not fail" | undefined>;
|
|
4
|
+
export declare const testModules: ({
|
|
5
|
+
tests: (typeof testsFail)[];
|
|
5
6
|
options: {
|
|
6
7
|
title: string;
|
|
7
8
|
};
|
|
8
|
-
}
|
|
9
|
+
} | {
|
|
10
|
+
tests: (typeof testsPass)[];
|
|
11
|
+
options: {
|
|
12
|
+
title: string;
|
|
13
|
+
};
|
|
14
|
+
} | {
|
|
15
|
+
tests: (typeof testsError)[];
|
|
16
|
+
options: {
|
|
17
|
+
title: string;
|
|
18
|
+
};
|
|
19
|
+
})[];
|
|
9
20
|
export {};
|