ortoni-report 4.0.1-beta.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,234 +8,14 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
8
8
  });
9
9
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
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
11
  // src/utils/utils.ts
232
- import path2 from "path";
12
+ import path from "path";
233
13
  function normalizeFilePath(filePath) {
234
- const normalizedPath = path2.normalize(filePath);
235
- return path2.basename(normalizedPath);
14
+ const normalizedPath = path.normalize(filePath);
15
+ return path.basename(normalizedPath);
236
16
  }
237
17
  function ensureHtmlExtension(filename) {
238
- const ext = path2.extname(filename);
18
+ const ext = path.extname(filename);
239
19
  if (ext && ext.toLowerCase() === ".html") {
240
20
  return filename;
241
21
  }
@@ -283,67 +63,6 @@ function extractSuites(titlePath) {
283
63
  };
284
64
  }
285
65
 
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
66
  // src/helpers/databaseManager.ts
348
67
  import { open } from "sqlite";
349
68
  import sqlite3 from "sqlite3";
@@ -618,14 +337,408 @@ var DatabaseManager = class {
618
337
  }
619
338
  };
620
339
 
621
- export {
622
- __publicField,
623
- FileManager,
624
- HTMLGenerator,
625
- normalizeFilePath,
626
- ensureHtmlExtension,
627
- escapeHtml,
628
- extractSuites,
629
- startReportServer,
630
- DatabaseManager
340
+ // src/utils/groupProjects.ts
341
+ function groupResults(config, results) {
342
+ if (config.showProject) {
343
+ const groupedResults = results.reduce((acc, result, index) => {
344
+ const testId = `${result.filePath}:${result.projectName}:${result.title}`;
345
+ const key = `${testId}-${result.key}-${result.retryAttemptCount}`;
346
+ const { filePath, suite, projectName } = result;
347
+ acc[filePath] = acc[filePath] || {};
348
+ acc[filePath][suite] = acc[filePath][suite] || {};
349
+ acc[filePath][suite][projectName] = acc[filePath][suite][projectName] || [];
350
+ acc[filePath][suite][projectName].push({ ...result, index, testId, key });
351
+ return acc;
352
+ }, {});
353
+ return groupedResults;
354
+ } else {
355
+ const groupedResults = results.reduce((acc, result, index) => {
356
+ const testId = `${result.filePath}:${result.projectName}:${result.title}`;
357
+ const key = `${testId}-${result.key}-${result.retryAttemptCount}`;
358
+ const { filePath, suite } = result;
359
+ acc[filePath] = acc[filePath] || {};
360
+ acc[filePath][suite] = acc[filePath][suite] || [];
361
+ acc[filePath][suite].push({ ...result, index, testId, key });
362
+ return acc;
363
+ }, {});
364
+ return groupedResults;
365
+ }
366
+ }
367
+
368
+ // src/helpers/HTMLGenerator.ts
369
+ var HTMLGenerator = class {
370
+ constructor(ortoniConfig, dbManager) {
371
+ this.ortoniConfig = ortoniConfig;
372
+ this.dbManager = dbManager;
373
+ }
374
+ async generateFinalReport(filteredResults, totalDuration, results, projectSet) {
375
+ const data = await this.prepareReportData(
376
+ filteredResults,
377
+ totalDuration,
378
+ results,
379
+ projectSet
380
+ );
381
+ return data;
382
+ }
383
+ /**
384
+ * Return safe analytics/report data.
385
+ * If no dbManager is provided, return empty defaults and a note explaining why.
386
+ */
387
+ async getReportData() {
388
+ if (!this.dbManager) {
389
+ return {
390
+ summary: {},
391
+ trends: {},
392
+ flakyTests: [],
393
+ slowTests: [],
394
+ note: "Test history/trends are unavailable (saveHistory disabled or DB not initialized)."
395
+ };
396
+ }
397
+ try {
398
+ const [summary, trends, flakyTests, slowTests] = await Promise.all([
399
+ this.dbManager.getSummaryData ? this.dbManager.getSummaryData() : Promise.resolve({}),
400
+ this.dbManager.getTrends ? this.dbManager.getTrends() : Promise.resolve({}),
401
+ this.dbManager.getFlakyTests ? this.dbManager.getFlakyTests() : Promise.resolve([]),
402
+ this.dbManager.getSlowTests ? this.dbManager.getSlowTests() : Promise.resolve([])
403
+ ]);
404
+ return {
405
+ summary: summary ?? {},
406
+ trends: trends ?? {},
407
+ flakyTests: flakyTests ?? [],
408
+ slowTests: slowTests ?? []
409
+ };
410
+ } catch (err) {
411
+ console.warn(
412
+ "HTMLGenerator: failed to read analytics from DB, continuing without history.",
413
+ err
414
+ );
415
+ return {
416
+ summary: {},
417
+ trends: {},
418
+ flakyTests: [],
419
+ slowTests: [],
420
+ note: "Test history/trends could not be loaded due to a DB error."
421
+ };
422
+ }
423
+ }
424
+ async prepareReportData(filteredResults, totalDuration, results, projectSet) {
425
+ const totalTests = filteredResults.length;
426
+ const passedTests = results.filter((r) => r.status === "passed").length;
427
+ const flakyTests = results.filter((r) => r.status === "flaky").length;
428
+ const failed = filteredResults.filter(
429
+ (r) => r.status === "failed" || r.status === "timedOut"
430
+ ).length;
431
+ const successRate = totalTests === 0 ? "0.00" : ((passedTests + flakyTests) / totalTests * 100).toFixed(2);
432
+ const allTags = /* @__PURE__ */ new Set();
433
+ results.forEach(
434
+ (result) => (result.testTags || []).forEach((tag) => allTags.add(tag))
435
+ );
436
+ const projectResults = this.calculateProjectResults(
437
+ filteredResults,
438
+ results,
439
+ projectSet
440
+ );
441
+ const lastRunDate = (/* @__PURE__ */ new Date()).toLocaleString();
442
+ const testHistories = await Promise.all(
443
+ results.map(async (result) => {
444
+ const testId = `${result.filePath}:${result.projectName}:${result.title}`;
445
+ if (!this.dbManager || !this.dbManager.getTestHistory) {
446
+ return {
447
+ testId,
448
+ history: []
449
+ };
450
+ }
451
+ try {
452
+ const history = await this.dbManager.getTestHistory(testId);
453
+ return {
454
+ testId,
455
+ history: history ?? []
456
+ };
457
+ } catch (err) {
458
+ console.warn(
459
+ `HTMLGenerator: failed to read history for ${testId}`,
460
+ err
461
+ );
462
+ return {
463
+ testId,
464
+ history: []
465
+ };
466
+ }
467
+ })
468
+ );
469
+ const reportData = await this.getReportData();
470
+ return {
471
+ summary: {
472
+ overAllResult: {
473
+ pass: passedTests,
474
+ fail: failed,
475
+ skip: results.filter((r) => r.status === "skipped").length,
476
+ retry: results.filter((r) => r.retryAttemptCount).length,
477
+ flaky: flakyTests,
478
+ total: filteredResults.length
479
+ },
480
+ successRate,
481
+ lastRunDate,
482
+ totalDuration,
483
+ stats: this.extractProjectStats(projectResults)
484
+ },
485
+ testResult: {
486
+ tests: groupResults(this.ortoniConfig, results),
487
+ testHistories,
488
+ allTags: Array.from(allTags),
489
+ set: projectSet
490
+ },
491
+ userConfig: {
492
+ projectName: this.ortoniConfig.projectName,
493
+ authorName: this.ortoniConfig.authorName,
494
+ type: this.ortoniConfig.testType,
495
+ title: this.ortoniConfig.title
496
+ },
497
+ userMeta: {
498
+ meta: this.ortoniConfig.meta
499
+ },
500
+ preferences: {
501
+ logo: this.ortoniConfig.logo || void 0,
502
+ showProject: this.ortoniConfig.showProject || false
503
+ },
504
+ analytics: {
505
+ reportData
506
+ }
507
+ };
508
+ }
509
+ calculateProjectResults(filteredResults, results, projectSet) {
510
+ return Array.from(projectSet).map((projectName) => {
511
+ const projectTests = filteredResults.filter(
512
+ (r) => r.projectName === projectName
513
+ );
514
+ const allProjectTests = results.filter(
515
+ (r) => r.projectName === projectName
516
+ );
517
+ return {
518
+ projectName,
519
+ passedTests: projectTests.filter((r) => r.status === "passed").length,
520
+ failedTests: projectTests.filter(
521
+ (r) => r.status === "failed" || r.status === "timedOut"
522
+ ).length,
523
+ skippedTests: allProjectTests.filter((r) => r.status === "skipped").length,
524
+ retryTests: allProjectTests.filter((r) => r.retryAttemptCount).length,
525
+ flakyTests: allProjectTests.filter((r) => r.status === "flaky").length,
526
+ totalTests: projectTests.length
527
+ };
528
+ });
529
+ }
530
+ extractProjectStats(projectResults) {
531
+ return {
532
+ projectNames: projectResults.map((result) => result.projectName),
533
+ totalTests: projectResults.map((result) => result.totalTests),
534
+ passedTests: projectResults.map((result) => result.passedTests),
535
+ failedTests: projectResults.map((result) => result.failedTests),
536
+ skippedTests: projectResults.map((result) => result.skippedTests),
537
+ retryTests: projectResults.map((result) => result.retryTests),
538
+ flakyTests: projectResults.map((result) => result.flakyTests)
539
+ };
540
+ }
541
+ };
542
+
543
+ // src/helpers/fileManager.ts
544
+ import fs2 from "fs";
545
+ import path3 from "path";
546
+
547
+ // src/helpers/templateLoader.ts
548
+ import fs from "fs";
549
+ import path2 from "path";
550
+ async function readBundledTemplate(pkgName = "ortoni-report") {
551
+ const packagedRel = "dist/index.html";
552
+ try {
553
+ if (typeof __require === "function") {
554
+ const resolved = __require.resolve(`${pkgName}/${packagedRel}`);
555
+ if (fs.existsSync(resolved)) {
556
+ return fs.readFileSync(resolved, "utf-8");
557
+ }
558
+ }
559
+ } catch {
560
+ }
561
+ try {
562
+ const moduleNS = await import("module");
563
+ if (moduleNS && typeof moduleNS.createRequire === "function") {
564
+ const createRequire = moduleNS.createRequire;
565
+ const req = createRequire(
566
+ // @ts-ignore
567
+ typeof __filename !== "undefined" ? __filename : import.meta.url
568
+ );
569
+ const resolved = req.resolve(`${pkgName}/${packagedRel}`);
570
+ if (fs.existsSync(resolved)) {
571
+ return fs.readFileSync(resolved, "utf-8");
572
+ }
573
+ }
574
+ } catch {
575
+ }
576
+ try {
577
+ const here = path2.resolve(__dirname, "../dist/index.html");
578
+ if (fs.existsSync(here)) return fs.readFileSync(here, "utf-8");
579
+ } catch {
580
+ }
581
+ try {
582
+ const nm = path2.join(process.cwd(), "node_modules", pkgName, packagedRel);
583
+ if (fs.existsSync(nm)) return fs.readFileSync(nm, "utf-8");
584
+ } catch {
585
+ }
586
+ try {
587
+ const alt = path2.join(process.cwd(), "dist", "index.html");
588
+ if (fs.existsSync(alt)) return fs.readFileSync(alt, "utf-8");
589
+ } catch {
590
+ }
591
+ throw new Error(
592
+ `ortoni-report template not found (tried:
593
+ - require.resolve('${pkgName}/${packagedRel}')
594
+ - import('module').createRequire(...).resolve('${pkgName}/${packagedRel}')
595
+ - relative ../dist/index.html
596
+ - ${path2.join(
597
+ process.cwd(),
598
+ "node_modules",
599
+ pkgName,
600
+ packagedRel
601
+ )}
602
+ - ${path2.join(process.cwd(), "dist", "index.html")}
603
+ Ensure 'dist/index.html' is present in the published package and package.json 'files' includes 'dist/'.`
604
+ );
605
+ }
606
+
607
+ // src/helpers/fileManager.ts
608
+ var FileManager = class {
609
+ constructor(folderPath) {
610
+ this.folderPath = folderPath;
611
+ }
612
+ ensureReportDirectory() {
613
+ const ortoniDataFolder = path3.join(this.folderPath, "ortoni-data");
614
+ if (!fs2.existsSync(this.folderPath)) {
615
+ fs2.mkdirSync(this.folderPath, { recursive: true });
616
+ } else {
617
+ if (fs2.existsSync(ortoniDataFolder)) {
618
+ fs2.rmSync(ortoniDataFolder, { recursive: true, force: true });
619
+ }
620
+ }
621
+ }
622
+ async writeReportFile(filename, data) {
623
+ let html = await readBundledTemplate();
624
+ const reportJSON = JSON.stringify({
625
+ data
626
+ });
627
+ html = html.replace("__ORTONI_TEST_REPORTDATA__", reportJSON);
628
+ const outputPath = path3.join(process.cwd(), this.folderPath, filename);
629
+ fs2.writeFileSync(outputPath, html);
630
+ return outputPath;
631
+ }
632
+ writeRawFile(filename, data) {
633
+ const outputPath = path3.join(process.cwd(), this.folderPath, filename);
634
+ fs2.mkdirSync(path3.dirname(outputPath), { recursive: true });
635
+ const content = typeof data === "string" ? data : JSON.stringify(data, null, 2);
636
+ fs2.writeFileSync(outputPath, content, "utf-8");
637
+ return outputPath;
638
+ }
639
+ copyTraceViewerAssets(skip) {
640
+ if (skip) return;
641
+ const traceViewerFolder = path3.join(
642
+ __require.resolve("playwright-core"),
643
+ "..",
644
+ "lib",
645
+ "vite",
646
+ "traceViewer"
647
+ );
648
+ const traceViewerTargetFolder = path3.join(this.folderPath, "trace");
649
+ const traceViewerAssetsTargetFolder = path3.join(
650
+ traceViewerTargetFolder,
651
+ "assets"
652
+ );
653
+ fs2.mkdirSync(traceViewerAssetsTargetFolder, { recursive: true });
654
+ for (const file of fs2.readdirSync(traceViewerFolder)) {
655
+ if (file.endsWith(".map") || file.includes("watch") || file.includes("assets"))
656
+ continue;
657
+ fs2.copyFileSync(
658
+ path3.join(traceViewerFolder, file),
659
+ path3.join(traceViewerTargetFolder, file)
660
+ );
661
+ }
662
+ const assetsFolder = path3.join(traceViewerFolder, "assets");
663
+ for (const file of fs2.readdirSync(assetsFolder)) {
664
+ if (file.endsWith(".map") || file.includes("xtermModule")) continue;
665
+ fs2.copyFileSync(
666
+ path3.join(assetsFolder, file),
667
+ path3.join(traceViewerAssetsTargetFolder, file)
668
+ );
669
+ }
670
+ }
671
+ };
672
+
673
+ // src/utils/expressServer.ts
674
+ import express from "express";
675
+ import path4 from "path";
676
+ import { spawn } from "child_process";
677
+ function startReportServer(reportFolder, reportFilename, port = 2004, open2) {
678
+ const app = express();
679
+ app.use(express.static(reportFolder, { index: false }));
680
+ app.get("/", (_req, res) => {
681
+ try {
682
+ res.sendFile(path4.resolve(reportFolder, reportFilename));
683
+ } catch (error) {
684
+ console.error("Ortoni Report: Error sending report file:", error);
685
+ res.status(500).send("Error loading report");
686
+ }
687
+ });
688
+ try {
689
+ const server = app.listen(port, () => {
690
+ console.log(
691
+ `Server is running at http://localhost:${port}
692
+ Press Ctrl+C to stop.`
693
+ );
694
+ if (open2 === "always" || open2 === "on-failure") {
695
+ try {
696
+ openBrowser(`http://localhost:${port}`);
697
+ } catch (error) {
698
+ console.error("Ortoni Report: Error opening browser:", error);
699
+ }
700
+ }
701
+ });
702
+ server.on("error", (error) => {
703
+ if (error.code === "EADDRINUSE") {
704
+ console.error(
705
+ `Ortoni Report: Port ${port} is already in use. Trying a different port...`
706
+ );
707
+ } else {
708
+ console.error("Ortoni Report: Server error:", error);
709
+ }
710
+ });
711
+ } catch (error) {
712
+ console.error("Ortoni Report: Error starting the server:", error);
713
+ }
714
+ }
715
+ function openBrowser(url) {
716
+ const platform = process.platform;
717
+ let command;
718
+ try {
719
+ if (platform === "win32") {
720
+ command = "cmd";
721
+ spawn(command, ["/c", "start", url]);
722
+ } else if (platform === "darwin") {
723
+ command = "open";
724
+ spawn(command, [url]);
725
+ } else {
726
+ command = "xdg-open";
727
+ spawn(command, [url]);
728
+ }
729
+ } catch (error) {
730
+ console.error("Ortoni Report: Error opening the browser:", error);
731
+ }
732
+ }
733
+
734
+ export {
735
+ __publicField,
736
+ normalizeFilePath,
737
+ ensureHtmlExtension,
738
+ escapeHtml,
739
+ extractSuites,
740
+ DatabaseManager,
741
+ HTMLGenerator,
742
+ FileManager,
743
+ startReportServer
631
744
  };