ortoni-report 4.0.2-beta.1 → 4.0.3

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