Skip to content

Commit

Permalink
Remove 'Details' column from Test case report
Browse files Browse the repository at this point in the history
Stack traces doesn't fit well into the table - there was not enough width for it.  Now the stack traces are included in annotations which looks much better
  • Loading branch information
Michal Dorner committed Nov 29, 2020
1 parent 63b94a3 commit bff3069
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 96 deletions.
36 changes: 18 additions & 18 deletions __tests__/__snapshots__/jest-junit.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Received: false
at processTicksAndRejections (internal/process/task_queues.js:97:5)",
"path": "__tests__/main.test.js",
"start_line": 10,
"title": "Exception was thrown here",
"title": "Test Failed: Failing test",
},
Object {
"annotation_level": "failure",
Expand All @@ -34,7 +34,7 @@ Received: false
at processTicksAndRejections (internal/process/task_queues.js:97:5)",
"path": "lib/main.js",
"start_line": 2,
"title": "Exception was thrown here",
"title": "Test Failed: Exception in target unit",
},
Object {
"annotation_level": "failure",
Expand All @@ -49,7 +49,7 @@ Received: false
at processTicksAndRejections (internal/process/task_queues.js:97:5)",
"path": "__tests__/main.test.js",
"start_line": 21,
"title": "Exception was thrown here",
"title": "Test Failed: Exception in test",
},
Object {
"annotation_level": "failure",
Expand All @@ -70,7 +70,7 @@ Received: false
at runTest (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runner\\\\build\\\\runTest.js:472:34)",
"path": "__tests__/second.test.js",
"start_line": 1,
"title": "Exception was thrown here",
"title": "Test Failed: Timeout test",
},
],
"summary": "# jest tests ❌
Expand All @@ -85,29 +85,29 @@ Received: false
#### Test 1
| Result | Test | Time | Details |
| :---: | :--- | ---: | --- |
| ✔️ | Passing test | 1ms | |
| Result | Test | Time |
| :---: | :--- | ---: |
| ✔️ | Passing test | 1ms |
#### Test 1 Test 1.1
| Result | Test | Time | Details |
| :---: | :--- | ---: | --- |
| ❌ | Failing test | 2ms | <details><summary>Error: expect(received).toBeTruthy()</summary><pre>Received: false<br> at Object.<anonymous> (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\__tests__\\\\main.test.js:10:21)<br> at Object.asyncJestTest (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmineAsyncInstall.js:106:37)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:45:12<br> at new Promise (<anonymous>)<br> at mapper (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:28:19)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:75:41<br> at processTicksAndRejections (internal/process/task_queues.js:97:5)</pre></details> |
| ❌ | Exception in target unit | 0ms | <details><summary>Error: Some error</summary><pre> at Object.throwError (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\lib\\\\main.js:2:9)<br> at Object.<anonymous> (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\__tests__\\\\main.test.js:14:11)<br> at Object.asyncJestTest (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmineAsyncInstall.js:106:37)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:45:12<br> at new Promise (<anonymous>)<br> at mapper (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:28:19)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:75:41<br> at processTicksAndRejections (internal/process/task_queues.js:97:5)</pre></details> |
| Result | Test | Time |
| :---: | :--- | ---: |
| | Failing test | 2ms |
| | Exception in target unit | 0ms |
#### Test 2
| Result | Test | Time | Details |
| :---: | :--- | ---: | --- |
| | Exception in test | 0ms | <details><summary>Error: Some error</summary><pre> at Object.<anonymous> (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\__tests__\\\\main.test.js:21:11)<br> at Object.asyncJestTest (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmineAsyncInstall.js:106:37)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:45:12<br> at new Promise (<anonymous>)<br> at mapper (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:28:19)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:75:41<br> at processTicksAndRejections (internal/process/task_queues.js:97:5)</pre></details> |
| Result | Test | Time |
| :---: | :--- | ---: |
| | Exception in test | 0ms |
### <a id=\\"user-content-ts-1-tests-second-test-js\\" href=\\"#ts-1-tests-second-test-js\\">__tests__\\\\second.test.js</a>
| Result | Test | Time | Details |
| :---: | :--- | ---: | --- |
| ❌ | Timeout test | 4ms | <details><summary>: Timeout - Async callback was not invoked within the 1 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 1 ms timeout specified by jest.setTimeout.Error:</summary><pre> at new Spec (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmine\\\\Spec.js:116:22)<br> at new Spec (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\setup_jest_globals.js:78:9)<br> at specFactory (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmine\\\\Env.js:523:24)<br> at Env.it (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmine\\\\Env.js:592:24)<br> at Env.it (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmineAsyncInstall.js:134:23)<br> at it (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmine\\\\jasmineLight.js:100:21)<br> at Object.<anonymous> (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\__tests__\\\\second.test.js:1:34)<br> at Runtime._execModule (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runtime\\\\build\\\\index.js:1245:24)<br> at Runtime._loadModule (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runtime\\\\build\\\\index.js:844:12)<br> at Runtime.requireModule (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runtime\\\\build\\\\index.js:694:10)<br> at jasmine2 (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\index.js:230:13)<br> at runTestInternal (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runner\\\\build\\\\runTest.js:380:22)<br> at runTest (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runner\\\\build\\\\runTest.js:472:34)</pre></details> |
| ✖️ | Skipped test | 0ms | Skipped |
| Result | Test | Time |
| :---: | :--- | ---: |
| | Timeout test | 4ms |
| ✖️ | Skipped test | 0ms |
",
"title": "jest tests",
}
Expand Down
42 changes: 7 additions & 35 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

