ortoni-report 1.0.0 → 1.0.2

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,14 @@
1
+ import { Reporter, FullConfig, Suite, TestCase, TestResult, FullResult } from '@playwright/test/reporter';
2
+
3
+ declare class OrtoniReport implements Reporter {
4
+ private results;
5
+ private groupedResults;
6
+ private suiteName;
7
+ onBegin(config: FullConfig, suite: Suite): void;
8
+ onTestBegin(test: TestCase, result: TestResult): void;
9
+ onTestEnd(test: TestCase, result: TestResult): void;
10
+ onEnd(result: FullResult): void;
11
+ generateHTML(): string;
12
+ }
13
+
14
+ export { OrtoniReport as default };
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // ortoni-report.ts
31
+ var ortoni_report_exports = {};
32
+ __export(ortoni_report_exports, {
33
+ default: () => OrtoniReport
34
+ });
35
+ module.exports = __toCommonJS(ortoni_report_exports);
36
+ var import_fs = __toESM(require("fs"));
37
+ var import_path = __toESM(require("path"));
38
+ var import_handlebars = __toESM(require("handlebars"));
39
+ var import_safe = __toESM(require("colors/safe"));
40
+ var OrtoniReport = class {
41
+ results = [];
42
+ groupedResults;
43
+ suiteName;
44
+ onBegin(config, suite) {
45
+ this.results = [];
46
+ const screenshotsDir = import_path.default.join(__dirname, "screenshots");
47
+ if (!import_fs.default.existsSync(screenshotsDir)) {
48
+ import_fs.default.mkdirSync(screenshotsDir);
49
+ }
50
+ }
51
+ onTestBegin(test, result) {
52
+ }
53
+ onTestEnd(test, result) {
54
+ console.log(test.titlePath());
55
+ const testResult = {
56
+ projectName: test.titlePath()[1],
57
+ // Get the project name
58
+ suite: test.titlePath()[3],
59
+ // Adjust the index based on your suite hierarchy
60
+ title: test.title,
61
+ status: result.status,
62
+ duration: result.duration,
63
+ errors: result.errors.map((e) => import_safe.default.strip(e.message || e.toString())),
64
+ steps: result.steps.map((step) => ({
65
+ title: step.title,
66
+ category: step.category,
67
+ duration: step.duration,
68
+ status: result.status
69
+ })),
70
+ logs: import_safe.default.strip(result.stdout.concat(result.stderr).map((log) => log).join("\n")),
71
+ screenshotPath: null,
72
+ filePath: test.titlePath()[2]
73
+ };
74
+ if (result.attachments) {
75
+ const screenshotsDir = import_path.default.join(__dirname, "screenshots\\" + test.id);
76
+ if (!import_fs.default.existsSync(screenshotsDir)) {
77
+ import_fs.default.mkdirSync(screenshotsDir);
78
+ }
79
+ const screenshot = result.attachments.find((attachment) => attachment.name === "screenshot");
80
+ if (screenshot && screenshot.path) {
81
+ const screenshotContent = import_fs.default.readFileSync(screenshot.path, "base64");
82
+ const screenshotFileName = `screenshots/${test.id}/${import_path.default.basename(screenshot.path)}`;
83
+ import_fs.default.writeFileSync(import_path.default.join(__dirname, screenshotFileName), screenshotContent, "base64");
84
+ testResult.screenshotPath = screenshotFileName;
85
+ }
86
+ }
87
+ this.results.push(testResult);
88
+ }
89
+ onEnd(result) {
90
+ this.groupedResults = this.results.reduce((acc, result2, index) => {
91
+ const filePath = result2.filePath;
92
+ const suiteName = result2.suite;
93
+ const projectName = result2.projectName;
94
+ if (!acc[filePath]) {
95
+ acc[filePath] = {};
96
+ }
97
+ if (!acc[filePath][suiteName]) {
98
+ acc[filePath][suiteName] = {};
99
+ }
100
+ if (!acc[filePath][suiteName][projectName]) {
101
+ acc[filePath][suiteName][projectName] = [];
102
+ }
103
+ acc[filePath][suiteName][projectName].push({ ...result2, index });
104
+ return acc;
105
+ }, {});
106
+ import_handlebars.default.registerHelper("json", function(context) {
107
+ return safeStringify(context);
108
+ });
109
+ import_handlebars.default.registerHelper("splitSuiteName", function(suiteName) {
110
+ return suiteName.split(" - ");
111
+ });
112
+ const html = this.generateHTML();
113
+ const outputPath = import_path.default.join(__dirname, "ortoni-report.html");
114
+ import_fs.default.writeFileSync(outputPath, html);
115
+ console.log(`Ortoni HTML report generated at ${outputPath}`);
116
+ }
117
+ generateHTML() {
118
+ const templateSource = import_fs.default.readFileSync(import_path.default.join(__dirname, "report-template.hbs"), "utf-8");
119
+ const template = import_handlebars.default.compile(templateSource);
120
+ const data = {
121
+ suiteName: this.suiteName,
122
+ results: this.results,
123
+ passCount: this.results.filter((r) => r.status === "passed").length,
124
+ failCount: this.results.filter((r) => r.status === "failed").length,
125
+ skipCount: this.results.filter((r) => r.status === "skipped").length,
126
+ retryCount: this.results.filter((r) => r.status === "retry").length,
127
+ totalCount: this.results.length,
128
+ groupedResults: this.groupedResults
129
+ };
130
+ return template(data);
131
+ }
132
+ };
133
+ function safeStringify(obj, indent = 2) {
134
+ const cache = /* @__PURE__ */ new Set();
135
+ const json = JSON.stringify(obj, (key, value) => {
136
+ if (typeof value === "object" && value !== null) {
137
+ if (cache.has(value)) {
138
+ return;
139
+ }
140
+ cache.add(value);
141
+ }
142
+ return value;
143
+ }, indent);
144
+ cache.clear();
145
+ return json;
146
+ }
@@ -0,0 +1,115 @@
1
+ // ortoni-report.ts
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import Handlebars from "handlebars";
5
+ import colors from "colors/safe";
6
+ var OrtoniReport = class {
7
+ results = [];
8
+ groupedResults;
9
+ suiteName;
10
+ onBegin(config, suite) {
11
+ this.results = [];
12
+ const screenshotsDir = path.join(__dirname, "screenshots");
13
+ if (!fs.existsSync(screenshotsDir)) {
14
+ fs.mkdirSync(screenshotsDir);
15
+ }
16
+ }
17
+ onTestBegin(test, result) {
18
+ }
19
+ onTestEnd(test, result) {
20
+ console.log(test.titlePath());
21
+ const testResult = {
22
+ projectName: test.titlePath()[1],
23
+ // Get the project name
24
+ suite: test.titlePath()[3],
25
+ // Adjust the index based on your suite hierarchy
26
+ title: test.title,
27
+ status: result.status,
28
+ duration: result.duration,
29
+ errors: result.errors.map((e) => colors.strip(e.message || e.toString())),
30
+ steps: result.steps.map((step) => ({
31
+ title: step.title,
32
+ category: step.category,
33
+ duration: step.duration,
34
+ status: result.status
35
+ })),
36
+ logs: colors.strip(result.stdout.concat(result.stderr).map((log) => log).join("\n")),
37
+ screenshotPath: null,
38
+ filePath: test.titlePath()[2]
39
+ };
40
+ if (result.attachments) {
41
+ const screenshotsDir = path.join(__dirname, "screenshots\\" + test.id);
42
+ if (!fs.existsSync(screenshotsDir)) {
43
+ fs.mkdirSync(screenshotsDir);
44
+ }
45
+ const screenshot = result.attachments.find((attachment) => attachment.name === "screenshot");
46
+ if (screenshot && screenshot.path) {
47
+ const screenshotContent = fs.readFileSync(screenshot.path, "base64");
48
+ const screenshotFileName = `screenshots/${test.id}/${path.basename(screenshot.path)}`;
49
+ fs.writeFileSync(path.join(__dirname, screenshotFileName), screenshotContent, "base64");
50
+ testResult.screenshotPath = screenshotFileName;
51
+ }
52
+ }
53
+ this.results.push(testResult);
54
+ }
55
+ onEnd(result) {
56
+ this.groupedResults = this.results.reduce((acc, result2, index) => {
57
+ const filePath = result2.filePath;
58
+ const suiteName = result2.suite;
59
+ const projectName = result2.projectName;
60
+ if (!acc[filePath]) {
61
+ acc[filePath] = {};
62
+ }
63
+ if (!acc[filePath][suiteName]) {
64
+ acc[filePath][suiteName] = {};
65
+ }
66
+ if (!acc[filePath][suiteName][projectName]) {
67
+ acc[filePath][suiteName][projectName] = [];
68
+ }
69
+ acc[filePath][suiteName][projectName].push({ ...result2, index });
70
+ return acc;
71
+ }, {});
72
+ Handlebars.registerHelper("json", function(context) {
73
+ return safeStringify(context);
74
+ });
75
+ Handlebars.registerHelper("splitSuiteName", function(suiteName) {
76
+ return suiteName.split(" - ");
77
+ });
78
+ const html = this.generateHTML();
79
+ const outputPath = path.join(__dirname, "ortoni-report.html");
80
+ fs.writeFileSync(outputPath, html);
81
+ console.log(`Ortoni HTML report generated at ${outputPath}`);
82
+ }
83
+ generateHTML() {
84
+ const templateSource = fs.readFileSync(path.join(__dirname, "report-template.hbs"), "utf-8");
85
+ const template = Handlebars.compile(templateSource);
86
+ const data = {
87
+ suiteName: this.suiteName,
88
+ results: this.results,
89
+ passCount: this.results.filter((r) => r.status === "passed").length,
90
+ failCount: this.results.filter((r) => r.status === "failed").length,
91
+ skipCount: this.results.filter((r) => r.status === "skipped").length,
92
+ retryCount: this.results.filter((r) => r.status === "retry").length,
93
+ totalCount: this.results.length,
94
+ groupedResults: this.groupedResults
95
+ };
96
+ return template(data);
97
+ }
98
+ };
99
+ function safeStringify(obj, indent = 2) {
100
+ const cache = /* @__PURE__ */ new Set();
101
+ const json = JSON.stringify(obj, (key, value) => {
102
+ if (typeof value === "object" && value !== null) {
103
+ if (cache.has(value)) {
104
+ return;
105
+ }
106
+ cache.add(value);
107
+ }
108
+ return value;
109
+ }, indent);
110
+ cache.clear();
111
+ return json;
112
+ }
113
+ export {
114
+ OrtoniReport as default
115
+ };
@@ -162,7 +162,7 @@
162
162
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.0/chart.min.js"></script>
163
163
  <script>
