refactor: improve getWorkDir() implementation

This commit is contained in:
Martin Fillafer 2023-03-15 16:02:05 +01:00
parent 33125699e3
commit cdfbf90a4e
4 changed files with 16 additions and 11 deletions

View file

@ -30,7 +30,6 @@ describe('pytest-junit tests', () => {
const opts: ParseOptions = { const opts: ParseOptions = {
parseErrors: true, parseErrors: true,
workDir: 'mnt/extra-addons',
trackedFiles: ['addons/product_changes/tests/first_test.py'] trackedFiles: ['addons/product_changes/tests/first_test.py']
} }

View file

@ -30,6 +30,7 @@ inputs:
- flutter-json - flutter-json
- java-junit - java-junit
- jest-junit - jest-junit
- pytest-junit
- mocha-json - mocha-json
required: true required: true
list-suites: list-suites:

View file

@ -69,9 +69,10 @@ export function getAnnotations(results: TestRunResult[], maxCount: number): Anno
errors.splice(maxCount + 1) errors.splice(maxCount + 1)
const annotations = errors.map(e => { const annotations = errors.map(e => {
const paths = e.path ? [e.path] : e.testRunPaths
const message = [ const message = [
'Failed test found in:', 'Failed test found in:',
e.testRunPaths.map(p => ` ${p}`).join('\n'), paths.map(p => ` ${p}`).join('\n'),
'Error:', 'Error:',
ident(fixEol(e.message), ' ') ident(fixEol(e.message), ' ')
].join('\n') ].join('\n')

View file

@ -23,17 +23,21 @@ export function getBasePath(path: string, trackedFiles: string[]): string | unde
return '' return ''
} }
let max = ''
for (const file of trackedFiles) { for (const file of trackedFiles) {
if (path.endsWith(file) && file.length > max.length) { const pathParts = path.split('/')
max = file const originalLength = pathParts.length
const fileParts = file.split('/')
while (pathParts.length && pathParts.slice(-1)[0] === fileParts.slice(-1)[0]) {
pathParts.pop()
fileParts.pop()
}
// we found some matching path parts
if (pathParts.length !== originalLength) {
return pathParts.join('/')
} }
} }
if (max === '') { return undefined
return undefined
}
const base = path.substr(0, path.length - max.length)
return base
} }