22 changes: 4 additions & 18 deletions src/parsers/jest-junit/jest-junit-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Annotation, ParseOptions, TestResult} from '../test-parser'
import {parseStringPromise} from 'xml2js'

import {JunitReport, TestCase, TestSuite, TestSuites} from './jest-junit-types'
import {Align, Icon, link, table, exceptionCell} from '../../utils/markdown-utils'
import {Align, Icon, link, table} from '../../utils/markdown-utils'
import {normalizeFilePath} from '../../utils/file-utils'
import {slug} from '../../utils/slugger'
import {parseAttribute} from '../../utils/xml-utils'
Expand Down Expand Up @@ -83,14 +83,13 @@ function getSuiteSummary(suite: TestSuite, index: number): string {
.map(grp => {
const header = grp.describe !== '' ? `#### ${grp.describe}\n\n` : ''
const tests = table(
['Result', 'Test', 'Time', 'Details'],
[Align.Center, Align.Left, Align.Right, Align.None],
['Result', 'Test', 'Time'],
[Align.Center, Align.Left, Align.Right],
...grp.tests.map(tc => {
const name = tc.$.name
const time = `${Math.round(tc.$.time * 1000)}ms`
const result = getTestCaseIcon(tc)
const ex = getTestCaseDetails(tc)
return [result, name, time, ex]
return [result, name, time]
})
)

Expand All @@ -110,19 +109,6 @@ function getTestCaseIcon(test: TestCase): string {
return Icon.success
}

function getTestCaseDetails(test: TestCase): string {
if (test.skipped !== undefined) {
return 'Skipped'
}

if (test.failure !== undefined) {
const failure = test.failure.join('\n')
return exceptionCell(failure)
}

return ''
}

function makeSuiteSlug(index: number, name: string): {id: string; link: string} {
// use "ts-$index-" as prefix to avoid slug conflicts after escaping the paths
return slug(`ts-${index}-${name}`)
Expand Down
28 changes: 4 additions & 24 deletions src/utils/markdown-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,12 @@ export function link(title: string, address: string): string {

type ToString = string | number | boolean | Date
export function table(headers: ToString[], align: ToString[], ...rows: ToString[][]): string {
const headerRow = `| ${headers.join(' | ')} |`
const headerRow = `| ${headers.map(tableEscape).join(' | ')} |`
const alignRow = `| ${align.join(' | ')} |`
const contentRows = rows.map(row => `| ${row.join(' | ')} |`).join('\n')
const contentRows = rows.map(row => `| ${row.map(tableEscape).join(' | ')} |`).join('\n')
return [headerRow, alignRow, contentRows].join('\n')
}

export function exceptionCell(ex: string): string {
const lines = ex.split(/\r?\n/)
if (lines.length === 0) {
return ''
}

const summary = tableEscape(lines.shift()?.trim() || '')
const emptyLine = /^\s*$/
const firstNonEmptyLine = lines.findIndex(l => !emptyLine.test(l))

if (firstNonEmptyLine === -1) {
return summary
}

const contentLines = firstNonEmptyLine > 0 ? lines.slice(firstNonEmptyLine) : lines

const content = '<pre>' + tableEscape(contentLines.join('<br>')) + '</pre>'
return details(summary, content)
}

export function tableEscape(content: string): string {
return content.replace('|', '\\|')
export function tableEscape(content: ToString): string {
return content.toString().replace('|', '\\|')
}

0 comments on commit bff3069

Please sign in to comment.