164
164
  document.addEventListener('DOMContentLoaded', () => {
165
- const testData = {{{ json results }}};
165
+ const testData = {{{ json results }}};
166
166
  const testDetails = document.getElementById('testDetails');
167
167
  const summary = document.getElementById('summary');
168
168
  const backButton = document.querySelector('.back-button');
package/ortoni-report.ts CHANGED
@@ -8,8 +8,8 @@ import type {
8
8
  } from '@playwright/test/reporter';
9
9
 
10
10
  interface TestResultData {
11
- projectName: string;
12
- suite: string;
11
+ projectName: any;
12
+ suite: any;
13
13
  title: string;
14
14
  status: string;
15
15
  duration: number;
@@ -17,7 +17,7 @@ interface TestResultData {
17
17
  steps: any[];
18
18
  logs: string;
19
19
  screenshotPath: string | null;
20
- filePath: string
20
+ filePath: any;
21
21
  }
22
22
  export default class OrtoniReport implements Reporter {
23
23
  private results: TestResultData[] = [];
@@ -101,9 +101,9 @@ export default class OrtoniReport implements Reporter {
101
101
  return suiteName.split(' - ');
102
102
  });
103
103
  const html = this.generateHTML();
104
- const outputPath = path.join(__dirname, 'advanced-playwright-report.html');
104
+ const outputPath = path.join(__dirname, 'ortoni-report.html');
105
105
  fs.writeFileSync(outputPath, html);
106
- console.log(`Advanced HTML report generated at ${outputPath}`);
106
+ console.log(`Ortoni HTML report generated at ${outputPath}`);
107
107
  }
108
108
  generateHTML() {
109
109
  const templateSource = fs.readFileSync(path.join(__dirname, 'report-template.hbs'), 'utf-8');
package/package.json CHANGED
@@ -1,25 +1,22 @@
1
1
  {
2
2
  "name": "ortoni-report",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Playwright Report By LetCode Koushik",
5
- "main": "index.js",
6
5
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
6
+ "build": "tsup ortoni-report.ts --format cjs,esm --dts",
7
+ "release": "npm publish",
8
+ "lint": "tsc"
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
11
12
  "url": "git+https://github.com/ortoniKC/letcode-pw-report.git"
12
13
  },
13
14
  "keywords": [
14
- "playwright",
15
- "playwright",
16
- "report",
17
- "letcode",
18
- "koushik",
19
- "report",
20
- "ortoni",
21
- "ortoni",
22
- "report"
15
+ "playwright report",
16
+ "playwright letcode",
17
+ "letcode koushik",
18
+ "ortoni report",
19
+ "ortoni"
23
20
  ],
24
21
  "author": "Koushik Chatterjee (LetCode with Koushik)",
25
22
  "license": "ISC",
@@ -34,6 +31,12 @@
34
31
  },
35
32
  "devDependencies": {
36
33
  "@playwright/test": "^1.44.1",
37
- "@types/node": "^20.14.2"
38
- }
34
+ "@types/node": "^20.14.2",
35
+ "@changesets/cli": "^2.26.0",
36
+ "tsup": "^6.5.0",
37
+ "typescript": "^4.9.4"
38
+ },
39
+ "main": "dist/ortoni-report.js",
40
+ "module": "dist/ortoni-report.mjs",
41
+ "types": "dist/ortoni-report.d.ts"
39
42
  }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Base Options: */
4
+ "moduleResolution":"Node",
5
+ "esModuleInterop": true,
6
+ "skipLibCheck": true,
7
+ "target": "es2022",
8
+ "allowJs": true,
9
+ "moduleDetection": "force",
10
+ /* Strictness */
11
+ "strict": true,
12
+ "noUncheckedIndexedAccess": true,
13
+ /* If NOT transpiling with TypeScript: */
14
+ "module": "ESNext",
15
+ "noEmit": true,
16
+ /* If your code runs in the DOM: */
17
+ "lib": ["es2022", "dom", "dom.iterable"],
18
+ }
19
+ }