mirror of
https://github.com/dorny/test-reporter.git
synced 2026-03-21 23:52:12 +01:00
Merge pull request #155 from johnbartholomew/feat-report-test-suite-errors
This commit is contained in:
commit
0d9f24e0e1
8 changed files with 145 additions and 6 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
|
// 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`] = `
|
exports[`jest-junit tests parsing ESLint report without timing information works - PR #134 1`] = `
|
||||||
TestRunResult {
|
TestRunResult {
|
||||||
"path": "fixtures/jest-junit-eslint.xml",
|
"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
|
// Report should have the title as the first line
|
||||||
expect(report).toMatch(/^# My Custom Title\n## 1 passed, 4 failed and 1 skipped\n/)
|
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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
7
dist/index.js
generated
vendored
7
dist/index.js
generated
vendored
|
|
@ -57248,17 +57248,18 @@ class JestJunitParser {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getTestCaseResult(test) {
|
getTestCaseResult(test) {
|
||||||
if (test.failure)
|
if (test.failure || test.error)
|
||||||
return 'failed';
|
return 'failed';
|
||||||
if (test.skipped)
|
if (test.skipped)
|
||||||
return 'skipped';
|
return 'skipped';
|
||||||
return 'success';
|
return 'success';
|
||||||
}
|
}
|
||||||
getTestCaseError(tc) {
|
getTestCaseError(tc) {
|
||||||
if (!this.options.parseErrors || !tc.failure) {
|
if (!this.options.parseErrors || !(tc.failure || tc.error)) {
|
||||||
return undefined;
|
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 path;
|
||||||
let line;
|
let line;
|
||||||
const src = getExceptionSource(details, this.options.trackedFiles, file => this.getRelativePath(file));
|
const src = getExceptionSource(details, this.options.trackedFiles, file => this.getRelativePath(file));
|
||||||
|
|
|
||||||
|
|
@ -75,17 +75,18 @@ export class JestJunitParser implements TestParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getTestCaseResult(test: TestCase): TestExecutionResult {
|
private getTestCaseResult(test: TestCase): TestExecutionResult {
|
||||||
if (test.failure) return 'failed'
|
if (test.failure || test.error) return 'failed'
|
||||||
if (test.skipped) return 'skipped'
|
if (test.skipped) return 'skipped'
|
||||||
return 'success'
|
return 'success'
|
||||||
}
|
}
|
||||||
|
|
||||||
private getTestCaseError(tc: TestCase): TestCaseError | undefined {
|
private getTestCaseError(tc: TestCase): TestCaseError | undefined {
|
||||||
if (!this.options.parseErrors || !tc.failure) {
|
if (!this.options.parseErrors || !(tc.failure || tc.error)) {
|
||||||
return undefined
|
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 path
|
||||||
let line
|
let line
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,4 +31,5 @@ export interface TestCase {
|
||||||
}
|
}
|
||||||
failure?: string[]
|
failure?: string[]
|
||||||
skipped?: string[]
|
skipped?: string[]
|
||||||
|
error?: string[]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue