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