Merge pull request #1 from cristidumitru/main

Add go-unit test
This commit is contained in:
Luis Penagos 2022-10-18 17:20:33 -05:00 committed by GitHub
commit 7ab3cf6aaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 184 additions and 32158 deletions

View file

@ -0,0 +1,19 @@
![Tests failed](https://img.shields.io/badge/tests-2%20passed%2C%201%20failed-critical)
## ❌ <a id="user-content-r0" href="#r0">fixtures/external/go/ginkgo-junit-report.xml</a>
**3** tests were completed in **10s** with **2** passed, **1** failed and **0** skipped.
|Test suite|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[Suite1](#r0s0)|1✔|||2ms|
|[Suite2](#r0s1)|1✔|1❌||135ms|
### ✔️ <a id="user-content-r0s0" href="#r0s0">Suite1</a>
```
Suite1
✔️ [It] Should succeed
```
### ❌ <a id="user-content-r0s1" href="#r0s1">Suite2</a>
```
Suite2
✔️ [It] Should succeed
❌ [It] Should succeed, but errors
/package2/a_test.go:52
```

View file

@ -0,0 +1,22 @@
![Tests failed](https://img.shields.io/badge/tests-2%20passed%2C%202%20failed%2C%201%20skipped-critical)
## ❌ <a id="user-content-r0" href="#r0">fixtures/external/go/go-junit-report.xml</a>
**5** tests were completed in **NaNms** with **2** passed, **2** failed and **1** skipped.
|Test suite|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[github.com/company/package1](#r0s0)||||0ms|
|[github.com/company/package2](#r0s1)|1✔|||482ms|
|[github.com/company/package3](#r0s2)|1✔|2❌|1✖|835ms|
### ✔️ <a id="user-content-r0s1" href="#r0s1">github.com/company/package2</a>
```
github.com/company/package2
✔️ TestPackage2
```
### ❌ <a id="user-content-r0s2" href="#r0s2">github.com/company/package3</a>
```
github.com/company/package3
❌ TestPackage3-1
Just error here
✔️ TestPackage3-2
✖️ TestPackage3-3
❌ TestPackage3-4
```

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="4" disabled="0" errors="0" failures="2" time="9.568500872999998">
<testsuite name="Suite1" package="/package1" tests="1" disabled="0" skipped="0" errors="0" failures="0" time="0.001759667" timestamp="2022-10-18T15:48:32">
<properties>
<property name="SuiteSucceeded" value="true"></property>
<property name="SuiteHasProgrammaticFocus" value="false"></property>
<property name="SpecialSuiteFailureReason" value=""></property>
<property name="SuiteLabels" value="[]"></property>
<property name="RandomSeed" value="1666126101"></property>
<property name="RandomizeAllSpecs" value="false"></property>
<property name="LabelFilter" value=""></property>
<property name="FocusStrings" value=""></property>
<property name="SkipStrings" value=""></property>
<property name="FocusFiles" value=""></property>
<property name="SkipFiles" value=""></property>
<property name="FailOnPending" value="false"></property>
<property name="FailFast" value="false"></property>
<property name="FlakeAttempts" value="0"></property>
<property name="EmitSpecProgress" value="false"></property>
<property name="DryRun" value="false"></property>
<property name="ParallelTotal" value="1"></property>
<property name="OutputInterceptorMode" value=""></property>
</properties>
<testcase name="[It] Should succeed" classname="Suite1" status="passed" time="0.000455833"></testcase>
</testsuite>
<testsuite name="Suite2" package="/package2" tests="3" disabled="0" skipped="0" errors="0" failures="2" time="0.135371083" timestamp="2022-10-18T15:48:32">
<properties>
<property name="SuiteSucceeded" value="true"></property>
<property name="SuiteHasProgrammaticFocus" value="false"></property>
<property name="SpecialSuiteFailureReason" value=""></property>
<property name="SuiteLabels" value="[]"></property>
<property name="RandomSeed" value="1666126101"></property>
<property name="RandomizeAllSpecs" value="false"></property>
<property name="LabelFilter" value=""></property>
<property name="FocusStrings" value=""></property>
<property name="SkipStrings" value=""></property>
<property name="FocusFiles" value=""></property>
<property name="SkipFiles" value=""></property>
<property name="FailOnPending" value="false"></property>
<property name="FailFast" value="false"></property>
<property name="FlakeAttempts" value="0"></property>
<property name="EmitSpecProgress" value="false"></property>
<property name="DryRun" value="false"></property>
<property name="ParallelTotal" value="1"></property>
<property name="OutputInterceptorMode" value=""></property>
</properties>
<testcase name="[It] Should succeed" classname="Suite2" status="passed" time="0.10459475"></testcase>
<testcase name="[It] Should succeed, but errors" classname="Suite2" status="failed" time="0.000523208">
<failure message="Expected success, but got an error:&#xA; &lt;*errors.withStack | 0x1400000ec30&gt;: {&#xA; error: &lt;*errors.withMessage | 0x1400007e7c0&gt;{&#xA; cause: &lt;*errors.fundamental | 0x14000202c60&gt;{&#xA; msg: &#34;[invalid label&#34;,&#xA; stack: [0x1056103f5, 0x104bb628c, 0x104bb61c8, 0x104ba84d8, 0x104bda0b4],&#xA; },&#xA; msg: &#34;outlier&#34;,&#xA; },&#xA; stack: [0x10560628c, 0x10560545c, 0x10560f968, 0x1055e9c1c, 0x104bda0b4],&#xA; }&#xA; invalid label" type="failed">/package2/a_test.go:52</failure>
</testcase>
</testsuite>
</testsuites>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="5" failures="2" skipped="1">
<testsuite name="github.com/company/package1" tests="0" failures="0" errors="0" id="0" hostname="MBP.local" time="0.000" timestamp="2022-10-13T16:53:32-05:00"></testsuite>
<testsuite name="github.com/company/package2" tests="1" failures="0" errors="0" id="8" hostname="MBP.local" time="0.482" timestamp="2022-10-13T16:53:32-05:00">
<testcase name="TestPackage2" classname="github.com/company/package2" time="0.000"></testcase>
</testsuite>
<testsuite name="github.com/company/package3" tests="1" failures="1" errors="0" id="10" hostname="MBP.local" time="0.835" timestamp="2022-10-13T16:53:32-05:00">
<testcase name="TestPackage3-1" classname="github.com/company/package3" time="0.000">
<failure message="Failed"><![CDATA[Just error here]]></failure>
</testcase>
<testcase name="TestPackage3-2" classname="github.com/company/package3" time="0.160">
<system-out><![CDATA[Just system.out here]]></system-out>
</testcase>
<testcase name="TestPackage3-3" classname="github.com/company/package3" time="0.000">
<skipped message="Skipped"><![CDATA[skipped here]]></skipped>
</testcase>
<testcase name="TestPackage3-4" classname="github.com/company/package3" time="0.000">
<failure message="Failed"></failure>
</testcase>
</testsuite>
</testsuites>

View file

@ -6,7 +6,7 @@ import {ParseOptions} from '../src/test-parser'
import {getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/path-utils'
describe('jest-junit tests', () => {
describe('go-junit tests', () => {
it('produces empty test run result when there are no test cases', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'jest-junit.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
@ -23,9 +23,9 @@ describe('jest-junit tests', () => {
expect(result.result).toBe('success')
})
it('report from ./reports/jest test results matches snapshot', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
const outputPath = path.join(__dirname, '__outputs__', 'jest-junit.md')
it('report from ./external/go-junit-report test results matches snapshot', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'go', 'go-junit-report.xml')
const outputPath = path.join(__dirname, '__outputs__', 'go-junit-report-test-results.md')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
@ -44,18 +44,16 @@ describe('jest-junit tests', () => {
fs.writeFileSync(outputPath, report)
})
it('report from facebook/jest test results matches snapshot', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'jest', 'jest-test-results.xml')
const trackedFilesPath = path.join(__dirname, 'fixtures', 'external', 'jest', 'files.txt')
const outputPath = path.join(__dirname, '__outputs__', 'jest-test-results.md')
it('report from ./external/ginkgo test results matches snapshot', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'go', 'ginkgo-junit-report.xml')
const outputPath = path.join(__dirname, '__outputs__', 'ginkgo-junit-test-results.md')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g)
const opts: ParseOptions = {
parseErrors: true,
trackedFiles
//workDir: '/home/dorny/dorny/jest/'
trackedFiles: ['__tests__/main.test.js', '__tests__/second.test.js', 'lib/main.js']
//workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/jest/'
}
const parser = new GoJunitParser(opts)

View file

@ -50,7 +50,7 @@ export class GoJunitParser implements TestParser {
private getGroups(suite: TestSuite): TestGroupResult[] {
const groups: {describe: string; tests: TestCase[]}[] = []
const returnEmpytGroups: TestGroupResult[] = [];
if (suite.testcase.length === 0) return returnEmpytGroups;
if (!suite.testcase?.length) return returnEmpytGroups;
for (const tc of suite.testcase) {
let grp = groups.find(g => g.describe === tc.$.classname)
if (grp === undefined) {
@ -83,7 +83,8 @@ export class GoJunitParser implements TestParser {
return undefined
}
const details = tc.failure[0]
const failure = tc.failure?.[0]
const details = (typeof failure === 'object' ? failure._ : failure) || ""
let path
let line

View file

@ -29,6 +29,11 @@ export interface TestCase {
name: string
time: string
}
failure?: string[]
failure?: string[] | Failure[]
error?: string[] | Failure[]
skipped?: string[]
}
export interface Failure {
_: string
}