mirror of
https://github.com/dorny/test-reporter.git
synced 2026-03-21 23:52:12 +01:00
Report jest-junit testsuite errors as failures
Test errors are different (represented differently in the JUnit XML output from jest-junit) to test _failures_. Failures are tests which ran and failed, errors are for tests/test suites which did not even run because the test code itself didn't build or didn't execute correctly. jest-junit has an option to enable reporting of test suite errors, but test-reporter then interprets these as successful tests.
This commit is contained in:
parent
540c28072b
commit
f8ae4deee6
7 changed files with 141 additions and 3 deletions
22
__tests__/__outputs__/jest-test-errors-results.md
Normal file
22
__tests__/__outputs__/jest-test-errors-results.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||

|
||||
|Report|Passed|Failed|Skipped|Time|
|
||||
|:---|---:|---:|---:|---:|
|
||||
|[fixtures/test-errors/jest/jest-test-results.xml](#user-content-r0)||2 ❌||646ms|
|
||||
## ❌ <a id="user-content-r0" href="#user-content-r0">fixtures/test-errors/jest/jest-test-results.xml</a>
|
||||
**2** tests were completed in **646ms** with **0** passed, **2** failed and **0** skipped.
|
||||
|Test suite|Passed|Failed|Skipped|Time|
|
||||
|:---|---:|---:|---:|---:|
|
||||
|[libs/bar.spec.ts](#user-content-r0s0)||1 ❌||0ms|
|
||||
|[libs/foo.spec.ts](#user-content-r0s1)||1 ❌||0ms|
|
||||
### ❌ <a id="user-content-r0s0" href="#user-content-r0s0">libs/bar.spec.ts</a>
|
||||
```
|
||||
Test suite failed to run
|
||||
❌ libs/bar.spec.ts
|
||||
● Test suite failed to run
|
||||
```
|
||||
### ❌ <a id="user-content-r0s1" href="#user-content-r0s1">libs/foo.spec.ts</a>
|
||||
```
|
||||
Test suite failed to run
|
||||
❌ libs/foo.spec.ts
|
||||
● Test suite failed to run
|
||||
```
|
||||
|
|
@ -1,5 +1,68 @@
|
|||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`jest-junit tests jest testsuite errors example test results matches snapshot 1`] = `
|
||||
TestRunResult {
|
||||
"path": "fixtures/test-errors/jest/jest-test-results.xml",
|
||||
"suites": [
|
||||
TestSuiteResult {
|
||||
"groups": [
|
||||
TestGroupResult {
|
||||
"name": "Test suite failed to run",
|
||||
"tests": [
|
||||
TestCaseResult {
|
||||
"error": {
|
||||
"details": " ● Test suite failed to run
|
||||
|
||||
tsconfig.json:13:3 - error TS6258: 'typeRoots' should be set inside the 'compilerOptions' object of the config json file
|
||||
|
||||
13 "typeRoots": ["./src/lib/types", "./node_modules/@types"],
|
||||
~~~~~~~~~~~
|
||||
",
|
||||
"line": undefined,
|
||||
"path": undefined,
|
||||
},
|
||||
"name": "libs/foo.spec.ts",
|
||||
"result": "failed",
|
||||
"time": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"name": "libs/foo.spec.ts",
|
||||
"totalTime": 0,
|
||||
},
|
||||
TestSuiteResult {
|
||||
"groups": [
|
||||
TestGroupResult {
|
||||
"name": "Test suite failed to run",
|
||||
"tests": [
|
||||
TestCaseResult {
|
||||
"error": {
|
||||
"details": " ● Test suite failed to run
|
||||
|
||||
tsconfig.json:13:3 - error TS6258: 'typeRoots' should be set inside the 'compilerOptions' object of the config json file
|
||||
|
||||
13 "typeRoots": ["./src/lib/types", "./node_modules/@types"],
|
||||
~~~~~~~~~~~
|
||||
",
|
||||
"line": undefined,
|
||||
"path": undefined,
|
||||
},
|
||||
"name": "libs/bar.spec.ts",
|
||||
"result": "failed",
|
||||
"time": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"name": "libs/bar.spec.ts",
|
||||
"totalTime": 0,
|
||||
},
|
||||
],
|
||||
"totalTime": 646,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`jest-junit tests parsing ESLint report without timing information works - PR #134 1`] = `
|
||||
TestRunResult {
|
||||
"path": "fixtures/jest-junit-eslint.xml",
|
||||
|
|
|
|||
3
__tests__/fixtures/test-errors/jest/files.txt
Normal file
3
__tests__/fixtures/test-errors/jest/files.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
libs/bar.spec.ts
|
||||
libs/foo.spec.ts
|
||||
tsconfig.json
|
||||
25
__tests__/fixtures/test-errors/jest/jest-test-results.xml
Normal file
25
__tests__/fixtures/test-errors/jest/jest-test-results.xml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites name="jest tests" tests="0" failures="0" errors="2" time="0.646">
|
||||
<testsuite name="libs/foo.spec.ts" errors="1" failures="0" skipped="0" timestamp="1970-01-01T00:00:00" time="0" tests="0">
|
||||
<testcase classname="Test suite failed to run" name="libs/foo.spec.ts" time="0">
|
||||
<error> ● Test suite failed to run
|
||||
|
||||
tsconfig.json:13:3 - error TS6258: 'typeRoots' should be set inside the 'compilerOptions' object of the config json file
|
||||
|
||||
13 "typeRoots": ["./src/lib/types", "./node_modules/@types"],
|
||||
~~~~~~~~~~~
|
||||
</error>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="libs/bar.spec.ts" errors="1" failures="0" skipped="0" timestamp="1970-01-01T00:00:00" time="0" tests="0">
|
||||
<testcase classname="Test suite failed to run" name="libs/bar.spec.ts" time="0">
|
||||
<error> ● Test suite failed to run
|
||||
|
||||
tsconfig.json:13:3 - error TS6258: 'typeRoots' should be set inside the 'compilerOptions' object of the config json file
|
||||
|
||||
13 "typeRoots": ["./src/lib/types", "./node_modules/@types"],
|
||||
~~~~~~~~~~~
|
||||
</error>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
|
@ -351,4 +351,27 @@ describe('jest-junit tests', () => {
|
|||
// Report should have the title as the first line
|
||||
expect(report).toMatch(/^# My Custom Title\n## 1 passed, 4 failed and 1 skipped\n/)
|
||||
})
|
||||
|
||||
it('jest testsuite errors example test results matches snapshot', async () => {
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'test-errors', 'jest', 'jest-test-results.xml')
|
||||
const trackedFilesPath = path.join(__dirname, 'fixtures', 'test-errors', 'jest', 'files.txt')
|
||||
const outputPath = path.join(__dirname, '__outputs__', 'jest-test-errors-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/'
|
||||
}
|
||||
|
||||
const parser = new JestJunitParser(opts)
|
||||
const result = await parser.parse(filePath, fileContent)
|
||||
expect(result).toMatchSnapshot()
|
||||
|
||||
const report = getReport([result])
|
||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
fs.writeFileSync(outputPath, report)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -75,17 +75,18 @@ export class JestJunitParser implements TestParser {
|
|||
}
|
||||
|
||||
private getTestCaseResult(test: TestCase): TestExecutionResult {
|
||||
if (test.failure) return 'failed'
|
||||
if (test.failure || test.error) return 'failed'
|
||||
if (test.skipped) return 'skipped'
|
||||
return 'success'
|
||||
}
|
||||
|
||||
private getTestCaseError(tc: TestCase): TestCaseError | undefined {
|
||||
if (!this.options.parseErrors || !tc.failure) {
|
||||
if (!this.options.parseErrors || !(tc.failure || tc.error)) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const details = typeof tc.failure[0] === 'string' ? tc.failure[0] : tc.failure[0]['_']
|
||||
const message = tc.failure ? tc.failure[0] : tc.error ? tc.error[0] : 'unknown failure'
|
||||
const details = typeof message === 'string' ? message : message['_']
|
||||
let path
|
||||
let line
|
||||
|
||||
|
|
|
|||
|
|
@ -31,4 +31,5 @@ export interface TestCase {
|
|||
}
|
||||
failure?: string[]
|
||||
skipped?: string[]
|
||||
error?: string[]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue