mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 14:57:09 +01:00
test: write integration test for pytest
This commit is contained in:
parent
60eba29d80
commit
3ec78ee9ff
2 changed files with 79 additions and 1 deletions
78
__tests__/integration.test.ts
Normal file
78
__tests__/integration.test.ts
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
import fs from 'fs'
|
||||||
|
import {LocalFileProvider} from '../src/input-providers/local-file-provider'
|
||||||
|
|
||||||
|
const input: Record<string, string> = {
|
||||||
|
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'
|
||||||
|
})
|
||||||
|
]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -124,7 +124,7 @@ export class PytestJunitParser implements TestParser {
|
||||||
private getAbsolutePath(path: string): string {
|
private getAbsolutePath(path: string): string {
|
||||||
const relativePath = this.getRelativePath(path)
|
const relativePath = this.getRelativePath(path)
|
||||||
for (const file of this.options.trackedFiles) {
|
for (const file of this.options.trackedFiles) {
|
||||||
if (file.endsWith(relativePath)) {
|
if (relativePath.endsWith(file)) {
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue