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