Manually create anchors for headings

This commit is contained in:
Michal Dorner 2020-11-18 23:31:33 +01:00
parent 3e8db1a67b
commit 95d3d1fb85
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
8 changed files with 82 additions and 156 deletions

133
dist/index.js generated vendored
View file

@ -83,18 +83,15 @@ run();
/***/ }),
/***/ 1113:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseJestJunit = void 0;
const xml2js_1 = __webpack_require__(6189);
const github_slugger_1 = __importDefault(__webpack_require__(237));
const markdown_utils_1 = __webpack_require__(6482);
const slugger_1 = __webpack_require__(3328);
const xml_utils_1 = __webpack_require__(8653);
async function parseJestJunit(content) {
var _a, _b;
@ -102,18 +99,17 @@ async function parseJestJunit(content) {
attrValueProcessors: [xml_utils_1.parseAttribute]
}));
const testsuites = junit.testsuites;
const slugger = new github_slugger_1.default();
const success = !(((_a = testsuites.$) === null || _a === void 0 ? void 0 : _a.failures) > 0 || ((_b = testsuites.$) === null || _b === void 0 ? void 0 : _b.errors) > 0);
return {
success,
output: {
title: junit.testsuites.$.name,
summary: getSummary(success, junit, slugger)
summary: getSummary(success, junit)
}
};
}
exports.parseJestJunit = parseJestJunit;
function getSummary(success, junit, slugger) {
function getSummary(success, junit) {
var _a, _b;
const stats = junit.testsuites.$;
const icon = success ? markdown_utils_1.Icon.success : markdown_utils_1.Icon.fail;
@ -123,26 +119,26 @@ function getSummary(success, junit, slugger) {
const passed = stats.tests - failed - skipped;
const heading = `# ${stats.name} ${icon}`;
const headingLine = `**${stats.tests}** tests were completed in **${time}** with **${passed}** passed, **${skipped}** skipped and **${failed}** failed.`;
const suitesSummary = junit.testsuites.testsuite.map(ts => {
const suitesSummary = junit.testsuites.testsuite.map((ts, i) => {
const skip = ts.$.skipped;
const fail = ts.$.errors + ts.$.failures;
const pass = ts.$.tests - fail - skip;
const tm = `${ts.$.time.toFixed(3)}s`;
const result = success ? markdown_utils_1.Icon.success : markdown_utils_1.Icon.fail;
const slug = slugger.slug(`${ts.$.name} ${result}`).replace(/_/g, '');
const tsAddr = `#${slug}`;
const name = markdown_utils_1.link(ts.$.name, tsAddr);
return [result, name, ts.$.tests, tm, pass, fail, skip];
const tsName = ts.$.name;
const tsAddr = makeSuiteSlug(i, tsName).link;
const tsNameLink = markdown_utils_1.link(tsName, tsAddr);
return [result, tsNameLink, ts.$.tests, tm, pass, fail, skip];
});
const summary = markdown_utils_1.table(['Result', 'Suite', 'Tests', 'Time', `Passed ${markdown_utils_1.Icon.success}`, `Failed ${markdown_utils_1.Icon.fail}`, `Skipped ${markdown_utils_1.Icon.skip}`], [markdown_utils_1.Align.Center, markdown_utils_1.Align.Left, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right], ...suitesSummary);
const suites = (_b = (_a = junit.testsuites) === null || _a === void 0 ? void 0 : _a.testsuite) === null || _b === void 0 ? void 0 : _b.map(ts => getSuiteSummary(ts)).join('\n');
const suites = (_b = (_a = junit.testsuites) === null || _a === void 0 ? void 0 : _a.testsuite) === null || _b === void 0 ? void 0 : _b.map((ts, i) => getSuiteSummary(ts, i)).join('\n');
const suitesSection = `## Test Suites\n\n${suites}`;
return `${heading}\n${headingLine}\n${summary}\n${suitesSection}`;
}
function getSkippedCount(suites) {
return suites.testsuite.reduce((sum, suite) => sum + suite.$.skipped, 0);
}
function getSuiteSummary(suite) {
function getSuiteSummary(suite, index) {
var _a, _b;
const success = !(((_a = suite.$) === null || _a === void 0 ? void 0 : _a.failures) > 0 || ((_b = suite.$) === null || _b === void 0 ? void 0 : _b.errors) > 0);
const icon = success ? markdown_utils_1.Icon.success : markdown_utils_1.Icon.fail;
@ -168,7 +164,10 @@ function getSuiteSummary(suite) {
return `${header}${tests}\n`;
})
.join('\n');
return `### ${suite.$.name} ${icon}\n\n${content}`;
const tsName = suite.$.name;
const tsSlug = makeSuiteSlug(index, tsName);
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`;
return `### ${tsNameLink} ${icon}\n\n${content}`;
}
function getTestCaseIcon(test) {
if (test.failure)
@ -187,6 +186,10 @@ function getTestCaseDetails(test) {
}
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}`);
}
/***/ }),
@ -328,6 +331,31 @@ function tableEscape(content) {
exports.tableEscape = tableEscape;
/***/ }),
/***/ 3328:
/***/ ((__unused_webpack_module, exports) => {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.slug = void 0;
// Returns HTML element id and href link usable as manual anchor links
// This is needed because Github in check run summary doesn't automatically
// create links out of headings as it normally does for other markdown content
function slug(name) {
const slugId = name
.trim()
.replace(/_/g, '')
.replace(/[./\\]/g, '-')
.replace(/[^\w-]/g, '');
const id = `user-content-${slugId}`;
const link = `#${slugId}`;
return { id, link };
}
exports.slug = slug;
/***/ }),
/***/ 8653:
@ -4132,79 +4160,6 @@ class Deprecation extends Error {
exports.Deprecation = Deprecation;
/***/ }),
/***/ 237:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
var emoji = __webpack_require__(5464)
module.exports = BananaSlug
var own = Object.hasOwnProperty
var whitespace = /\s/g
var specials = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g
function BananaSlug () {
var self = this
if (!(self instanceof BananaSlug)) return new BananaSlug()
self.reset()
}
/**
* Generate a unique slug.
* @param {string} value String of text to slugify
* @param {boolean} [false] Keep the current case, otherwise make all lowercase
* @return {string} A unique slug string
*/
BananaSlug.prototype.slug = function (value, maintainCase) {
var self = this
var slug = slugger(value, maintainCase === true)
var originalSlug = slug
while (own.call(self.occurrences, slug)) {
self.occurrences[originalSlug]++
slug = originalSlug + '-' + self.occurrences[originalSlug]
}
self.occurrences[slug] = 0
return slug
}
/**
* Reset - Forget all previous slugs
* @return void
*/
BananaSlug.prototype.reset = function () {
this.occurrences = Object.create(null)
}
function slugger (string, maintainCase) {
if (typeof string !== 'string') return ''
if (!maintainCase) string = string.toLowerCase()
return string.trim()
.replace(specials, '')
.replace(emoji(), '')
.replace(whitespace, '-')
}
BananaSlug.slug = slugger
/***/ }),
/***/ 5464:
/***/ ((module) => {
module.exports = function() {
return /[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2648-\u2653\u2660\u2663\u2665\u2666\u2668\u267B\u267F\u2692-\u2694\u2696\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD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