@arghajit/playwright-pulse-report 0.3.0 → 0.3.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.
@@ -252,15 +252,38 @@ const sendEmail = async (credentials, reportDir) => {
252
252
  try {
253
253
  console.log("Starting the sendEmail function...");
254
254
 
255
- const secureTransporter = nodemailer.createTransport({
256
- host: "smtp.gmail.com",
257
- port: 465,
258
- secure: true,
259
- auth: {
260
- user: credentials.username,
261
- pass: credentials.password,
262
- },
263
- });
255
+ let secureTransporter;
256
+ const mailHost = credentials.host
257
+ ? credentials.host.toLowerCase()
258
+ : "gmail";
259
+
260
+ if (mailHost === "gmail") {
261
+ secureTransporter = nodemailer.createTransport({
262
+ service: "gmail",
263
+ auth: {
264
+ user: credentials.username,
265
+ pass: credentials.password,
266
+ },
267
+ });
268
+ } else if (mailHost === "outlook") {
269
+ secureTransporter = nodemailer.createTransport({
270
+ host: "smtp.outlook.com",
271
+ port: 587,
272
+ secure: false,
273
+ auth: {
274
+ user: credentials.username,
275
+ pass: credentials.password,
276
+ },
277
+ });
278
+ } else {
279
+ // Should be caught in main, but safety check here
280
+ console.log(
281
+ chalk.red(
282
+ "Pulse report currently do not support provided mail host, kindly use either outlook mail or, gmail"
283
+ )
284
+ );
285
+ process.exit(1);
286
+ }
264
287
 
265
288
  const reportData = getPulseReportSummary(reportDir);
266
289
  const htmlContent = generateHtmlTable(reportData);
@@ -399,13 +422,50 @@ const main = async () => {
399
422
  );
400
423
  }
401
424
 
402
- const credentials = await fetchCredentials(reportDir);
403
- if (!credentials) {
404
- console.warn(
405
- "Skipping email sending due to missing or failed credential fetch"
425
+ // --- MODIFIED: Credentials Selection Logic ---
426
+ let credentials;
427
+
428
+ // Check if custom environment variables are provided
429
+ if (
430
+ process.env.PULSE_MAIL_HOST &&
431
+ process.env.PULSE_MAIL_USERNAME &&
432
+ process.env.PULSE_MAIL_PASSWORD
433
+ ) {
434
+ const host = process.env.PULSE_MAIL_HOST.toLowerCase();
435
+
436
+ // Validate host immediately
437
+ if (host !== "gmail" && host !== "outlook") {
438
+ console.log(
439
+ chalk.red(
440
+ "Pulse report currently do not support provided mail host, kindly use either outlook mail or, gmail."
441
+ )
442
+ );
443
+ process.exit(1);
444
+ }
445
+
446
+ console.log(
447
+ chalk.blue(
448
+ `Using custom credentials from environment variables for ${host}.`
449
+ )
406
450
  );
407
- return;
451
+ credentials = {
452
+ username: process.env.PULSE_MAIL_USERNAME,
453
+ password: process.env.PULSE_MAIL_PASSWORD,
454
+ host: host,
455
+ };
456
+ } else {
457
+ // Fallback to existing fetch mechanism
458
+ credentials = await fetchCredentials(reportDir);
459
+ if (!credentials) {
460
+ console.warn(
461
+ "Skipping email sending due to missing or failed credential fetch"
462
+ );
463
+ return;
464
+ }
465
+ // Mark fetched credentials as gmail by default for compatibility
466
+ credentials.host = "gmail";
408
467
  }
468
+ // --- END MODIFICATION ---
409
469
  // Removed await delay(10000); // If not strictly needed, remove it.
410
470
  try {
411
471
  await sendEmail(credentials, reportDir);