|
| 1 | +const tablePrinter = require('table'), // { table, getBorderCharacters } |
| 2 | + chalk = require('chalk'), |
| 3 | + Constants = require("../constants"), |
| 4 | + logger = require("../logger").syncCliLogger; |
| 5 | + |
| 6 | +/** |
| 7 | + * |
| 8 | + * @param {Array.<{specName: string, status: string, combination: string, sessionId: string}>} data |
| 9 | + * @returns {Promise.resolve || Promise.reject} |
| 10 | + */ |
| 11 | +// Example: |
| 12 | +// [ |
| 13 | +// {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}, |
| 14 | +// {specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}, |
| 15 | +// {specName: 'spec3.network.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}, |
| 16 | +// {specName: 'spec6.utils.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}, |
| 17 | +// {specName: 'spec8.alias.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'} |
| 18 | +// ] |
| 19 | +// |
| 20 | +let failedSpecsDetails = (data) => { |
| 21 | + return new Promise((resolve, reject) => { |
| 22 | + if (data.length === 0) resolve(0); // return if no failed/skipped tests. |
| 23 | + |
| 24 | + let failedSpecs = false; |
| 25 | + let specResultHeader = Constants.syncCLI.FAILED_SPEC_DETAILS_COL_HEADER.map((col) => { |
| 26 | + return chalk.blueBright(col); |
| 27 | + }); |
| 28 | + |
| 29 | + let specData = [specResultHeader]; // 2-D array |
| 30 | + |
| 31 | + data.forEach((spec) => { |
| 32 | + if (spec.status && spec.status.toLowerCase() === 'failed' && !failedSpecs) |
| 33 | + failedSpecs = true; |
| 34 | + |
| 35 | + let specStatus = (spec.status && spec.status.toLowerCase() === 'failed') ? |
| 36 | + chalk.red(spec.status) : chalk.yellow(spec.status); |
| 37 | + specData.push([spec.specName, specStatus, spec.combination, spec.sessionId]); |
| 38 | + }); |
| 39 | + |
| 40 | + let config = { |
| 41 | + border: tablePrinter.getBorderCharacters('ramac'), |
| 42 | + columns: { |
| 43 | + 0: { alignment: 'left' }, |
| 44 | + 1: { alignment: 'left' }, |
| 45 | + 2: { alignment: 'left' }, |
| 46 | + 3: { alignment: 'left' }, |
| 47 | + }, |
| 48 | + /** |
| 49 | + * @typedef {function} drawHorizontalLine |
| 50 | + * @param {number} index |
| 51 | + * @param {number} size |
| 52 | + * @return {boolean} |
| 53 | + */ |
| 54 | + drawHorizontalLine: (index, size) => { |
| 55 | + return (index === 0 || index === 1 || index === size); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + let result = tablePrinter.table(specData, config); |
| 60 | + |
| 61 | + logger.info('Failed / skipped test report'); |
| 62 | + logger.info(result); |
| 63 | + |
| 64 | + if (failedSpecs) reject(1); // specs failed, send exitCode as 1 |
| 65 | + resolve(0); // No Specs failed, maybe skipped, but not failed, send exitCode as 0 |
| 66 | + }); |
| 67 | +} |
| 68 | + |
| 69 | +exports.failedSpecsDetails = failedSpecsDetails; |
0 commit comments