From 50bef67ef12fbfdd2ce6d24477f6448dd18acf1a Mon Sep 17 00:00:00 2001 From: Michael Corcoran <100386526+MoochaelCorcoran@users.noreply.github.com> Date: Wed, 12 Apr 2023 17:25:41 -0230 Subject: [PATCH] Add function to retrieve nested project settings (#32) LGTM --- src/ResultsParser.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/ResultsParser.ts b/src/ResultsParser.ts index 7b63ceb..b2d56dc 100644 --- a/src/ResultsParser.ts +++ b/src/ResultsParser.ts @@ -102,19 +102,14 @@ export default class ResultsParser { addTestResult(suiteName: any, testCase: any) { const testResults: testResult[] = []; + const projectSettings = this.getParentConfigInformation(testCase); for (const result of testCase.results) { testResults.push({ suiteName, name: testCase.title, status: result.status, - // eslint-disable-next-line no-underscore-dangle - browser: testCase.parent?.parent?._projectConfig?.use?.defaultBrowserType - ? testCase.parent.parent._projectConfig.use.defaultBrowserType - : '', - // eslint-disable-next-line no-underscore-dangle - projectName: testCase.parent?.parent?._projectConfig?.name - ? testCase.parent.parent._projectConfig.name - : '', + browser: projectSettings.browser, + projectName: projectSettings.projectName, retry: result.retry, retries: testCase.retries, startedAt: new Date(result.startTime).toISOString(), @@ -171,4 +166,16 @@ export default class ResultsParser { ); return logsStripped; } + + getParentConfigInformation(testCase: any): {projectName: string, browser: string} { + if (testCase._projectConfig !== undefined) { + return { + projectName: testCase._projectConfig.name || '', + browser: testCase._projectConfig.use?.defaultBrowserType || '', + }; + } if (testCase.parent) { + return this.getParentConfigInformation(testCase.parent); + } + return { projectName: '', browser: '' }; + } }