mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 06:17:10 +01:00
Remove 'Details' column from Test case report
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
This commit is contained in:
parent
63b94a335a
commit
bff3069f5c
5 changed files with 34 additions and 96 deletions
|
|
@ -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",
|
||||
|
|
@ -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",
|
||||
|
|
@ -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",
|
||||
|
|
@ -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 ❌
|
||||
|
|
@ -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",
|
||||
}
|
||||
|
|
|
|||
42
dist/index.js
generated
vendored
42
dist/index.js
generated
vendored
|
|
@ -170,12 +170,11 @@ function getSuiteSummary(suite, index) {
|
|||
const content = groups
|
||||
.map(grp => {
|
||||
const header = grp.describe !== '' ? `#### ${grp.describe}\n\n` : '';
|
||||
const tests = markdown_utils_1.table(['Result', 'Test', 'Time', 'Details'], [markdown_utils_1.Align.Center, markdown_utils_1.Align.Left, markdown_utils_1.Align.Right, markdown_utils_1.Align.None], ...grp.tests.map(tc => {
|
||||
const tests = markdown_utils_1.table(['Result', 'Test', 'Time'], [markdown_utils_1.Align.Center, markdown_utils_1.Align.Left, markdown_utils_1.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];
|
||||
}));
|
||||
return `${header}${tests}\n`;
|
||||
})
|
||||
|
|
@ -192,16 +191,6 @@ function getTestCaseIcon(test) {
|
|||
return markdown_utils_1.Icon.skip;
|
||||
return markdown_utils_1.Icon.success;
|
||||
}
|
||||
function getTestCaseDetails(test) {
|
||||
if (test.skipped !== undefined) {
|
||||
return 'Skipped';
|
||||
}
|
||||
if (test.failure !== undefined) {
|
||||
const failure = test.failure.join('\n');
|
||||
return markdown_utils_1.exceptionCell(failure);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
function makeSuiteSlug(index, name) {
|
||||
// use "ts-$index-" as prefix to avoid slug conflicts after escaping the paths
|
||||
return slugger_1.slug(`ts-${index}-${name}`);
|
||||
|
|
@ -224,7 +213,7 @@ function getAnnotations(junit, workDir, trackedFiles) {
|
|||
end_line: src.line,
|
||||
path: src.file,
|
||||
message: ex,
|
||||
title: 'Exception was thrown here'
|
||||
title: `Test Failed: ${tc.$.name}`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -437,7 +426,7 @@ exports.getCheckRunSha = getCheckRunSha;
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.tableEscape = exports.exceptionCell = exports.table = exports.link = exports.details = exports.Icon = exports.Align = void 0;
|
||||
exports.tableEscape = exports.table = exports.link = exports.details = exports.Icon = exports.Align = void 0;
|
||||
var Align;
|
||||
(function (Align) {
|
||||
Align["Left"] = ":---";
|
||||
|
|
@ -459,31 +448,14 @@ function link(title, address) {
|
|||
}
|
||||
exports.link = link;
|
||||
function table(headers, align, ...rows) {
|
||||
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');
|
||||
}
|
||||
exports.table = table;
|
||||
function exceptionCell(ex) {
|
||||
var _a;
|
||||
const lines = ex.split(/\r?\n/);
|
||||
if (lines.length === 0) {
|
||||
return '';
|
||||
}
|
||||
const summary = tableEscape(((_a = lines.shift()) === null || _a === void 0 ? void 0 : _a.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);
|
||||
}
|
||||
exports.exceptionCell = exceptionCell;
|
||||
function tableEscape(content) {
|
||||
return content.replace('|', '\\|');
|
||||
return content.toString().replace('|', '\\|');
|
||||
}
|
||||
exports.tableEscape = tableEscape;
|
||||
|
||||
|
|
|
|||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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'
|
||||
|
|
@ -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]
|
||||
})
|
||||
)
|
||||
|
||||
|
|
@ -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}`)
|
||||
|
|
|
|||
|
|
@ -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('|', '\\|')
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue