@arghajit/playwright-pulse-report 0.2.9 → 0.3.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/README.md +40 -0
- package/dist/reporter/playwright-pulse-reporter.js +5 -4
- package/dist/types/index.d.ts +9 -0
- package/package.json +4 -3
- package/scripts/config-reader.mjs +132 -0
- package/scripts/generate-email-report.mjs +21 -1
- package/scripts/generate-report.mjs +525 -274
- package/scripts/generate-static-report.mjs +267 -51
- package/scripts/generate-trend.mjs +11 -1
- package/scripts/merge-pulse-report.js +46 -14
- package/scripts/sendReport.mjs +36 -21
package/scripts/sendReport.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import { fileURLToPath } from "url";
|
|
11
11
|
import { fork } from "child_process"; // This was missing in your sendReport.js but present in generate-email-report.js and needed for runScript
|
|
12
12
|
import "dotenv/config"; // CHANGED for dotenv
|
|
13
|
+
import { getOutputDir } from "./config-reader.mjs";
|
|
13
14
|
|
|
14
15
|
// Import chalk using top-level await if your Node version supports it (14.8+)
|
|
15
16
|
// or keep the dynamic import if preferred, but ensure chalk is resolved before use.
|
|
@@ -28,7 +29,14 @@ try {
|
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
const
|
|
32
|
+
const args = process.argv.slice(2);
|
|
33
|
+
let customOutputDir = null;
|
|
34
|
+
for (let i = 0; i < args.length; i++) {
|
|
35
|
+
if (args[i] === "--outputDir" || args[i] === "-o") {
|
|
36
|
+
customOutputDir = args[i + 1];
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
32
40
|
|
|
33
41
|
let fetch;
|
|
34
42
|
// Ensure fetch is imported and available before it's used in fetchCredentials
|
|
@@ -40,11 +48,8 @@ let fetch;
|
|
|
40
48
|
|
|
41
49
|
let projectName;
|
|
42
50
|
|
|
43
|
-
function getUUID() {
|
|
44
|
-
const reportPath = path.join(
|
|
45
|
-
process.cwd(),
|
|
46
|
-
`${reportDir}/playwright-pulse-report.json`
|
|
47
|
-
);
|
|
51
|
+
function getUUID(reportDir) {
|
|
52
|
+
const reportPath = path.join(reportDir, "playwright-pulse-report.json");
|
|
48
53
|
console.log("Report path:", reportPath);
|
|
49
54
|
|
|
50
55
|
if (!fsExistsSync(reportPath)) {
|
|
@@ -71,18 +76,15 @@ const formatStartTime = (isoString) => {
|
|
|
71
76
|
return date.toLocaleString(); // Default locale
|
|
72
77
|
};
|
|
73
78
|
|
|
74
|
-
const getPulseReportSummary = () => {
|
|
75
|
-
const reportPath = path.join(
|
|
76
|
-
process.cwd(),
|
|
77
|
-
`${reportDir}/playwright-pulse-report.json`
|
|
78
|
-
);
|
|
79
|
+
const getPulseReportSummary = (reportDir) => {
|
|
80
|
+
const reportPath = path.join(reportDir, "playwright-pulse-report.json");
|
|
79
81
|
|
|
80
82
|
if (!fsExistsSync(reportPath)) {
|
|
81
83
|
// CHANGED
|
|
82
84
|
throw new Error("Pulse report file not found.");
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
const content = JSON.parse(fsReadFileSync(reportPath, "utf-8")); //
|
|
87
|
+
const content = JSON.parse(fsReadFileSync(reportPath, "utf-8")); // D
|
|
86
88
|
const run = content.run;
|
|
87
89
|
|
|
88
90
|
const total = run.totalTests || 0;
|
|
@@ -220,9 +222,9 @@ const archiveRunScriptPath = path.resolve(
|
|
|
220
222
|
"generate-email-report.mjs" // Or input_file_0.mjs if you rename it, or input_file_0.js if you configure package.json
|
|
221
223
|
);
|
|
222
224
|
|
|
223
|
-
async function runScript(scriptPath) {
|
|
225
|
+
async function runScript(scriptPath, args = []) {
|
|
224
226
|
return new Promise((resolve, reject) => {
|
|
225
|
-
const childProcess = fork(scriptPath,
|
|
227
|
+
const childProcess = fork(scriptPath, args, {
|
|
226
228
|
// Renamed variable
|
|
227
229
|
stdio: "inherit",
|
|
228
230
|
});
|
|
@@ -244,8 +246,9 @@ async function runScript(scriptPath) {
|
|
|
244
246
|
});
|
|
245
247
|
}
|
|
246
248
|
|
|
247
|
-
const sendEmail = async (credentials) => {
|
|
248
|
-
|
|
249
|
+
const sendEmail = async (credentials, reportDir) => {
|
|
250
|
+
const archiveArgs = customOutputDir ? ["--outputDir", customOutputDir] : [];
|
|
251
|
+
await runScript(archiveRunScriptPath, archiveArgs);
|
|
249
252
|
try {
|
|
250
253
|
console.log("Starting the sendEmail function...");
|
|
251
254
|
|
|
@@ -259,7 +262,7 @@ const sendEmail = async (credentials) => {
|
|
|
259
262
|
},
|
|
260
263
|
});
|
|
261
264
|
|
|
262
|
-
const reportData = getPulseReportSummary();
|
|
265
|
+
const reportData = getPulseReportSummary(reportDir);
|
|
263
266
|
const htmlContent = generateHtmlTable(reportData);
|
|
264
267
|
|
|
265
268
|
const mailOptions = {
|
|
@@ -289,7 +292,7 @@ const sendEmail = async (credentials) => {
|
|
|
289
292
|
}
|
|
290
293
|
};
|
|
291
294
|
|
|
292
|
-
async function fetchCredentials(retries = 10) {
|
|
295
|
+
async function fetchCredentials(reportDir, retries = 10) {
|
|
293
296
|
// Ensure fetch is initialized from the dynamic import before calling this
|
|
294
297
|
if (!fetch) {
|
|
295
298
|
try {
|
|
@@ -304,7 +307,7 @@ async function fetchCredentials(retries = 10) {
|
|
|
304
307
|
}
|
|
305
308
|
|
|
306
309
|
const timeout = 10000;
|
|
307
|
-
const key = getUUID();
|
|
310
|
+
const key = getUUID(reportDir);
|
|
308
311
|
|
|
309
312
|
if (!key) {
|
|
310
313
|
console.error(
|
|
@@ -384,7 +387,19 @@ const main = async () => {
|
|
|
384
387
|
}
|
|
385
388
|
}
|
|
386
389
|
|
|
387
|
-
const
|
|
390
|
+
const reportDir = await getOutputDir(customOutputDir);
|
|
391
|
+
|
|
392
|
+
console.log(chalk.blue(`Preparing to send email report...`));
|
|
393
|
+
console.log(chalk.blue(`Report directory set to: ${reportDir}`));
|
|
394
|
+
if (customOutputDir) {
|
|
395
|
+
console.log(chalk.gray(` (from CLI argument)`));
|
|
396
|
+
} else {
|
|
397
|
+
console.log(
|
|
398
|
+
chalk.gray(` (auto-detected from playwright.config or using default)`)
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const credentials = await fetchCredentials(reportDir);
|
|
388
403
|
if (!credentials) {
|
|
389
404
|
console.warn(
|
|
390
405
|
"Skipping email sending due to missing or failed credential fetch"
|
|
@@ -393,7 +408,7 @@ const main = async () => {
|
|
|
393
408
|
}
|
|
394
409
|
// Removed await delay(10000); // If not strictly needed, remove it.
|
|
395
410
|
try {
|
|
396
|
-
await sendEmail(credentials);
|
|
411
|
+
await sendEmail(credentials, reportDir);
|
|
397
412
|
} catch (error) {
|
|
398
413
|
console.error("Error in main function: ", error);
|
|
399
414
|
}
|