mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 06:47:09 +01:00
refactor: improve getWorkDir() implementation
This commit is contained in:
parent
33125699e3
commit
cdfbf90a4e
4 changed files with 16 additions and 11 deletions
|
|
@ -30,7 +30,6 @@ describe('pytest-junit tests', () => {
|
|||
|
||||
const opts: ParseOptions = {
|
||||
parseErrors: true,
|
||||
workDir: 'mnt/extra-addons',
|
||||
trackedFiles: ['addons/product_changes/tests/first_test.py']
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ inputs:
|
|||
- flutter-json
|
||||
- java-junit
|
||||
- jest-junit
|
||||
- pytest-junit
|
||||
- mocha-json
|
||||
required: true
|
||||
list-suites:
|
||||
|
|
|
|||
|
|
@ -69,9 +69,10 @@ export function getAnnotations(results: TestRunResult[], maxCount: number): Anno
|
|||
errors.splice(maxCount + 1)
|
||||
|
||||
const annotations = errors.map(e => {
|
||||
const paths = e.path ? [e.path] : e.testRunPaths
|
||||
const message = [
|
||||
'Failed test found in:',
|
||||
e.testRunPaths.map(p => ` ${p}`).join('\n'),
|
||||
paths.map(p => ` ${p}`).join('\n'),
|
||||
'Error:',
|
||||
ident(fixEol(e.message), ' ')
|
||||
].join('\n')
|
||||
|
|
|
|||
|
|
@ -23,17 +23,21 @@ export function getBasePath(path: string, trackedFiles: string[]): string | unde
|
|||
return ''
|
||||
}
|
||||
|
||||
let max = ''
|
||||
for (const file of trackedFiles) {
|
||||
if (path.endsWith(file) && file.length > max.length) {
|
||||
max = file
|
||||
const pathParts = path.split('/')
|
||||
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
|
||||
}
|
||||
|
||||
const base = path.substr(0, path.length - max.length)
|
||||
return base
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue