ortoni-report 3.0.5 → 4.0.1-beta.0

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