qa-shadow-report
Version:
npm package that prints formatted test reports into a google sheet or csv file
61 lines (53 loc) • 1.95 kB
JavaScript
import {
TEST_TYPES_AVAILABLE,
TEST_CATEGORIES_AVAILABLE,
ALL_TEAM_NAMES,
} from '../../../constants.js';
import { combineReports } from './combineReports.js';
import {
generateReport,
generatePlaceholders,
} from './reportGenerationHelpers.js';
/**
* Asynchronously constructs a header report from the given payload.
* @param {Array<Array<string>>} payload - The payload data to construct the report from.
* @returns {Promise<Array<Array<string>>>} A promise that resolves with the constructed report as a 2D string array.
* @throws {Error} Throws an error if report generation fails.
*/
export const constructHeaderReport = async (payload) => {
if (!Array.isArray(payload)) {
throw new Error('Invalid payload: Expected an array.');
}
const typesAvailable = TEST_TYPES_AVAILABLE();
const categoriesAvailable = TEST_CATEGORIES_AVAILABLE();
const teamNames = ALL_TEAM_NAMES();
try {
// Define the structure for the types to be reported
const typeArrays = [
{ types: typesAvailable, index: 3 },
{ types: categoriesAvailable, index: 4 },
{ types: teamNames, index: 5 },
];
const allReportEntries = [];
for (const typeData of typeArrays) {
if (!Array.isArray(typeData.types)) {
throw new Error(
`Invalid types: Expected an array at index ${typeData.index}.`
);
}
const reportEntry = await generateReport(
typeData.types,
payload,
typeData.index,
typeData.index === 5 // Some additional condition based on index
);
allReportEntries.push(reportEntry);
}
const maxTypes = Math.max(...typeArrays.map((t) => t.types.length));
const placeholders = generatePlaceholders(maxTypes);
return combineReports(allReportEntries, placeholders);
} catch (error) {
console.error('Error constructing header report:', error);
throw new Error('Failed to construct header report');
}
};