Skip to content

Commit

Permalink
fix maxCols for file name
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 21, 2024
1 parent 64a2ff6 commit ff40ab8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
32 changes: 22 additions & 10 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,17 @@ const handleConsoleSummaryReport = (reportData, reportOptions, options) => {
});
};

const cutWithMaxCols = (str, maxCols, before) => {
if (str && maxCols && str.length > maxCols) {
if (before) {
return `... ${str.slice(str.length - (maxCols - 4))}`;
}
return `${str.slice(0, maxCols - 4)} ...`;
}

return str;
};

const handleMarkdownDetailsReport = async (reportData, reportOptions, options) => {
const mdOptions = {
baseUrl: '',
Expand All @@ -391,8 +402,9 @@ const handleMarkdownDetailsReport = async (reportData, reportOptions, options) =
... reportOptions
};

const color = Util.normalizeColorType(mdOptions.color);
const baseUrl = mdOptions.baseUrl;
const color = Util.normalizeColorType(mdOptions.color);
const maxCols = Util.normalizeMaxCols(mdOptions.maxCols, 15);

const mdPath = path.resolve(options.outputDir, mdOptions.outputFile);

Expand All @@ -413,8 +425,6 @@ const handleMarkdownDetailsReport = async (reportData, reportOptions, options) =
});
}

const maxCols = Util.normalizeMaxCols(mdOptions.maxCols, 15);

const rows = [];
files.forEach((file) => {

Expand All @@ -426,19 +436,21 @@ const handleMarkdownDetailsReport = async (reportData, reportOptions, options) =
const { sourcePath, summary } = file;

const fileRow = getRowData(sourcePath, summary, metrics, color);

let rowName = cutWithMaxCols(fileRow.name, maxCols, true);

if (fileRow.nameStatus) {
const nameColor = baseUrl && color === 'tex' ? '' : color;
fileRow.name = Util.getColorStrByStatus(fileRow.name, fileRow.nameStatus, nameColor);
rowName = Util.getColorStrByStatus(rowName, fileRow.nameStatus, nameColor);
}
if (baseUrl) {
fileRow.name = `[${fileRow.name}](${baseUrl + sourcePath})`;
rowName = `[${rowName}](${baseUrl + sourcePath})`;
}

let uncoveredLines = Util.getUncoveredLines(file.data.lines, color);
if (maxCols && uncoveredLines.length > maxCols) {
uncoveredLines = `${uncoveredLines.slice(0, maxCols - 4)} ...`;
}
fileRow.uncoveredLines = uncoveredLines;
fileRow.name = rowName;

const uncoveredLines = Util.getUncoveredLines(file.data.lines, color);
fileRow.uncoveredLines = cutWithMaxCols(uncoveredLines, maxCols);

rows.push(fileRow);
});
Expand Down
2 changes: 1 addition & 1 deletion test/mcr.config.mcr.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
}],
['markdown-details', {
// color: 'Tex',
maxCols: 80,
maxCols: 50,
baseUrl: 'https://cenfun.github.io/monocart-coverage-reports/mcr/#page=',
metrics: ['bytes', 'lines']
}]
Expand Down

0 comments on commit ff40ab8

Please sign in to comment.