Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: for issue #30 - many tests #31

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ inputs:
description: 'Boolean flag. Set to true to prevent failed tests from failing the job'
required: false
default: false
only-show-failed-tests:
description: 'Boolean flag. Show only failed tests in summary. Useful for when test count is large and the details are truncated'
required: false
default: true
show-test-output:
description: 'Boolean flag. Show the output of the tests. Useful if there is too much output leading to truncation on the summary'
required: false
default: true
outputs:
tests-total:
description: 'Total number of tests'
Expand Down
166 changes: 159 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,32 @@ exports.formatElapsedTime = formatElapsedTime;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.formatCoverageHtml = exports.formatResultHtml = exports.formatTitleHtml = void 0;
const common_1 = __nccwpck_require__(9759);
const fast_sort_1 = __nccwpck_require__(611);
const outcomeIcons = {
Passed: '✔️',
Failed: '❌',
NotExecuted: '⚠️'
};
const formatTitleHtml = (title) => wrap(title, { tag: 'h1', attributes: { id: (0, common_1.getSectionLink)(title) } });
exports.formatTitleHtml = formatTitleHtml;
const formatResultHtml = (result) => {
const formatResultHtml = (result, onlyShowFailedTests, showTestOutput) => {
let html = wrap('Tests', 'h3');
html += formatTable([{ name: '✔️ Passed' }, { name: '❌ Failed' }, { name: '⚠️ Skipped' }, { name: '⏱️ Time' }], [[`${result.passed}`, `${result.failed}`, `${result.skipped}`, (0, common_1.formatElapsedTime)(result.elapsed)]]);
html += result.suits.map(formatTestSuit).join('');
console.log(onlyShowFailedTests);
console.log(showTestOutput);
// .map(suit => {
// let filteredTests =
// sort(suit.tests).asc([u => u.outcome])
// .filter(test => (onlyShowFailedTests && test.outcome === 'Failed') || !onlyShowFailedTests);
// if(!showTestOutput) {
// filteredTests.forEach(t => {
// t.output = "";
// })
// }
// suit.tests = filteredTests;
// return suit;
html += (0, fast_sort_1.sort)(result.suits).asc([s => s.tests.length == s.passed ? 1 : 0, s => s.name])
.map(formatTestSuit).join('');
return html;
};
exports.formatResultHtml = formatResultHtml;
Expand Down Expand Up @@ -147,7 +162,7 @@ const formatLinesToCover = (linesToCover) => {
const formatTestSuit = (suit) => {
const icon = (0, common_1.getStatusIcon)(suit.success);
const summary = `${icon} ${suit.name} - ${suit.passed}/${suit.tests.length}`;
const hasOutput = suit.tests.some(test => test.output || test.error);
const hasOutput = suit.tests.some(test => (test.output && test.output !== '') || test.error);
const table = formatTable([{ name: 'Result', align: 'center' }, { name: 'Test' }, ...(hasOutput ? [{ name: 'Output' }] : [])], suit.tests.map(test => [outcomeIcons[test.outcome], test.name, ...(hasOutput ? [formatTestOutput(test)] : [])]));
return formatDetails(summary, table);
};
Expand Down Expand Up @@ -256,12 +271,12 @@ const markdown_1 = __nccwpck_require__(2519);
const html_1 = __nccwpck_require__(9339);
const run = () => __awaiter(void 0, void 0, void 0, function* () {
try {
const { token, title, resultsPath, coveragePath, coverageType, coverageThreshold, postNewComment, allowFailedTests } = (0, utils_1.getInputs)();
const { token, title, resultsPath, coveragePath, coverageType, coverageThreshold, postNewComment, allowFailedTests, onlyShowFailedTests, showTestOutput } = (0, utils_1.getInputs)();
let comment = '';
let summary = (0, html_1.formatTitleHtml)(title);
const testResult = yield (0, results_1.processTestResults)(resultsPath, allowFailedTests);
comment += (0, markdown_1.formatResultMarkdown)(testResult);
summary += (0, html_1.formatResultHtml)(testResult);
summary += (0, html_1.formatResultHtml)(testResult, onlyShowFailedTests, showTestOutput);
if (coveragePath) {
const testCoverage = yield (0, coverage_1.processTestCoverage)(coveragePath, coverageType, coverageThreshold);
comment += testCoverage ? (0, markdown_1.formatCoverageMarkdown)(testCoverage, coverageThreshold) : '';
Expand Down Expand Up @@ -734,7 +749,9 @@ const inputs = {
resultsPath: 'results-path',
coveragePath: 'coverage-path',
coverageType: 'coverage-type',
coverageThreshold: 'coverage-threshold'
coverageThreshold: 'coverage-threshold',
onlyShowFailedTests: 'only-show-failed-tests',
showTestOutput: 'show-test-output'
};
const outputs = {
total: 'tests-total',
Expand All @@ -758,7 +775,9 @@ const getInputs = () => {
resultsPath: core.getInput(inputs.resultsPath),
coveragePath: core.getInput(inputs.coveragePath),
coverageType: core.getInput(inputs.coverageType),
coverageThreshold: Number(core.getInput(inputs.coverageThreshold))
coverageThreshold: Number(core.getInput(inputs.coverageThreshold)),
onlyShowFailedTests: core.getBooleanInput(inputs.onlyShowFailedTests),
showTestOutput: core.getBooleanInput(inputs.showTestOutput)
};
};
exports.getInputs = getInputs;
Expand Down Expand Up @@ -5542,6 +5561,139 @@ class Deprecation extends Error {
exports.Deprecation = Deprecation;


/***/ }),

/***/ 611:
/***/ ((__unused_webpack_module, exports) => {

"use strict";


Object.defineProperty(exports, "__esModule", ({ value: true }));

// >>> INTERFACES <<<
// >>> HELPERS <<<
var castComparer = function (comparer) { return function (a, b, order) { return comparer(a, b, order) * order; }; };
var throwInvalidConfigErrorIfTrue = function (condition, context) {
if (condition)
throw Error("Invalid sort config: " + context);
};
var unpackObjectSorter = function (sortByObj) {
var _a = sortByObj || {}, asc = _a.asc, desc = _a.desc;
var order = asc ? 1 : -1;
var sortBy = (asc || desc);
// Validate object config
throwInvalidConfigErrorIfTrue(!sortBy, 'Expected `asc` or `desc` property');
throwInvalidConfigErrorIfTrue(asc && desc, 'Ambiguous object with `asc` and `desc` config properties');
var comparer = sortByObj.comparer && castComparer(sortByObj.comparer);
return { order: order, sortBy: sortBy, comparer: comparer };
};
// >>> SORTERS <<<
var multiPropertySorterProvider = function (defaultComparer) {
return function multiPropertySorter(sortBy, sortByArr, depth, order, comparer, a, b) {
var valA;
var valB;
if (typeof sortBy === 'string') {
valA = a[sortBy];
valB = b[sortBy];
}
else if (typeof sortBy === 'function') {
valA = sortBy(a);
valB = sortBy(b);
}
else {
var objectSorterConfig = unpackObjectSorter(sortBy);
return multiPropertySorter(objectSorterConfig.sortBy, sortByArr, depth, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer, a, b);
}
var equality = comparer(valA, valB, order);
if ((equality === 0 || (valA == null && valB == null)) &&
sortByArr.length > depth) {
return multiPropertySorter(sortByArr[depth], sortByArr, depth + 1, order, comparer, a, b);
}
return equality;
};
};
function getSortStrategy(sortBy, comparer, order) {
// Flat array sorter
if (sortBy === undefined || sortBy === true) {
return function (a, b) { return comparer(a, b, order); };
}
// Sort list of objects by single object key
if (typeof sortBy === 'string') {
throwInvalidConfigErrorIfTrue(sortBy.includes('.'), 'String syntax not allowed for nested properties.');
return function (a, b) { return comparer(a[sortBy], b[sortBy], order); };
}
// Sort list of objects by single function sorter
if (typeof sortBy === 'function') {
return function (a, b) { return comparer(sortBy(a), sortBy(b), order); };
}
// Sort by multiple properties
if (Array.isArray(sortBy)) {
var multiPropSorter_1 = multiPropertySorterProvider(comparer);
return function (a, b) { return multiPropSorter_1(sortBy[0], sortBy, 1, order, comparer, a, b); };
}
// Unpack object config to get actual sorter strategy
var objectSorterConfig = unpackObjectSorter(sortBy);
return getSortStrategy(objectSorterConfig.sortBy, objectSorterConfig.comparer || comparer, objectSorterConfig.order);
}
var sortArray = function (order, ctx, sortBy, comparer) {
var _a;
if (!Array.isArray(ctx)) {
return ctx;
}
// Unwrap sortBy if array with only 1 value to get faster sort strategy
if (Array.isArray(sortBy) && sortBy.length < 2) {
_a = sortBy, sortBy = _a[0];
}
return ctx.sort(getSortStrategy(sortBy, comparer, order));
};
function createNewSortInstance(opts) {
var comparer = castComparer(opts.comparer);
return function (arrayToSort) {
var ctx = Array.isArray(arrayToSort) && !opts.inPlaceSorting
? arrayToSort.slice()
: arrayToSort;
return {
asc: function (sortBy) {
return sortArray(1, ctx, sortBy, comparer);
},
desc: function (sortBy) {
return sortArray(-1, ctx, sortBy, comparer);
},
by: function (sortBy) {
return sortArray(1, ctx, sortBy, comparer);
},
};
};
}
var defaultComparer = function (a, b, order) {
if (a == null)
return order;
if (b == null)
return -order;
if (typeof a !== typeof b) {
return typeof a < typeof b ? -1 : 1;
}
if (a < b)
return -1;
if (a > b)
return 1;
return 0;
};
var sort = createNewSortInstance({
comparer: defaultComparer,
});
var inPlaceSort = createNewSortInstance({
comparer: defaultComparer,
inPlaceSorting: true,
});

exports.createNewSortInstance = createNewSortInstance;
exports.defaultComparer = defaultComparer;
exports.inPlaceSort = inPlaceSort;
exports.sort = sort;


/***/ }),

/***/ 1046:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions dist/licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,31 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


fast-sort
MIT
MIT License

Copyright (c) 2017 Stefan Novaković

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


glob
ISC
The ISC License
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dependencies": {
"@actions/core": "^1.8.2",
"@actions/github": "^5.0.3",
"fast-sort": "3.4.0",
"glob": "^10.3.10",
"xml2js": "^0.4.23"
},
Expand Down
2 changes: 2 additions & 0 deletions src/data/IActionInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export default interface IActionInputs {
coverageThreshold: number;
postNewComment: boolean;
allowFailedTests: boolean;
onlyShowFailedTests: boolean;
showTestOutput: boolean;
}
27 changes: 23 additions & 4 deletions src/formatting/html.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ICoverage, ICoverageModule, IResult, ITest, ITestSuit, TestOutcome } from '../data';
import { formatElapsedTime, getSectionLink, getStatusIcon } from './common';
import { sort } from 'fast-sort';

interface Element {
tag: string;
Expand All @@ -20,15 +21,33 @@ const outcomeIcons: { [key in TestOutcome]: string } = {
export const formatTitleHtml = (title: string): string =>
wrap(title, { tag: 'h1', attributes: { id: getSectionLink(title) } });

export const formatResultHtml = (result: IResult): string => {
export const formatResultHtml = (result: IResult, onlyShowFailedTests:boolean, showTestOutput:boolean): string => {
let html = wrap('Tests', 'h3');

html += formatTable(
[{ name: '✔️ Passed' }, { name: '❌ Failed' }, { name: '⚠️ Skipped' }, { name: '⏱️ Time' }],
[[`${result.passed}`, `${result.failed}`, `${result.skipped}`, formatElapsedTime(result.elapsed)]]
);

html += result.suits.map(formatTestSuit).join('');
console.log(onlyShowFailedTests);
console.log(showTestOutput);

// .map(suit => {
// let filteredTests =
// sort(suit.tests).asc([u => u.outcome])
// .filter(test => (onlyShowFailedTests && test.outcome === 'Failed') || !onlyShowFailedTests);

// if(!showTestOutput) {
// filteredTests.forEach(t => {
// t.output = "";
// })
// }

// suit.tests = filteredTests;
// return suit;

html += sort(result.suits).asc([s=> s.tests.length == s.passed ? 1 : 0, s => s.name])
.map(formatTestSuit).join('');

return html;
};
Expand Down Expand Up @@ -87,11 +106,11 @@ const formatLinesToCover = (linesToCover: number[]): string => {
const formatTestSuit = (suit: ITestSuit): string => {
const icon = getStatusIcon(suit.success);
const summary = `${icon} ${suit.name} - ${suit.passed}/${suit.tests.length}`;
const hasOutput = suit.tests.some(test => test.output || test.error);
const hasOutput = suit.tests.some(test => (test.output && test.output !== '') || test.error);

const table = formatTable(
[{ name: 'Result', align: 'center' }, { name: 'Test' }, ...(hasOutput ? [{ name: 'Output' }] : [])],
suit.tests.map(test => [outcomeIcons[test.outcome], test.name, ...(hasOutput ? [formatTestOutput(test)] : [])])
suit.tests.map(test => [outcomeIcons[test.outcome], test.name, ...(hasOutput ? [formatTestOutput(test)] : [])])
);

return formatDetails(summary, table);
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ const run = async (): Promise<void> => {
coverageType,
coverageThreshold,
postNewComment,
allowFailedTests
allowFailedTests,
onlyShowFailedTests,
showTestOutput
} = getInputs();

let comment = '';
let summary = formatTitleHtml(title);

const testResult = await processTestResults(resultsPath, allowFailedTests);
comment += formatResultMarkdown(testResult);
summary += formatResultHtml(testResult);
summary += formatResultHtml(testResult, onlyShowFailedTests, showTestOutput);

if (coveragePath) {
const testCoverage = await processTestCoverage(coveragePath, coverageType, coverageThreshold);
Expand Down
Loading
Loading