-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from currents-dev/feat/migrate-fulltestsuite-…
…convert [CSR-2066] feat: added full test suite generation for convert command
- Loading branch information
Showing
14 changed files
with
183 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
FullSuiteProject, | ||
FullSuiteTest, | ||
FullTestSuite, | ||
} from '../upload/discovery'; | ||
import { TestCase, TestSuite, TestSuites } from './types'; | ||
import { | ||
ensureArray, | ||
generateTestId, | ||
getSuiteName, | ||
getTestTitle, | ||
} from './utils'; | ||
|
||
export function createFullTestSuite(parsedXMLInputs: TestSuites[]) { | ||
const fullTestSuite: FullTestSuite = []; | ||
|
||
parsedXMLInputs.forEach((item) => { | ||
const testsuites = ensureArray<TestSuite>(item.testsuites?.testsuite); | ||
|
||
const fullSuiteProject: FullSuiteProject = { | ||
name: item.testsuites?.name ?? 'No name', | ||
tags: [], | ||
tests: [], | ||
}; | ||
|
||
testsuites?.forEach((suite) => { | ||
const suiteName = getSuiteName(suite, testsuites); | ||
const testcases = ensureArray<TestCase>(suite?.testcase); | ||
|
||
testcases?.forEach((testcase) => { | ||
const fullSuiteTest: FullSuiteTest = { | ||
title: getTestTitle(testcase.name, suiteName), | ||
spec: suiteName, | ||
tags: [], | ||
testId: generateTestId( | ||
getTestTitle(testcase.name, suiteName).join(', '), | ||
suiteName | ||
), | ||
}; | ||
|
||
fullSuiteProject.tests.push(fullSuiteTest); | ||
}); | ||
}); | ||
fullTestSuite.push(fullSuiteProject); | ||
}); | ||
|
||
return fullTestSuite; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { debug } from '@debug'; | ||
import { warn } from '@logger'; | ||
import { readFile } from 'fs-extra'; | ||
import { parseStringPromise } from 'xml2js'; | ||
import { TestSuites } from './types'; | ||
|
||
export async function getParsedXMLArray( | ||
inputFiles: string[] | ||
): Promise<TestSuites[]> { | ||
const filesData: string[] = await Promise.all( | ||
inputFiles.map((item) => readFile(item, 'utf-8')) | ||
); | ||
|
||
const parsedXMLInputs = ( | ||
await Promise.all(filesData.map(getParsedXMLInput)) | ||
).filter(Boolean); | ||
|
||
if (filesData.length !== parsedXMLInputs.length) { | ||
warn( | ||
'Some files could not be parsed. Enable debug logging for more details' | ||
); | ||
} | ||
|
||
return parsedXMLInputs; | ||
} | ||
|
||
async function getParsedXMLInput(XMLString: string) { | ||
const trimmedXMLString = XMLString.trim(); | ||
if (!trimmedXMLString) return null; | ||
|
||
try { | ||
const parsedXMLInput = await parseStringPromise(trimmedXMLString, { | ||
explicitArray: false, | ||
mergeAttrs: true, | ||
}); | ||
return parsedXMLInput || null; | ||
} catch (e) { | ||
debug('Error parsing XML input', e); | ||
return null; | ||
} | ||
} |
Oops, something went wrong.