import Table from 'cli-table3'; import chalk from 'chalk'; import { Execution } from '../types/execution.types'; import { formatTime, getVerboseSchedule, log, wordWrap } from '../utils/general'; import dotenv from 'dotenv'; import { ExecutionHistory, RunnningExecution } from '../types/types'; import { fetchUserByUserId } from '../api/crud'; dotenv.config({ quiet: true }); export async function printExecutionsTable(executions: Execution[]) { const table = new Table({ head: [' ', 'Execution info', 'Schedule', 'Status', 'Enabled'], colWidths: [5, 30, 40, 15, 10], style: { head: [chalk.rgb(255, 105, 180).toString()], border: ['grey'] }, }); for (let idx = 0; idx < executions.length; idx++) { const exec = executions[idx]; const user = await fetchUserByUserId(exec.userId); table.push([ (idx + 1).toString() + '.', exec.name + '\n' + chalk.dim(user.name), chalk.rgb(0, 191, 255)(getVerboseSchedule(exec.schedule)), exec.schedule ? exec.enabled ? chalk.greenBright('Scheduled') : chalk.rgb(0, 155, 0)('Planned') : chalk.rgb(169, 169, 169)('Draft'), exec.enabled ? chalk.rgb(0, 255, 0)('Yes') : chalk.rgb(169, 169, 169)('No'), ]); } console.log(table.toString()); } export function printRunningExecutionsTable(executions: RunnningExecution[]) { const table = new Table({ head: [' ', 'Execution info', 'Started at', 'Progress', 'Latest status', 'Report link'], colWidths: [4, 20, 30, 25, 70], style: { head: [chalk.rgb(255, 105, 180).toString()], border: ['grey'] }, }); executions.filter(exec => exec.running).forEach((exec, idx) => { table.push([ (idx + 1).toString() + '.', exec.name + '\n' + chalk.dim(process.env.username!), chalk.greenBright(formatTime(exec.executionStatus.startedAt)), ( chalk.rgb(255, 255, 255)('Total Scenarios: ' + exec.executionStatus.totalScenarios) + '\n' + chalk.greenBright('Passed: ' + exec.executionStatus.scenariosPassed) + '\n' + chalk.redBright('Failed: ' + exec.executionStatus.scenariosFailed) ) || chalk.rgb(169, 169, 169)('Unknown'), chalk.cyanBright(exec.executionStatus.verboseStatus) || chalk.rgb(169, 169, 169)('Unknown'), chalk.blueBright(exec.reportLink) || chalk.rgb(169, 169, 169)('Unknown'), ]); }); console.log(table.toString()); } export function printExecutionsHistory(executions: ExecutionHistory[]) { const table = new Table({ head: [' ', 'Execution info', 'Run duration', 'Final status', 'Report link'], colWidths: [4, 20, 30, 25, 100], style: { head: [chalk.rgb(255, 105, 180).toString()], border: ['grey'] }, }); executions.forEach((exec, idx) => { // const status = exec.finalStatus.verboseStatus.includes('success') ? chalk.greenBright('Finished successfully') : chalk.redBright('Finished abruptly'); const status = exec.finalStatus?.verboseStatus?.includes('success') ? chalk.greenBright('Finished successfully') : chalk.redBright('Finished abruptly'); table.push([ (idx + 1).toString() + '.', wordWrap(exec.name, 18) + '\n' + chalk.dim(process.env.username!), chalk.greenBright(formatTime(exec.startedAt)) + ' to\n' + chalk.greenBright(formatTime(exec.endedAt)), (chalk.cyanBright(status) || chalk.rgb(169, 169, 169)('Unknown')) + '\n' + chalk.rgb(255, 255, 255)('Total Scenarios: ' + exec.finalStatus.totalScenarios) + '\n' + chalk.greenBright('Passed: ' + exec.finalStatus.scenariosPassed) + '\n' + chalk.redBright('Failed: ' + exec.finalStatus.scenariosFailed), chalk.blueBright(exec.reportLink) || chalk.rgb(169, 169, 169)('Unknown'), ]); }); console.log(table.toString()); }