ortoni-report 4.0.1-beta.3 → 4.0.1
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/changelog.md +17 -0
- package/dist/cli.js +27 -25
- package/dist/cli.mjs +27 -25
- package/dist/index.html +2 -2
- package/dist/ortoni-report.js +2 -2
- package/dist/ortoni-report.mjs +2 -2
- package/package.json +1 -1
- package/readme.md +56 -75
- package/dist/chunk-HOOC3MDY.mjs +0 -632
- package/dist/chunk-ISCRDMPY.mjs +0 -693
- package/dist/chunk-P72FKFLZ.mjs +0 -692
- package/dist/chunk-S45BZGXX.mjs +0 -744
- package/dist/chunk-ZG4JPYLC.mjs +0 -692
- package/dist/chunk-ZSPTPISU.mjs +0 -692
package/dist/chunk-ZSPTPISU.mjs
DELETED
|
@@ -1,692 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
-
}) : x)(function(x) {
|
|
6
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
-
});
|
|
9
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
-
|
|
11
|
-
// src/utils/utils.ts
|
|
12
|
-
import path from "path";
|
|
13
|
-
function normalizeFilePath(filePath) {
|
|
14
|
-
const normalizedPath = path.normalize(filePath);
|
|
15
|
-
return path.basename(normalizedPath);
|
|
16
|
-
}
|
|
17
|
-
function ensureHtmlExtension(filename) {
|
|
18
|
-
const ext = path.extname(filename);
|
|
19
|
-
if (ext && ext.toLowerCase() === ".html") {
|
|
20
|
-
return filename;
|
|
21
|
-
}
|
|
22
|
-
return `${filename}.html`;
|
|
23
|
-
}
|
|
24
|
-
function escapeHtml(unsafe) {
|
|
25
|
-
if (typeof unsafe !== "string") {
|
|
26
|
-
return String(unsafe);
|
|
27
|
-
}
|
|
28
|
-
return unsafe.replace(/[&<"']/g, function(match) {
|
|
29
|
-
const escapeMap = {
|
|
30
|
-
"&": "&",
|
|
31
|
-
"<": "<",
|
|
32
|
-
">": ">",
|
|
33
|
-
'"': """,
|
|
34
|
-
"'": "'"
|
|
35
|
-
};
|
|
36
|
-
return escapeMap[match] || match;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function formatDateLocal(dateInput) {
|
|
40
|
-
const date = typeof dateInput === "string" ? new Date(dateInput) : dateInput;
|
|
41
|
-
const options = {
|
|
42
|
-
year: "numeric",
|
|
43
|
-
month: "short",
|
|
44
|
-
day: "2-digit",
|
|
45
|
-
hour: "2-digit",
|
|
46
|
-
minute: "2-digit",
|
|
47
|
-
hour12: true,
|
|
48
|
-
timeZoneName: "short"
|
|
49
|
-
// or "Asia/Kolkata"
|
|
50
|
-
};
|
|
51
|
-
return new Intl.DateTimeFormat(void 0, options).format(date);
|
|
52
|
-
}
|
|
53
|
-
function extractSuites(titlePath) {
|
|
54
|
-
const tagPattern = /@[\w]+/g;
|
|
55
|
-
const suiteParts = titlePath.slice(3, titlePath.length - 1).map((p) => p.replace(tagPattern, "").trim());
|
|
56
|
-
return {
|
|
57
|
-
hierarchy: suiteParts.join(" > "),
|
|
58
|
-
// full hierarchy
|
|
59
|
-
topLevelSuite: suiteParts[0] ?? "",
|
|
60
|
-
// first suite
|
|
61
|
-
parentSuite: suiteParts[suiteParts.length - 1] ?? ""
|
|
62
|
-
// last suite
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/helpers/databaseManager.ts
|
|
67
|
-
import { open } from "sqlite";
|
|
68
|
-
import sqlite3 from "sqlite3";
|
|
69
|
-
var DatabaseManager = class {
|
|
70
|
-
constructor() {
|
|
71
|
-
this.db = null;
|
|
72
|
-
}
|
|
73
|
-
async initialize(dbPath) {
|
|
74
|
-
try {
|
|
75
|
-
this.db = await open({
|
|
76
|
-
filename: dbPath,
|
|
77
|
-
driver: sqlite3.Database
|
|
78
|
-
});
|
|
79
|
-
await this.createTables();
|
|
80
|
-
await this.createIndexes();
|
|
81
|
-
} catch (error) {
|
|
82
|
-
console.error("OrtoniReport: Error initializing database:", error);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async createTables() {
|
|
86
|
-
if (!this.db) {
|
|
87
|
-
console.error("OrtoniReport: Database not initialized");
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
await this.db.exec(`
|
|
92
|
-
CREATE TABLE IF NOT EXISTS test_runs (
|
|
93
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
94
|
-
run_date TEXT
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
CREATE TABLE IF NOT EXISTS test_results (
|
|
98
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
99
|
-
run_id INTEGER,
|
|
100
|
-
test_id TEXT,
|
|
101
|
-
status TEXT,
|
|
102
|
-
duration INTEGER, -- store duration as raw ms
|
|
103
|
-
error_message TEXT,
|
|
104
|
-
FOREIGN KEY (run_id) REFERENCES test_runs (id)
|
|
105
|
-
);
|
|
106
|
-
`);
|
|
107
|
-
} catch (error) {
|
|
108
|
-
console.error("OrtoniReport: Error creating tables:", error);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async createIndexes() {
|
|
112
|
-
if (!this.db) {
|
|
113
|
-
console.error("OrtoniReport: Database not initialized");
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
await this.db.exec(`
|
|
118
|
-
CREATE INDEX IF NOT EXISTS idx_test_id ON test_results (test_id);
|
|
119
|
-
CREATE INDEX IF NOT EXISTS idx_run_id ON test_results (run_id);
|
|
120
|
-
`);
|
|
121
|
-
} catch (error) {
|
|
122
|
-
console.error("OrtoniReport: Error creating indexes:", error);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
async saveTestRun() {
|
|
126
|
-
if (!this.db) {
|
|
127
|
-
console.error("OrtoniReport: Database not initialized");
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
const runDate = (/* @__PURE__ */ new Date()).toISOString();
|
|
132
|
-
const { lastID } = await this.db.run(
|
|
133
|
-
`
|
|
134
|
-
INSERT INTO test_runs (run_date)
|
|
135
|
-
VALUES (?)
|
|
136
|
-
`,
|
|
137
|
-
[runDate]
|
|
138
|
-
);
|
|
139
|
-
return lastID;
|
|
140
|
-
} catch (error) {
|
|
141
|
-
console.error("OrtoniReport: Error saving test run:", error);
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
async saveTestResults(runId, results) {
|
|
146
|
-
if (!this.db) {
|
|
147
|
-
console.error("OrtoniReport: Database not initialized");
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
try {
|
|
151
|
-
await this.db.exec("BEGIN TRANSACTION;");
|
|
152
|
-
const stmt = await this.db.prepare(`
|
|
153
|
-
INSERT INTO test_results (run_id, test_id, status, duration, error_message)
|
|
154
|
-
VALUES (?, ?, ?, ?, ?)
|
|
155
|
-
`);
|
|
156
|
-
for (const result of results) {
|
|
157
|
-
await stmt.run([
|
|
158
|
-
runId,
|
|
159
|
-
`${result.filePath}:${result.projectName}:${result.title}`,
|
|
160
|
-
result.status,
|
|
161
|
-
result.duration,
|
|
162
|
-
// store raw ms
|
|
163
|
-
result.errors.join("\n")
|
|
164
|
-
]);
|
|
165
|
-
}
|
|
166
|
-
await stmt.finalize();
|
|
167
|
-
await this.db.exec("COMMIT;");
|
|
168
|
-
} catch (error) {
|
|
169
|
-
await this.db.exec("ROLLBACK;");
|
|
170
|
-
console.error("OrtoniReport: Error saving test results:", error);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
async getTestHistory(testId, limit = 10) {
|
|
174
|
-
if (!this.db) {
|
|
175
|
-
console.error("OrtoniReport: Database not initialized");
|
|
176
|
-
return [];
|
|
177
|
-
}
|
|
178
|
-
try {
|
|
179
|
-
const results = await this.db.all(
|
|
180
|
-
`
|
|
181
|
-
SELECT tr.status, tr.duration, tr.error_message, trun.run_date
|
|
182
|
-
FROM test_results tr
|
|
183
|
-
JOIN test_runs trun ON tr.run_id = trun.id
|
|
184
|
-
WHERE tr.test_id = ?
|
|
185
|
-
ORDER BY trun.run_date DESC
|
|
186
|
-
LIMIT ?
|
|
187
|
-
`,
|
|
188
|
-
[testId, limit]
|
|
189
|
-
);
|
|
190
|
-
return results.map((result) => ({
|
|
191
|
-
...result,
|
|
192
|
-
run_date: formatDateLocal(result.run_date)
|
|
193
|
-
}));
|
|
194
|
-
} catch (error) {
|
|
195
|
-
console.error("OrtoniReport: Error getting test history:", error);
|
|
196
|
-
return [];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
async close() {
|
|
200
|
-
if (this.db) {
|
|
201
|
-
try {
|
|
202
|
-
await this.db.close();
|
|
203
|
-
} catch (error) {
|
|
204
|
-
console.error("OrtoniReport: Error closing database:", error);
|
|
205
|
-
} finally {
|
|
206
|
-
this.db = null;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
async getSummaryData() {
|
|
211
|
-
if (!this.db) {
|
|
212
|
-
console.error("OrtoniReport: Database not initialized");
|
|
213
|
-
return {
|
|
214
|
-
totalRuns: 0,
|
|
215
|
-
totalTests: 0,
|
|
216
|
-
passed: 0,
|
|
217
|
-
failed: 0,
|
|
218
|
-
passRate: 0,
|
|
219
|
-
avgDuration: 0
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
try {
|
|
223
|
-
const summary = await this.db.get(`
|
|
224
|
-
SELECT
|
|
225
|
-
(SELECT COUNT(*) FROM test_runs) as totalRuns,
|
|
226
|
-
(SELECT COUNT(*) FROM test_results) as totalTests,
|
|
227
|
-
(SELECT COUNT(*) FROM test_results WHERE status = 'passed') as passed,
|
|
228
|
-
(SELECT COUNT(*) FROM test_results WHERE status = 'failed') as failed,
|
|
229
|
-
(SELECT AVG(duration) FROM test_results) as avgDuration
|
|
230
|
-
`);
|
|
231
|
-
const passRate = summary.totalTests ? (summary.passed / summary.totalTests * 100).toFixed(2) : 0;
|
|
232
|
-
return {
|
|
233
|
-
totalRuns: summary.totalRuns,
|
|
234
|
-
totalTests: summary.totalTests,
|
|
235
|
-
passed: summary.passed,
|
|
236
|
-
failed: summary.failed,
|
|
237
|
-
passRate: parseFloat(passRate.toString()),
|
|
238
|
-
avgDuration: Math.round(summary.avgDuration || 0)
|
|
239
|
-
// raw ms avg
|
|
240
|
-
};
|
|
241
|
-
} catch (error) {
|
|
242
|
-
console.error("OrtoniReport: Error getting summary data:", error);
|
|
243
|
-
return {
|
|
244
|
-
totalRuns: 0,
|
|
245
|
-
totalTests: 0,
|
|
246
|
-
passed: 0,
|
|
247
|
-
failed: 0,
|
|
248
|
-
passRate: 0,
|
|
249
|
-
avgDuration: 0
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
async getTrends(limit = 100) {
|
|
254
|
-
if (!this.db) {
|
|
255
|
-
console.error("OrtoniReport: Database not initialized");
|
|
256
|
-
return [];
|
|
257
|
-
}
|
|
258
|
-
try {
|
|
259
|
-
const rows = await this.db.all(
|
|
260
|
-
`
|
|
261
|
-
SELECT trun.run_date,
|
|
262
|
-
SUM(CASE WHEN tr.status = 'passed' THEN 1 ELSE 0 END) AS passed,
|
|
263
|
-
SUM(CASE WHEN tr.status = 'failed' THEN 1 ELSE 0 END) AS failed,
|
|
264
|
-
AVG(tr.duration) AS avg_duration
|
|
265
|
-
FROM test_results tr
|
|
266
|
-
JOIN test_runs trun ON tr.run_id = trun.id
|
|
267
|
-
GROUP BY trun.run_date
|
|
268
|
-
ORDER BY trun.run_date DESC
|
|
269
|
-
LIMIT ?
|
|
270
|
-
`,
|
|
271
|
-
[limit]
|
|
272
|
-
);
|
|
273
|
-
return rows.reverse().map((row) => ({
|
|
274
|
-
...row,
|
|
275
|
-
run_date: formatDateLocal(row.run_date),
|
|
276
|
-
avg_duration: Math.round(row.avg_duration || 0)
|
|
277
|
-
// raw ms avg
|
|
278
|
-
}));
|
|
279
|
-
} catch (error) {
|
|
280
|
-
console.error("OrtoniReport: Error getting trends data:", error);
|
|
281
|
-
return [];
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
async getFlakyTests(limit = 10) {
|
|
285
|
-
if (!this.db) {
|
|
286
|
-
console.error("OrtoniReport: Database not initialized");
|
|
287
|
-
return [];
|
|
288
|
-
}
|
|
289
|
-
try {
|
|
290
|
-
return await this.db.all(
|
|
291
|
-
`
|
|
292
|
-
SELECT
|
|
293
|
-
test_id,
|
|
294
|
-
COUNT(*) AS total,
|
|
295
|
-
SUM(CASE WHEN status = 'flaky' THEN 1 ELSE 0 END) AS flaky,
|
|
296
|
-
AVG(duration) AS avg_duration
|
|
297
|
-
FROM test_results
|
|
298
|
-
GROUP BY test_id
|
|
299
|
-
HAVING flaky > 0
|
|
300
|
-
ORDER BY flaky DESC
|
|
301
|
-
LIMIT ?
|
|
302
|
-
`,
|
|
303
|
-
[limit]
|
|
304
|
-
);
|
|
305
|
-
} catch (error) {
|
|
306
|
-
console.error("OrtoniReport: Error getting flaky tests:", error);
|
|
307
|
-
return [];
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
async getSlowTests(limit = 10) {
|
|
311
|
-
if (!this.db) {
|
|
312
|
-
console.error("OrtoniReport: Database not initialized");
|
|
313
|
-
return [];
|
|
314
|
-
}
|
|
315
|
-
try {
|
|
316
|
-
const rows = await this.db.all(
|
|
317
|
-
`
|
|
318
|
-
SELECT
|
|
319
|
-
test_id,
|
|
320
|
-
AVG(duration) AS avg_duration
|
|
321
|
-
FROM test_results
|
|
322
|
-
GROUP BY test_id
|
|
323
|
-
ORDER BY avg_duration DESC
|
|
324
|
-
LIMIT ?
|
|
325
|
-
`,
|
|
326
|
-
[limit]
|
|
327
|
-
);
|
|
328
|
-
return rows.map((row) => ({
|
|
329
|
-
test_id: row.test_id,
|
|
330
|
-
avg_duration: Math.round(row.avg_duration || 0)
|
|
331
|
-
// raw ms avg
|
|
332
|
-
}));
|
|
333
|
-
} catch (error) {
|
|
334
|
-
console.error("OrtoniReport: Error getting slow tests:", error);
|
|
335
|
-
return [];
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
// src/utils/groupProjects.ts
|
|
341
|
-
function groupResults(config, results) {
|
|
342
|
-
if (config.showProject) {
|
|
343
|
-
const groupedResults = results.reduce((acc, result, index) => {
|
|
344
|
-
const testId = `${result.filePath}:${result.projectName}:${result.title}`;
|
|
345
|
-
const key = `${testId}-${result.key}-${result.retryAttemptCount}`;
|
|
346
|
-
const { filePath, suite, projectName } = result;
|
|
347
|
-
acc[filePath] = acc[filePath] || {};
|
|
348
|
-
acc[filePath][suite] = acc[filePath][suite] || {};
|
|
349
|
-
acc[filePath][suite][projectName] = acc[filePath][suite][projectName] || [];
|
|
350
|
-
acc[filePath][suite][projectName].push({ ...result, index, testId, key });
|
|
351
|
-
return acc;
|
|
352
|
-
}, {});
|
|
353
|
-
return groupedResults;
|
|
354
|
-
} else {
|
|
355
|
-
const groupedResults = results.reduce((acc, result, index) => {
|
|
356
|
-
const testId = `${result.filePath}:${result.projectName}:${result.title}`;
|
|
357
|
-
const key = `${testId}-${result.key}-${result.retryAttemptCount}`;
|
|
358
|
-
const { filePath, suite } = result;
|
|
359
|
-
acc[filePath] = acc[filePath] || {};
|
|
360
|
-
acc[filePath][suite] = acc[filePath][suite] || [];
|
|
361
|
-
acc[filePath][suite].push({ ...result, index, testId, key });
|
|
362
|
-
return acc;
|
|
363
|
-
}, {});
|
|
364
|
-
return groupedResults;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// src/helpers/HTMLGenerator.ts
|
|
369
|
-
var HTMLGenerator = class {
|
|
370
|
-
constructor(ortoniConfig, dbManager) {
|
|
371
|
-
this.ortoniConfig = ortoniConfig;
|
|
372
|
-
this.dbManager = dbManager;
|
|
373
|
-
}
|
|
374
|
-
async generateFinalReport(filteredResults, totalDuration, results, projectSet) {
|
|
375
|
-
const data = await this.prepareReportData(
|
|
376
|
-
filteredResults,
|
|
377
|
-
totalDuration,
|
|
378
|
-
results,
|
|
379
|
-
projectSet
|
|
380
|
-
);
|
|
381
|
-
return data;
|
|
382
|
-
}
|
|
383
|
-
async getReportData() {
|
|
384
|
-
return {
|
|
385
|
-
summary: await this.dbManager.getSummaryData(),
|
|
386
|
-
trends: await this.dbManager.getTrends(),
|
|
387
|
-
flakyTests: await this.dbManager.getFlakyTests(),
|
|
388
|
-
slowTests: await this.dbManager.getSlowTests()
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
async prepareReportData(filteredResults, totalDuration, results, projectSet) {
|
|
392
|
-
const totalTests = filteredResults.length;
|
|
393
|
-
const passedTests = results.filter((r) => r.status === "passed").length;
|
|
394
|
-
const flakyTests = results.filter((r) => r.status === "flaky").length;
|
|
395
|
-
const failed = filteredResults.filter(
|
|
396
|
-
(r) => r.status === "failed" || r.status === "timedOut"
|
|
397
|
-
).length;
|
|
398
|
-
const successRate = ((passedTests + flakyTests) / totalTests * 100).toFixed(2);
|
|
399
|
-
const allTags = /* @__PURE__ */ new Set();
|
|
400
|
-
results.forEach(
|
|
401
|
-
(result) => result.testTags.forEach((tag) => allTags.add(tag))
|
|
402
|
-
);
|
|
403
|
-
const projectResults = this.calculateProjectResults(
|
|
404
|
-
filteredResults,
|
|
405
|
-
results,
|
|
406
|
-
projectSet
|
|
407
|
-
);
|
|
408
|
-
const lastRunDate = (/* @__PURE__ */ new Date()).toLocaleString();
|
|
409
|
-
const testHistories = await Promise.all(
|
|
410
|
-
results.map(async (result) => {
|
|
411
|
-
const testId = `${result.filePath}:${result.projectName}:${result.title}`;
|
|
412
|
-
const history = await this.dbManager.getTestHistory(testId);
|
|
413
|
-
return {
|
|
414
|
-
testId,
|
|
415
|
-
history
|
|
416
|
-
};
|
|
417
|
-
})
|
|
418
|
-
);
|
|
419
|
-
return {
|
|
420
|
-
summary: {
|
|
421
|
-
overAllResult: {
|
|
422
|
-
pass: passedTests,
|
|
423
|
-
fail: failed,
|
|
424
|
-
skip: results.filter((r) => r.status === "skipped").length,
|
|
425
|
-
retry: results.filter((r) => r.retryAttemptCount).length,
|
|
426
|
-
flaky: flakyTests,
|
|
427
|
-
total: filteredResults.length
|
|
428
|
-
},
|
|
429
|
-
successRate,
|
|
430
|
-
lastRunDate,
|
|
431
|
-
totalDuration,
|
|
432
|
-
stats: this.extractProjectStats(projectResults)
|
|
433
|
-
},
|
|
434
|
-
testResult: {
|
|
435
|
-
tests: groupResults(this.ortoniConfig, results),
|
|
436
|
-
testHistories,
|
|
437
|
-
allTags: Array.from(allTags),
|
|
438
|
-
set: projectSet
|
|
439
|
-
},
|
|
440
|
-
userConfig: {
|
|
441
|
-
projectName: this.ortoniConfig.projectName,
|
|
442
|
-
authorName: this.ortoniConfig.authorName,
|
|
443
|
-
type: this.ortoniConfig.testType,
|
|
444
|
-
title: this.ortoniConfig.title
|
|
445
|
-
},
|
|
446
|
-
userMeta: {
|
|
447
|
-
meta: this.ortoniConfig.meta
|
|
448
|
-
},
|
|
449
|
-
preferences: {
|
|
450
|
-
logo: this.ortoniConfig.logo || void 0,
|
|
451
|
-
showProject: this.ortoniConfig.showProject || false
|
|
452
|
-
},
|
|
453
|
-
analytics: {
|
|
454
|
-
reportData: await this.getReportData()
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
calculateProjectResults(filteredResults, results, projectSet) {
|
|
459
|
-
return Array.from(projectSet).map((projectName) => {
|
|
460
|
-
const projectTests = filteredResults.filter(
|
|
461
|
-
(r) => r.projectName === projectName
|
|
462
|
-
);
|
|
463
|
-
const allProjectTests = results.filter(
|
|
464
|
-
(r) => r.projectName === projectName
|
|
465
|
-
);
|
|
466
|
-
return {
|
|
467
|
-
projectName,
|
|
468
|
-
passedTests: projectTests.filter((r) => r.status === "passed").length,
|
|
469
|
-
failedTests: projectTests.filter(
|
|
470
|
-
(r) => r.status === "failed" || r.status === "timedOut"
|
|
471
|
-
).length,
|
|
472
|
-
skippedTests: allProjectTests.filter((r) => r.status === "skipped").length,
|
|
473
|
-
retryTests: allProjectTests.filter((r) => r.retryAttemptCount).length,
|
|
474
|
-
flakyTests: allProjectTests.filter((r) => r.status === "flaky").length,
|
|
475
|
-
totalTests: projectTests.length
|
|
476
|
-
};
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
extractProjectStats(projectResults) {
|
|
480
|
-
return {
|
|
481
|
-
projectNames: projectResults.map((result) => result.projectName),
|
|
482
|
-
totalTests: projectResults.map((result) => result.totalTests),
|
|
483
|
-
passedTests: projectResults.map((result) => result.passedTests),
|
|
484
|
-
failedTests: projectResults.map((result) => result.failedTests),
|
|
485
|
-
skippedTests: projectResults.map((result) => result.skippedTests),
|
|
486
|
-
retryTests: projectResults.map((result) => result.retryTests),
|
|
487
|
-
flakyTests: projectResults.map((result) => result.flakyTests)
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
// src/helpers/fileManager.ts
|
|
493
|
-
import fs2 from "fs";
|
|
494
|
-
import path3 from "path";
|
|
495
|
-
|
|
496
|
-
// src/helpers/templateLoader.ts
|
|
497
|
-
import fs from "fs";
|
|
498
|
-
import path2 from "path";
|
|
499
|
-
function getCreateRequire() {
|
|
500
|
-
try {
|
|
501
|
-
const { createRequire } = __require("module");
|
|
502
|
-
return createRequire;
|
|
503
|
-
} catch (e) {
|
|
504
|
-
try {
|
|
505
|
-
const m = eval("require('module')");
|
|
506
|
-
return m.createRequire;
|
|
507
|
-
} catch {
|
|
508
|
-
return null;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
function readBundledTemplate(pkgName = "ortoni-report") {
|
|
513
|
-
const packagedRel = "dist/index.html";
|
|
514
|
-
const createRequire = getCreateRequire();
|
|
515
|
-
if (createRequire) {
|
|
516
|
-
try {
|
|
517
|
-
const requireFn = createRequire(__filename);
|
|
518
|
-
const resolved = requireFn.resolve(`${pkgName}/${packagedRel}`);
|
|
519
|
-
if (fs.existsSync(resolved)) {
|
|
520
|
-
return fs.readFileSync(resolved, "utf-8");
|
|
521
|
-
}
|
|
522
|
-
} catch {
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
try {
|
|
526
|
-
const here = path2.resolve(__dirname, "../dist/index.html");
|
|
527
|
-
if (fs.existsSync(here)) return fs.readFileSync(here, "utf-8");
|
|
528
|
-
} catch {
|
|
529
|
-
}
|
|
530
|
-
try {
|
|
531
|
-
const nm = path2.join(process.cwd(), "node_modules", pkgName, packagedRel);
|
|
532
|
-
if (fs.existsSync(nm)) return fs.readFileSync(nm, "utf-8");
|
|
533
|
-
} catch {
|
|
534
|
-
}
|
|
535
|
-
try {
|
|
536
|
-
const alt = path2.join(process.cwd(), "dist", "index.html");
|
|
537
|
-
if (fs.existsSync(alt)) return fs.readFileSync(alt, "utf-8");
|
|
538
|
-
} catch {
|
|
539
|
-
}
|
|
540
|
-
throw new Error(
|
|
541
|
-
`ortoni-report template not found (tried:
|
|
542
|
-
- require.resolve('${pkgName}/${packagedRel}')
|
|
543
|
-
- relative ../dist/index.html
|
|
544
|
-
- ${path2.join(
|
|
545
|
-
process.cwd(),
|
|
546
|
-
"node_modules",
|
|
547
|
-
pkgName,
|
|
548
|
-
packagedRel
|
|
549
|
-
)}
|
|
550
|
-
- ${path2.join(process.cwd(), "dist", "index.html")}
|
|
551
|
-
Ensure 'dist/index.html' is present in the package and that your package.json 'files' includes 'dist/'.`
|
|
552
|
-
);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// src/helpers/fileManager.ts
|
|
556
|
-
var FileManager = class {
|
|
557
|
-
constructor(folderPath) {
|
|
558
|
-
this.folderPath = folderPath;
|
|
559
|
-
}
|
|
560
|
-
ensureReportDirectory() {
|
|
561
|
-
const ortoniDataFolder = path3.join(this.folderPath, "ortoni-data");
|
|
562
|
-
if (!fs2.existsSync(this.folderPath)) {
|
|
563
|
-
fs2.mkdirSync(this.folderPath, { recursive: true });
|
|
564
|
-
} else {
|
|
565
|
-
if (fs2.existsSync(ortoniDataFolder)) {
|
|
566
|
-
fs2.rmSync(ortoniDataFolder, { recursive: true, force: true });
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
writeReportFile(filename, data) {
|
|
571
|
-
let html = readBundledTemplate();
|
|
572
|
-
const reportJSON = JSON.stringify({
|
|
573
|
-
data
|
|
574
|
-
});
|
|
575
|
-
html = html.replace("__ORTONI_TEST_REPORTDATA__", reportJSON);
|
|
576
|
-
const outputPath = path3.join(process.cwd(), this.folderPath, filename);
|
|
577
|
-
fs2.writeFileSync(outputPath, html);
|
|
578
|
-
return outputPath;
|
|
579
|
-
}
|
|
580
|
-
writeRawFile(filename, data) {
|
|
581
|
-
const outputPath = path3.join(process.cwd(), this.folderPath, filename);
|
|
582
|
-
fs2.mkdirSync(path3.dirname(outputPath), { recursive: true });
|
|
583
|
-
const content = typeof data === "string" ? data : JSON.stringify(data, null, 2);
|
|
584
|
-
fs2.writeFileSync(outputPath, content, "utf-8");
|
|
585
|
-
return outputPath;
|
|
586
|
-
}
|
|
587
|
-
copyTraceViewerAssets(skip) {
|
|
588
|
-
if (skip) return;
|
|
589
|
-
const traceViewerFolder = path3.join(
|
|
590
|
-
__require.resolve("playwright-core"),
|
|
591
|
-
"..",
|
|
592
|
-
"lib",
|
|
593
|
-
"vite",
|
|
594
|
-
"traceViewer"
|
|
595
|
-
);
|
|
596
|
-
const traceViewerTargetFolder = path3.join(this.folderPath, "trace");
|
|
597
|
-
const traceViewerAssetsTargetFolder = path3.join(
|
|
598
|
-
traceViewerTargetFolder,
|
|
599
|
-
"assets"
|
|
600
|
-
);
|
|
601
|
-
fs2.mkdirSync(traceViewerAssetsTargetFolder, { recursive: true });
|
|
602
|
-
for (const file of fs2.readdirSync(traceViewerFolder)) {
|
|
603
|
-
if (file.endsWith(".map") || file.includes("watch") || file.includes("assets"))
|
|
604
|
-
continue;
|
|
605
|
-
fs2.copyFileSync(
|
|
606
|
-
path3.join(traceViewerFolder, file),
|
|
607
|
-
path3.join(traceViewerTargetFolder, file)
|
|
608
|
-
);
|
|
609
|
-
}
|
|
610
|
-
const assetsFolder = path3.join(traceViewerFolder, "assets");
|
|
611
|
-
for (const file of fs2.readdirSync(assetsFolder)) {
|
|
612
|
-
if (file.endsWith(".map") || file.includes("xtermModule")) continue;
|
|
613
|
-
fs2.copyFileSync(
|
|
614
|
-
path3.join(assetsFolder, file),
|
|
615
|
-
path3.join(traceViewerAssetsTargetFolder, file)
|
|
616
|
-
);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
|
|
621
|
-
// src/utils/expressServer.ts
|
|
622
|
-
import express from "express";
|
|
623
|
-
import path4 from "path";
|
|
624
|
-
import { spawn } from "child_process";
|
|
625
|
-
function startReportServer(reportFolder, reportFilename, port = 2004, open2) {
|
|
626
|
-
const app = express();
|
|
627
|
-
app.use(express.static(reportFolder));
|
|
628
|
-
app.get("/", (_req, res) => {
|
|
629
|
-
try {
|
|
630
|
-
res.sendFile(path4.resolve(reportFolder, reportFilename));
|
|
631
|
-
} catch (error) {
|
|
632
|
-
console.error("Ortoni Report: Error sending report file:", error);
|
|
633
|
-
res.status(500).send("Error loading report");
|
|
634
|
-
}
|
|
635
|
-
});
|
|
636
|
-
try {
|
|
637
|
-
const server = app.listen(port, () => {
|
|
638
|
-
console.log(
|
|
639
|
-
`Server is running at http://localhost:${port}
|
|
640
|
-
Press Ctrl+C to stop.`
|
|
641
|
-
);
|
|
642
|
-
if (open2 === "always" || open2 === "on-failure") {
|
|
643
|
-
try {
|
|
644
|
-
openBrowser(`http://localhost:${port}`);
|
|
645
|
-
} catch (error) {
|
|
646
|
-
console.error("Ortoni Report: Error opening browser:", error);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
});
|
|
650
|
-
server.on("error", (error) => {
|
|
651
|
-
if (error.code === "EADDRINUSE") {
|
|
652
|
-
console.error(
|
|
653
|
-
`Ortoni Report: Port ${port} is already in use. Trying a different port...`
|
|
654
|
-
);
|
|
655
|
-
} else {
|
|
656
|
-
console.error("Ortoni Report: Server error:", error);
|
|
657
|
-
}
|
|
658
|
-
});
|
|
659
|
-
} catch (error) {
|
|
660
|
-
console.error("Ortoni Report: Error starting the server:", error);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
function openBrowser(url) {
|
|
664
|
-
const platform = process.platform;
|
|
665
|
-
let command;
|
|
666
|
-
try {
|
|
667
|
-
if (platform === "win32") {
|
|
668
|
-
command = "cmd";
|
|
669
|
-
spawn(command, ["/c", "start", url]);
|
|
670
|
-
} else if (platform === "darwin") {
|
|
671
|
-
command = "open";
|
|
672
|
-
spawn(command, [url]);
|
|
673
|
-
} else {
|
|
674
|
-
command = "xdg-open";
|
|
675
|
-
spawn(command, [url]);
|
|
676
|
-
}
|
|
677
|
-
} catch (error) {
|
|
678
|
-
console.error("Ortoni Report: Error opening the browser:", error);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
export {
|
|
683
|
-
__publicField,
|
|
684
|
-
normalizeFilePath,
|
|
685
|
-
ensureHtmlExtension,
|
|
686
|
-
escapeHtml,
|
|
687
|
-
extractSuites,
|
|
688
|
-
DatabaseManager,
|
|
689
|
-
HTMLGenerator,
|
|
690
|
-
FileManager,
|
|
691
|
-
startReportServer
|
|
692
|
-
};
|