diff --git a/__tests__/pytest-junit.test.ts b/__tests__/pytest-junit.test.ts index d618822..629c41b 100644 --- a/__tests__/pytest-junit.test.ts +++ b/__tests__/pytest-junit.test.ts @@ -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'] } diff --git a/action.yml b/action.yml index 325e2c4..37c1637 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,7 @@ inputs: - flutter-json - java-junit - jest-junit + - pytest-junit - mocha-json required: true list-suites: diff --git a/src/report/get-annotations.ts b/src/report/get-annotations.ts index 1b3e8aa..a7fafb7 100644 --- a/src/report/get-annotations.ts +++ b/src/report/get-annotations.ts @@ -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') diff --git a/src/utils/path-utils.ts b/src/utils/path-utils.ts index 91f1784..e0dbbc8 100644 --- a/src/utils/path-utils.ts +++ b/src/utils/path-utils.ts @@ -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 + return undefined }