From 33125699e3a154c2edfc2c0a239cdd47f7618ffb Mon Sep 17 00:00:00 2001 From: Martin Fillafer Date: Tue, 14 Mar 2023 11:40:21 +0100 Subject: [PATCH] feat: consider tracked files to get absolute paths --- __tests__/pytest-junit.test.ts | 4 ++-- dist/index.js | 11 ++++++++++- src/parsers/pytest-junit/pytest-junit-parser.ts | 12 +++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/__tests__/pytest-junit.test.ts b/__tests__/pytest-junit.test.ts index b1f06df..d618822 100644 --- a/__tests__/pytest-junit.test.ts +++ b/__tests__/pytest-junit.test.ts @@ -31,7 +31,7 @@ describe('pytest-junit tests', () => { const opts: ParseOptions = { parseErrors: true, workDir: 'mnt/extra-addons', - trackedFiles: ['mnt/extra-addons/product_changes/tests/first_test.py'] + trackedFiles: ['addons/product_changes/tests/first_test.py'] } const parser = new PytestJunitParser(opts) @@ -45,6 +45,6 @@ describe('pytest-junit tests', () => { const annotations = getAnnotations([result], 1) expect(annotations.length).toBe(1) - expect(annotations[0].path).toBe('product_changes/tests/first_test.py') + expect(annotations[0].path).toBe('addons/product_changes/tests/first_test.py') }) }) diff --git a/dist/index.js b/dist/index.js index a6fbec0..415ff2b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1494,7 +1494,7 @@ class PytestJunitParser { const line = Number.parseInt(pos); if (path && Number.isFinite(line)) { return { - path: this.getRelativePath(path), + path: this.getAbsolutePath(path), line, message: lines[1] }; @@ -1509,6 +1509,15 @@ class PytestJunitParser { } return path; } + getAbsolutePath(path) { + const relativePath = this.getRelativePath(path); + for (const file of this.options.trackedFiles) { + if (file.endsWith(relativePath)) { + return file; + } + } + return relativePath; + } getWorkDir(path) { var _a, _b; return ((_b = (_a = this.options.workDir) !== null && _a !== void 0 ? _a : this.assumedWorkDir) !== null && _b !== void 0 ? _b : (this.assumedWorkDir = (0, path_utils_1.getBasePath)(path, this.options.trackedFiles))); diff --git a/src/parsers/pytest-junit/pytest-junit-parser.ts b/src/parsers/pytest-junit/pytest-junit-parser.ts index 41e9932..d133ab0 100644 --- a/src/parsers/pytest-junit/pytest-junit-parser.ts +++ b/src/parsers/pytest-junit/pytest-junit-parser.ts @@ -103,7 +103,7 @@ export class PytestJunitParser implements TestParser { if (path && Number.isFinite(line)) { return { - path: this.getRelativePath(path), + path: this.getAbsolutePath(path), line, message: lines[1] } @@ -121,6 +121,16 @@ export class PytestJunitParser implements TestParser { return path } + private getAbsolutePath(path: string): string { + const relativePath = this.getRelativePath(path) + for (const file of this.options.trackedFiles) { + if (file.endsWith(relativePath)) { + return file + } + } + return relativePath + } + private getWorkDir(path: string): string | undefined { return ( this.options.workDir ??