diff --git a/__tests__/integration.test.ts b/__tests__/integration.test.ts new file mode 100644 index 0000000..d419022 --- /dev/null +++ b/__tests__/integration.test.ts @@ -0,0 +1,78 @@ +import fs from 'fs' +import {LocalFileProvider} from '../src/input-providers/local-file-provider' + +const input: Record = { + name: 'Test Results', + path: 'test-report.xml', + reporter: 'pytest-junit', + 'path-replace-backslashes': 'false', + 'list-suites': 'all', + 'list-tests': 'all', + 'max-annotations': '10', + 'fail-on-error': 'true', + 'only-summary': 'false', + token: '***' +} + +const update = jest.fn().mockReturnValue({data: {}, status: 0}) + +jest.mock('@actions/core', () => ({ + getInput: jest.fn().mockImplementation((name: string) => input[name]), + setFailed: jest.fn(), + setOutput: jest.fn(), + startGroup: jest.fn(), + endGroup: jest.fn(), + info: jest.fn(), + warning: jest.fn() +})) +jest.mock('@actions/github', () => { + return { + getOctokit: jest.fn().mockReturnValue({ + rest: { + checks: { + update, + create: jest.fn().mockReturnValue({data: {}}) + } + } + }), + context: { + eventName: '', + payload: {} + } + } +}) + +jest.mock('../src/input-providers/local-file-provider') + +describe('integration test', () => { + it('pytest', async () => { + jest.spyOn(LocalFileProvider.prototype, 'load').mockResolvedValue({ + 'report-tb-short.xml': [ + { + file: 'report-tb-short.xml', + content: fs.readFileSync(__dirname + '/fixtures/external/pytest/report-tb-short.xml', {encoding: 'utf8'}) + } + ] + }) + jest + .spyOn(LocalFileProvider.prototype, 'listTrackedFiles') + .mockResolvedValue(['addons/product_changes/tests/first_test.py']) + + await import('../src/main') + // trick to wait for the pending "main" Promise + await new Promise(resolve => setTimeout(resolve)) + + expect(update).toHaveBeenCalledTimes(1) + expect(update).toHaveBeenCalledWith( + expect.objectContaining({ + output: expect.objectContaining({ + annotations: [ + expect.objectContaining({ + path: 'addons/product_changes/tests/first_test.py' + }) + ] + }) + }) + ) + }) +}) diff --git a/src/parsers/pytest-junit/pytest-junit-parser.ts b/src/parsers/pytest-junit/pytest-junit-parser.ts index d133ab0..980986b 100644 --- a/src/parsers/pytest-junit/pytest-junit-parser.ts +++ b/src/parsers/pytest-junit/pytest-junit-parser.ts @@ -124,7 +124,7 @@ export class PytestJunitParser implements TestParser { private getAbsolutePath(path: string): string { const relativePath = this.getRelativePath(path) for (const file of this.options.trackedFiles) { - if (file.endsWith(relativePath)) { + if (relativePath.endsWith(file)) { return file } }