mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Merge pull request #89 from dorny/fix-suite-links
Use full URL to link test suites
This commit is contained in:
commit
39f7ac7868
4 changed files with 47 additions and 21 deletions
32
dist/index.js
generated
vendored
32
dist/index.js
generated
vendored
|
|
@ -324,18 +324,29 @@ class TestReporter {
|
||||||
const tr = await parser.parse(file, content);
|
const tr = await parser.parse(file, content);
|
||||||
results.push(tr);
|
results.push(tr);
|
||||||
}
|
}
|
||||||
|
core.info(`Creating check run ${name}`);
|
||||||
|
const createResp = await this.octokit.checks.create({
|
||||||
|
head_sha: this.context.sha,
|
||||||
|
name,
|
||||||
|
status: 'in_progress',
|
||||||
|
output: {
|
||||||
|
title: name,
|
||||||
|
summary: ''
|
||||||
|
},
|
||||||
|
...github.context.repo
|
||||||
|
});
|
||||||
core.info('Creating report summary');
|
core.info('Creating report summary');
|
||||||
const { listSuites, listTests } = this;
|
const { listSuites, listTests } = this;
|
||||||
const summary = get_report_1.getReport(results, { listSuites, listTests });
|
const baseUrl = createResp.data.html_url;
|
||||||
|
const summary = get_report_1.getReport(results, { listSuites, listTests, baseUrl });
|
||||||
core.info('Creating annotations');
|
core.info('Creating annotations');
|
||||||
const annotations = get_annotations_1.getAnnotations(results, this.maxAnnotations);
|
const annotations = get_annotations_1.getAnnotations(results, this.maxAnnotations);
|
||||||
const isFailed = results.some(tr => tr.result === 'failed');
|
const isFailed = results.some(tr => tr.result === 'failed');
|
||||||
const conclusion = isFailed ? 'failure' : 'success';
|
const conclusion = isFailed ? 'failure' : 'success';
|
||||||
const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success;
|
const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success;
|
||||||
core.info(`Creating check run with conclusion ${conclusion}`);
|
core.info(`Updating check run conclusion (${conclusion}) and output`);
|
||||||
const resp = await this.octokit.checks.create({
|
const resp = await this.octokit.checks.update({
|
||||||
head_sha: this.context.sha,
|
check_run_id: createResp.data.id,
|
||||||
name,
|
|
||||||
conclusion,
|
conclusion,
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
output: {
|
output: {
|
||||||
|
|
@ -1224,7 +1235,8 @@ const slugger_1 = __nccwpck_require__(3328);
|
||||||
const MAX_REPORT_LENGTH = 65535;
|
const MAX_REPORT_LENGTH = 65535;
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
listSuites: 'all',
|
listSuites: 'all',
|
||||||
listTests: 'all'
|
listTests: 'all',
|
||||||
|
baseUrl: ''
|
||||||
};
|
};
|
||||||
function getReport(results, options = defaultOptions) {
|
function getReport(results, options = defaultOptions) {
|
||||||
core.info('Generating check run summary');
|
core.info('Generating check run summary');
|
||||||
|
|
@ -1326,7 +1338,7 @@ function getTestRunsReport(testRuns, options) {
|
||||||
const tableData = testRuns.map((tr, runIndex) => {
|
const tableData = testRuns.map((tr, runIndex) => {
|
||||||
const time = markdown_utils_1.formatTime(tr.time);
|
const time = markdown_utils_1.formatTime(tr.time);
|
||||||
const name = tr.path;
|
const name = tr.path;
|
||||||
const addr = makeRunSlug(runIndex).link;
|
const addr = options.baseUrl + makeRunSlug(runIndex).link;
|
||||||
const nameLink = markdown_utils_1.link(name, addr);
|
const nameLink = markdown_utils_1.link(name, addr);
|
||||||
const passed = tr.passed > 0 ? `${tr.passed}${markdown_utils_1.Icon.success}` : '';
|
const passed = tr.passed > 0 ? `${tr.passed}${markdown_utils_1.Icon.success}` : '';
|
||||||
const failed = tr.failed > 0 ? `${tr.failed}${markdown_utils_1.Icon.fail}` : '';
|
const failed = tr.failed > 0 ? `${tr.failed}${markdown_utils_1.Icon.fail}` : '';
|
||||||
|
|
@ -1343,7 +1355,7 @@ function getTestRunsReport(testRuns, options) {
|
||||||
function getSuitesReport(tr, runIndex, options) {
|
function getSuitesReport(tr, runIndex, options) {
|
||||||
const sections = [];
|
const sections = [];
|
||||||
const trSlug = makeRunSlug(runIndex);
|
const trSlug = makeRunSlug(runIndex);
|
||||||
const nameLink = `<a id="${trSlug.id}" href="${trSlug.link}">${tr.path}</a>`;
|
const nameLink = `<a id="${trSlug.id}" href="${options.baseUrl + trSlug.link}">${tr.path}</a>`;
|
||||||
const icon = getResultIcon(tr.result);
|
const icon = getResultIcon(tr.result);
|
||||||
sections.push(`## ${icon}\xa0${nameLink}`);
|
sections.push(`## ${icon}\xa0${nameLink}`);
|
||||||
const time = markdown_utils_1.formatTime(tr.time);
|
const time = markdown_utils_1.formatTime(tr.time);
|
||||||
|
|
@ -1357,7 +1369,7 @@ function getSuitesReport(tr, runIndex, options) {
|
||||||
const tsTime = markdown_utils_1.formatTime(s.time);
|
const tsTime = markdown_utils_1.formatTime(s.time);
|
||||||
const tsName = s.name;
|
const tsName = s.name;
|
||||||
const skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed');
|
const skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed');
|
||||||
const tsAddr = makeSuiteSlug(runIndex, suiteIndex).link;
|
const tsAddr = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link;
|
||||||
const tsNameLink = skipLink ? tsName : markdown_utils_1.link(tsName, tsAddr);
|
const tsNameLink = skipLink ? tsName : markdown_utils_1.link(tsName, tsAddr);
|
||||||
const passed = s.passed > 0 ? `${s.passed}${markdown_utils_1.Icon.success}` : '';
|
const passed = s.passed > 0 ? `${s.passed}${markdown_utils_1.Icon.success}` : '';
|
||||||
const failed = s.failed > 0 ? `${s.failed}${markdown_utils_1.Icon.fail}` : '';
|
const failed = s.failed > 0 ? `${s.failed}${markdown_utils_1.Icon.fail}` : '';
|
||||||
|
|
@ -1386,7 +1398,7 @@ function getTestsReport(ts, runIndex, suiteIndex, options) {
|
||||||
const sections = [];
|
const sections = [];
|
||||||
const tsName = ts.name;
|
const tsName = ts.name;
|
||||||
const tsSlug = makeSuiteSlug(runIndex, suiteIndex);
|
const tsSlug = makeSuiteSlug(runIndex, suiteIndex);
|
||||||
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`;
|
const tsNameLink = `<a id="${tsSlug.id}" href="${options.baseUrl + tsSlug.link}">${tsName}</a>`;
|
||||||
const icon = getResultIcon(ts.result);
|
const icon = getResultIcon(ts.result);
|
||||||
sections.push(`### ${icon}\xa0${tsNameLink}`);
|
sections.push(`### ${icon}\xa0${tsNameLink}`);
|
||||||
sections.push('```');
|
sections.push('```');
|
||||||
|
|
|
||||||
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
22
src/main.ts
22
src/main.ts
|
|
@ -146,9 +146,22 @@ class TestReporter {
|
||||||
results.push(tr)
|
results.push(tr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.info(`Creating check run ${name}`)
|
||||||
|
const createResp = await this.octokit.checks.create({
|
||||||
|
head_sha: this.context.sha,
|
||||||
|
name,
|
||||||
|
status: 'in_progress',
|
||||||
|
output: {
|
||||||
|
title: name,
|
||||||
|
summary: ''
|
||||||
|
},
|
||||||
|
...github.context.repo
|
||||||
|
})
|
||||||
|
|
||||||
core.info('Creating report summary')
|
core.info('Creating report summary')
|
||||||
const {listSuites, listTests} = this
|
const {listSuites, listTests} = this
|
||||||
const summary = getReport(results, {listSuites, listTests})
|
const baseUrl = createResp.data.html_url
|
||||||
|
const summary = getReport(results, {listSuites, listTests, baseUrl})
|
||||||
|
|
||||||
core.info('Creating annotations')
|
core.info('Creating annotations')
|
||||||
const annotations = getAnnotations(results, this.maxAnnotations)
|
const annotations = getAnnotations(results, this.maxAnnotations)
|
||||||
|
|
@ -157,10 +170,9 @@ class TestReporter {
|
||||||
const conclusion = isFailed ? 'failure' : 'success'
|
const conclusion = isFailed ? 'failure' : 'success'
|
||||||
const icon = isFailed ? Icon.fail : Icon.success
|
const icon = isFailed ? Icon.fail : Icon.success
|
||||||
|
|
||||||
core.info(`Creating check run with conclusion ${conclusion}`)
|
core.info(`Updating check run conclusion (${conclusion}) and output`)
|
||||||
const resp = await this.octokit.checks.create({
|
const resp = await this.octokit.checks.update({
|
||||||
head_sha: this.context.sha,
|
check_run_id: createResp.data.id,
|
||||||
name,
|
|
||||||
conclusion,
|
conclusion,
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
output: {
|
output: {
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,13 @@ const MAX_REPORT_LENGTH = 65535
|
||||||
export interface ReportOptions {
|
export interface ReportOptions {
|
||||||
listSuites: 'all' | 'failed'
|
listSuites: 'all' | 'failed'
|
||||||
listTests: 'all' | 'failed' | 'none'
|
listTests: 'all' | 'failed' | 'none'
|
||||||
|
baseUrl: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions: ReportOptions = {
|
const defaultOptions: ReportOptions = {
|
||||||
listSuites: 'all',
|
listSuites: 'all',
|
||||||
listTests: 'all'
|
listTests: 'all',
|
||||||
|
baseUrl: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
|
export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
|
||||||
|
|
@ -134,7 +136,7 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s
|
||||||
const tableData = testRuns.map((tr, runIndex) => {
|
const tableData = testRuns.map((tr, runIndex) => {
|
||||||
const time = formatTime(tr.time)
|
const time = formatTime(tr.time)
|
||||||
const name = tr.path
|
const name = tr.path
|
||||||
const addr = makeRunSlug(runIndex).link
|
const addr = options.baseUrl + makeRunSlug(runIndex).link
|
||||||
const nameLink = link(name, addr)
|
const nameLink = link(name, addr)
|
||||||
const passed = tr.passed > 0 ? `${tr.passed}${Icon.success}` : ''
|
const passed = tr.passed > 0 ? `${tr.passed}${Icon.success}` : ''
|
||||||
const failed = tr.failed > 0 ? `${tr.failed}${Icon.fail}` : ''
|
const failed = tr.failed > 0 ? `${tr.failed}${Icon.fail}` : ''
|
||||||
|
|
@ -159,7 +161,7 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
|
||||||
const sections: string[] = []
|
const sections: string[] = []
|
||||||
|
|
||||||
const trSlug = makeRunSlug(runIndex)
|
const trSlug = makeRunSlug(runIndex)
|
||||||
const nameLink = `<a id="${trSlug.id}" href="${trSlug.link}">${tr.path}</a>`
|
const nameLink = `<a id="${trSlug.id}" href="${options.baseUrl + trSlug.link}">${tr.path}</a>`
|
||||||
const icon = getResultIcon(tr.result)
|
const icon = getResultIcon(tr.result)
|
||||||
sections.push(`## ${icon}\xa0${nameLink}`)
|
sections.push(`## ${icon}\xa0${nameLink}`)
|
||||||
|
|
||||||
|
|
@ -179,7 +181,7 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
|
||||||
const tsTime = formatTime(s.time)
|
const tsTime = formatTime(s.time)
|
||||||
const tsName = s.name
|
const tsName = s.name
|
||||||
const skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed')
|
const skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed')
|
||||||
const tsAddr = makeSuiteSlug(runIndex, suiteIndex).link
|
const tsAddr = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link
|
||||||
const tsNameLink = skipLink ? tsName : link(tsName, tsAddr)
|
const tsNameLink = skipLink ? tsName : link(tsName, tsAddr)
|
||||||
const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : ''
|
const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : ''
|
||||||
const failed = s.failed > 0 ? `${s.failed}${Icon.fail}` : ''
|
const failed = s.failed > 0 ? `${s.failed}${Icon.fail}` : ''
|
||||||
|
|
@ -214,7 +216,7 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe
|
||||||
|
|
||||||
const tsName = ts.name
|
const tsName = ts.name
|
||||||
const tsSlug = makeSuiteSlug(runIndex, suiteIndex)
|
const tsSlug = makeSuiteSlug(runIndex, suiteIndex)
|
||||||
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`
|
const tsNameLink = `<a id="${tsSlug.id}" href="${options.baseUrl + tsSlug.link}">${tsName}</a>`
|
||||||
const icon = getResultIcon(ts.result)
|
const icon = getResultIcon(ts.result)
|
||||||
sections.push(`### ${icon}\xa0${tsNameLink}`)
|
sections.push(`### ${icon}\xa0${tsNameLink}`)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue