Skip to content

Commit d5ff664

Browse files
committed
adding new variable for code clarity
1 parent b777462 commit d5ff664

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

browserstack-report-action/dist/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38681,15 +38681,18 @@ class ReportProcessor {
3868138681
const { summary } = core;
3868238682
await summary.addHeading('BrowserStack Test Report');
3868338683

38684-
if (this.reportData?.report?.basicHtml) {
38685-
await summary.addRaw(`<html>${this.reportData.report.basicHtml}</html>`);
38684+
const addToSummaryReport = this.reportData?.report?.basicHtml;
38685+
if (addToSummaryReport) {
38686+
await summary.addRaw(`<html>${addToSummaryReport}</html>`);
3868638687
} else {
3868738688
await summary.addRaw('⚠️ No report content available');
3868838689
}
3868938690
summary.write();
38690-
if (this.reportData?.report?.richHtml) {
38691-
const report = `<!DOCTYPE html> <html><head><style>${this.reportData?.report?.richCss}</style></head> ${this.reportData?.report?.richHtml}</html>`;
38692-
const artifactObj = new UploadFileForArtifact(report);
38691+
const addToArtifactReport = this.reportData?.report?.richHtml;
38692+
const addToArtifactReportCss = this.reportData?.report?.richCss;
38693+
if (addToArtifactReport) {
38694+
const report = `<!DOCTYPE html> <html><head><style>${addToArtifactReportCss}</style></head> ${addToArtifactReport}}</html>`;
38695+
const artifactObj = new UploadFileForArtifact(report, 'browserstack-artifacts', 'browserstack-report.html', 'BrowserStack Test Report');
3869338696
await artifactObj.saveReportInFile();
3869438697
}
3869538698
} catch (error) {
@@ -38844,8 +38847,11 @@ const path = __nccwpck_require__(6928);
3884438847
const core = __nccwpck_require__(7484);
3884538848

3884638849
class UploadFileForArtifact {
38847-
constructor(report) {
38850+
constructor(report, pathName, fileName, artifactName) {
3884838851
this.report = report;
38852+
this.pathName = pathName;
38853+
this.fileName = fileName;
38854+
this.artifactName = artifactName;
3884938855
}
3885038856

3885138857
async saveReportInFile() {
@@ -38855,17 +38861,14 @@ class UploadFileForArtifact {
3885538861
}
3885638862

3885738863
try {
38858-
const pathName = "browserstack-reports-artifact";
38859-
const fileName = `bstack-report.html`;
38860-
const artifactName = "browserstack-report";
3886138864
// Create artifacts directory
38862-
fs.mkdirSync(pathName, { recursive: true });
38865+
fs.mkdirSync(this.pathName, { recursive: true });
3886338866
// save path in a env variable
38864-
core.exportVariable('BROWSERSTACK_REPORT_PATH', pathName);
38865-
core.exportVariable("BROWSERSTACK_REPORT_NAME", artifactName);
38867+
core.exportVariable('BROWSERSTACK_REPORT_PATH', this.pathName);
38868+
core.exportVariable("BROWSERSTACK_REPORT_NAME", this.artifactName);
3886638869

3886738870
// Write content
38868-
fs.writeFileSync(path.join(pathName, fileName), this.report);
38871+
fs.writeFileSync(path.join(this.pathName, this.fileName), this.report);
3886938872
} catch (error) {
3887038873
core.warning(`Failed to save file: ${error.message}`);
3887138874
return '';

browserstack-report-action/src/services/ReportProcessor.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ class ReportProcessor {
1111
const { summary } = core;
1212
await summary.addHeading('BrowserStack Test Report');
1313

14-
if (this.reportData?.report?.basicHtml) {
15-
await summary.addRaw(`<html>${this.reportData.report.basicHtml}</html>`);
14+
const addToSummaryReport = this.reportData?.report?.basicHtml;
15+
if (addToSummaryReport) {
16+
await summary.addRaw(`<html>${addToSummaryReport}</html>`);
1617
} else {
1718
await summary.addRaw('⚠️ No report content available');
1819
}
1920
summary.write();
20-
if (this.reportData?.report?.richHtml) {
21-
const report = `<!DOCTYPE html> <html><head><style>${this.reportData?.report?.richCss}</style></head> ${this.reportData?.report?.richHtml}</html>`;
22-
const artifactObj = new UploadFileForArtifact(report);
21+
const addToArtifactReport = this.reportData?.report?.richHtml;
22+
const addToArtifactReportCss = this.reportData?.report?.richCss;
23+
if (addToArtifactReport) {
24+
const report = `<!DOCTYPE html> <html><head><style>${addToArtifactReportCss}</style></head> ${addToArtifactReport}}</html>`;
25+
const artifactObj = new UploadFileForArtifact(report, 'browserstack-artifacts', 'browserstack-report.html', 'BrowserStack Test Report');
2326
await artifactObj.saveReportInFile();
2427
}
2528
} catch (error) {

browserstack-report-action/src/utils/UploadFileForArtifact.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ const path = require('path');
33
const core = require('@actions/core');
44

55
class UploadFileForArtifact {
6-
constructor(report) {
6+
constructor(report, pathName, fileName, artifactName) {
77
this.report = report;
8+
this.pathName = pathName;
9+
this.fileName = fileName;
10+
this.artifactName = artifactName;
811
}
912

1013
async saveReportInFile() {
@@ -14,17 +17,14 @@ class UploadFileForArtifact {
1417
}
1518

1619
try {
17-
const pathName = "browserstack-reports-artifact";
18-
const fileName = `bstack-report.html`;
19-
const artifactName = "browserstack-report";
2020
// Create artifacts directory
21-
fs.mkdirSync(pathName, { recursive: true });
21+
fs.mkdirSync(this.pathName, { recursive: true });
2222
// save path in a env variable
23-
core.exportVariable('BROWSERSTACK_REPORT_PATH', pathName);
24-
core.exportVariable("BROWSERSTACK_REPORT_NAME", artifactName);
23+
core.exportVariable('BROWSERSTACK_REPORT_PATH', this.pathName);
24+
core.exportVariable("BROWSERSTACK_REPORT_NAME", this.artifactName);
2525

2626
// Write content
27-
fs.writeFileSync(path.join(pathName, fileName), this.report);
27+
fs.writeFileSync(path.join(this.pathName, this.fileName), this.report);
2828
} catch (error) {
2929
core.warning(`Failed to save file: ${error.message}`);
3030
return '';

0 commit comments

Comments
 (0)