diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 456fbea9..e38ab280 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2020, 2022 IBM Corporation. + * Copyright (c) 2020, 2024 IBM Corporation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -489,29 +489,27 @@ export async function openReport(reportType: string, libProject?: LibertyProject const path = Path.dirname(libProject.getPath()); if (path !== undefined) { let report: any; - if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - report = Path.join(path, "target", "site", reportType + "-report.html"); - } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - report = await getGradleTestReport(libProject.path, path); - } let reportTypeLabel = reportType; if (reportType === "gradle") { reportTypeLabel = "test"; } - fs.exists(report, (exists) => { - if (exists) { - const panel = vscode.window.createWebviewPanel( - reportType, // Identifies the type of the webview. Used internally - libProject.getLabel() + " " + reportTypeLabel + " report", // Title of the panel displayed to the user - vscode.ViewColumn.Two, // Open the panel in the second window - {}, // Webview options - ); - panel.webview.html = getReport(report); // display HTML content - } else { - const message = localize("test.report.does.not.exist.run.test.first", report); - vscode.window.showInformationMessage(message); + let showErrorMessage: boolean = true; + if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { + report = getReportFile(path, "reports", reportType + ".html"); + // show the error message only if both "reports" and "site" dirs do not contain the test reports + // set to false since this will be the first location checked + showErrorMessage = false; + if (!await checkReportAndDisplay(report, reportType, reportTypeLabel, libProject, showErrorMessage)) { + report = getReportFile(path, "site", reportType + "-report.html"); + // show the error message only if both "reports" and "site" dirs do not contain the test reports + // set to true since this will be the second location checked + showErrorMessage = true; + await checkReportAndDisplay(report, reportType, reportTypeLabel, libProject, showErrorMessage); } - }); + } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { + report = await getGradleTestReport(libProject.path, path); + await checkReportAndDisplay(report, reportType, reportTypeLabel, libProject, showErrorMessage); + } } } else if (ProjectProvider.getInstance() && reportType) { showProjects(reportType, openReport, reportType); @@ -610,4 +608,41 @@ async function getLocalGradleWrapper(projectFolder: string): Promise { + return new Promise((resolve) => { + fs.exists(report, (exists) => { + if (exists) { + const panel = vscode.window.createWebviewPanel( + reportType, // Identifies the type of the webview. Used internally + libProject.getLabel() + " " + reportTypeLabel + " report", // Title of the panel displayed to the user + vscode.ViewColumn.Two, // Open the panel in the second window + {}, // Webview options + ); + panel.webview.html = getReport(report); // display HTML content + /* + For Maven projects we need to check for the test report in the 'reports' and 'site' dirs. + We only need to show the message if it is not available in both locations. + The `showErrorMessage` flag will only be set to true when checking the second location. + */ + } else if (showErrorMessage) { + const message = localize("test.report.does.not.exist.run.test.first", report); + vscode.window.showInformationMessage(message); + } + resolve(exists); + }); + }); } \ No newline at end of file diff --git a/src/test/MavenTestDevModeActions.ts b/src/test/MavenTestDevModeActions.ts index 5e34c8f6..967a0210 100755 --- a/src/test/MavenTestDevModeActions.ts +++ b/src/test/MavenTestDevModeActions.ts @@ -99,8 +99,10 @@ it('Run tests for sample maven project', async () => { it('start maven with options from liberty dashboard', async () => { const reportPath = path.join(utils.getMvnProjectPath(),"target","site","failsafe-report.html"); - const deleteReport = await utils.deleteReports(reportPath); - expect (deleteReport).to.be.true; + const alternateReportPath = path.join(utils.getMvnProjectPath(), "target", "reports", "failsafe.html"); // new path to scan for the reports + let deleteReport = await utils.deleteReports(reportPath); + let deleteAlternateReport = await utils.deleteReports(alternateReportPath); + expect (deleteReport && deleteAlternateReport).to.be.true; // both report files should either not exist or be successfully deleted await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM); await utils.setCustomParameter("-DhotTests=true"); await utils.delay(30000); @@ -111,7 +113,8 @@ it('start maven with options from liberty dashboard', async () => { { console.log("Server succuessfully started"); let checkFile = await utils.checkIfTestReportExists(reportPath); - expect (checkFile).to.be.true; + let checkAlternateFile = await utils.checkIfTestReportExists(alternateReportPath); + expect (checkFile || checkAlternateFile).to.be.true; // check both potential locations for the test report, one of them must exist await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION); const serverStopStatus= await utils.checkTerminalforServerState(constants.SERVER_STOP_STRING); if(!serverStopStatus){ @@ -129,8 +132,10 @@ it('start maven with options from liberty dashboard', async () => { it('start maven with history from liberty dashboard', async () => { const reportPath = path.join(utils.getMvnProjectPath(),"target","site","failsafe-report.html"); - const deleteReport = await utils.deleteReports(reportPath); - expect (deleteReport).to.be.true; + const alternateReportPath = path.join(utils.getMvnProjectPath(), "target", "reports", "failsafe.html"); + let deleteReport = await utils.deleteReports(reportPath); + let deleteAlternateReport = await utils.deleteReports(alternateReportPath); + expect (deleteReport && deleteAlternateReport).to.be.true; // both report files should either not exist or be successfully deleted await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM); const foundCommand = await utils.chooseCmdFromHistory("-DhotTests=true"); expect (foundCommand).to.be.true; @@ -142,7 +147,8 @@ it('start maven with history from liberty dashboard', async () => { { console.log("Server succuessfully started"); let checkFile = await utils.checkIfTestReportExists(reportPath); - expect (checkFile).to.be.true; + let checkAlternateFile = await utils.checkIfTestReportExists(alternateReportPath); + expect (checkFile || checkAlternateFile).to.be.true; // check both potential locations for the test report, one of them must exist await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION); const serverStopStatus= await utils.checkTerminalforServerState(constants.SERVER_STOP_STRING); if(!serverStopStatus){