@arghajit/dummy 0.1.0-beta-20 → 0.1.0-beta-21

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.
@@ -11,6 +11,7 @@ export declare class PlaywrightPulseReporter implements Reporter {
11
11
  private baseOutputFile;
12
12
  private isSharded;
13
13
  private shardIndex;
14
+ private resetOnEachRun;
14
15
  constructor(options?: PlaywrightPulseReporterOptions);
15
16
  printsToStdio(): boolean;
16
17
  onBegin(config: FullConfig, suite: Suite): void;
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.PlaywrightPulseReporter = void 0;
37
37
  const fs = __importStar(require("fs/promises"));
38
38
  const path = __importStar(require("path"));
39
+ const fsSync = __importStar(require("fs"));
39
40
  const crypto_1 = require("crypto");
40
41
  const ua_parser_js_1 = require("ua-parser-js");
41
42
  const os = __importStar(require("os"));
@@ -62,7 +63,7 @@ const TEMP_SHARD_FILE_PREFIX = ".pulse-shard-results-";
62
63
  const ATTACHMENTS_SUBDIR = "attachments";
63
64
  class PlaywrightPulseReporter {
64
65
  constructor(options = {}) {
65
- var _a, _b;
66
+ var _a, _b, _c;
66
67
  this.results = [];
67
68
  this.baseOutputFile = "playwright-pulse-report.json";
68
69
  this.isSharded = false;
@@ -71,6 +72,7 @@ class PlaywrightPulseReporter {
71
72
  this.baseOutputFile = (_a = options.outputFile) !== null && _a !== void 0 ? _a : this.baseOutputFile;
72
73
  this.outputDir = (_b = options.outputDir) !== null && _b !== void 0 ? _b : "pulse-report";
73
74
  this.attachmentsDir = path.join(this.outputDir, ATTACHMENTS_SUBDIR);
75
+ this.resetOnEachRun = (_c = options.resetOnEachRun) !== null && _c !== void 0 ? _c : false;
74
76
  }
75
77
  printsToStdio() {
76
78
  return this.shardIndex === undefined || this.shardIndex === 0;
@@ -469,29 +471,118 @@ class PlaywrightPulseReporter {
469
471
  console.error("PlaywrightPulseReporter: CRITICAL - finalReport object was not generated. Cannot create summary.");
470
472
  return;
471
473
  }
472
- const finalOutputPath = path.join(this.outputDir, this.baseOutputFile);
473
- try {
474
- await this._ensureDirExists(this.outputDir);
475
- await fs.writeFile(finalOutputPath, JSON.stringify(finalReport, (key, value) => {
476
- if (value instanceof Date)
477
- return value.toISOString();
478
- if (typeof value === "bigint")
479
- return value.toString();
480
- return value;
481
- }, 2));
482
- if (this.printsToStdio()) {
483
- console.log(`PlaywrightPulseReporter: JSON report written to ${finalOutputPath}`);
474
+ if (this.resetOnEachRun == true) {
475
+ const finalOutputPath = path.join(this.outputDir, this.baseOutputFile);
476
+ try {
477
+ await this._ensureDirExists(this.outputDir);
478
+ await fs.writeFile(finalOutputPath, JSON.stringify(finalReport, (key, value) => {
479
+ if (value instanceof Date)
480
+ return value.toISOString();
481
+ if (typeof value === "bigint")
482
+ return value.toString();
483
+ return value;
484
+ }, 2));
485
+ if (this.printsToStdio()) {
486
+ console.log(`PlaywrightPulseReporter: JSON report written to ${finalOutputPath}`);
487
+ }
488
+ }
489
+ catch (error) {
490
+ console.error(`Pulse Reporter: Failed to write final JSON report to ${finalOutputPath}. Error: ${error.message}`);
491
+ }
492
+ finally {
493
+ if (this.isSharded) {
494
+ await this._cleanupTemporaryFiles();
495
+ }
484
496
  }
485
497
  }
486
- catch (error) {
487
- console.error(`Pulse Reporter: Failed to write final JSON report to ${finalOutputPath}. Error: ${error.message}`);
488
- }
489
- finally {
490
- if (this.isSharded) {
491
- await this._cleanupTemporaryFiles();
498
+ else {
499
+ console.warn("PlaywrightPulseReporter: resetOnEachRun is set to false. The finalReport will display all the results present in '/pulse-results'.");
500
+ const finalOutputPath = path.join(`${this.outputDir}/pulse-results`, `playwright-pulse-report-${Date.now()}.json`);
501
+ try {
502
+ await this._ensureDirExists(this.outputDir);
503
+ await fs.writeFile(finalOutputPath, JSON.stringify(finalReport, (key, value) => {
504
+ if (value instanceof Date)
505
+ return value.toISOString();
506
+ if (typeof value === "bigint")
507
+ return value.toString();
508
+ return value;
509
+ }, 2));
510
+ if (this.printsToStdio()) {
511
+ console.log(`PlaywrightPulseReporter: JSON report written to ${finalOutputPath}`);
512
+ }
513
+ }
514
+ catch (error) {
515
+ console.error(`Pulse Reporter: Failed to write final JSON report to ${finalOutputPath}. Error: ${error.message}`);
516
+ }
517
+ finally {
518
+ if (this.isSharded) {
519
+ await this._cleanupTemporaryFiles();
520
+ }
492
521
  }
493
522
  }
494
523
  }
495
524
  }
496
525
  exports.PlaywrightPulseReporter = PlaywrightPulseReporter;
526
+ function falseResetOnEachRun() {
527
+ const REPORT_DIR = "./pulse-report"; // Or change this to your reports directory
528
+ const OUTPUT_FILE = "playwright-pulse-report.json";
529
+ function getReportFiles(dir) {
530
+ return fsSync
531
+ .readdirSync(dir)
532
+ .filter((file) => file.startsWith("playwright-pulse-report-") && file.endsWith(".json"));
533
+ }
534
+ function mergeReports(files) {
535
+ var _a;
536
+ let combinedRun = {
537
+ totalTests: 0,
538
+ passed: 0,
539
+ failed: 0,
540
+ skipped: 0,
541
+ duration: 0,
542
+ environment: {},
543
+ };
544
+ let combinedResults = [];
545
+ let latestTimestamp = "";
546
+ let latestGeneratedAt = "";
547
+ for (const file of files) {
548
+ const filePath = path.join(`${REPORT_DIR}/pulse-results`, file);
549
+ const json = JSON.parse(fsSync.readFileSync(filePath, "utf-8"));
550
+ const run = json.run || {};
551
+ combinedRun.totalTests += run.totalTests || 0;
552
+ combinedRun.passed += run.passed || 0;
553
+ combinedRun.failed += run.failed || 0;
554
+ combinedRun.skipped += run.skipped || 0;
555
+ combinedRun.duration += run.duration || 0;
556
+ combinedRun.environment = run.environment || {};
557
+ if (json.results) {
558
+ combinedResults.push(...json.results);
559
+ }
560
+ if (run.timestamp > latestTimestamp)
561
+ latestTimestamp = run.timestamp;
562
+ if (((_a = json.metadata) === null || _a === void 0 ? void 0 : _a.generatedAt) > latestGeneratedAt)
563
+ latestGeneratedAt = json.metadata.generatedAt;
564
+ }
565
+ const finalJson = {
566
+ run: {
567
+ id: `merged-${Date.now()}`,
568
+ timestamp: latestTimestamp,
569
+ ...combinedRun,
570
+ },
571
+ results: combinedResults,
572
+ metadata: {
573
+ generatedAt: latestGeneratedAt,
574
+ },
575
+ };
576
+ return finalJson;
577
+ }
578
+ // Main execution
579
+ const reportFiles = getReportFiles(REPORT_DIR);
580
+ if (reportFiles.length === 0) {
581
+ console.log("No matching JSON report files found.");
582
+ process.exit(1);
583
+ }
584
+ const merged = mergeReports(reportFiles);
585
+ fsSync.writeFileSync(path.join(REPORT_DIR, OUTPUT_FILE), JSON.stringify(merged, null, 2));
586
+ console.log(`✅ Merged report saved as ${OUTPUT_FILE}`);
587
+ }
497
588
  exports.default = PlaywrightPulseReporter;
@@ -72,6 +72,7 @@ export interface PlaywrightPulseReporterOptions {
72
72
  outputFile?: string;
73
73
  outputDir?: string;
74
74
  base64Images?: boolean;
75
+ resetOnEachRun?: boolean;
75
76
  }
76
77
  export interface EnvDetails {
77
78
  host: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arghajit/dummy",
3
3
  "author": "Arghajit Singha",
4
- "version": "0.1.0-beta-20",
4
+ "version": "0.1.0-beta-21",
5
5
  "description": "A Playwright reporter and dashboard for visualizing test results.",
6
6
  "homepage": "https://playwright-pulse-report.netlify.app/",
7
7
  "keywords": [