UNPKG

upload-test-manual

Version:

CLI tool untuk mengolah file CSV dan upload ke ReportPortal

90 lines (71 loc) • 2.85 kB
#!/usr/bin/env node require('dotenv').config(); const path = require('path'); const config = require('./config'); const { startLaunch, finishLaunch } = require('./utils/rpHelpers'); const { processCSV, preparePaths, ensureDirExists } = require('./utils/fileHandler'); async function main() { try { const csvFilename = process.argv[2] || null; const configFile = process.argv[3] || null; let customConfig = {}; if (configFile) { try { const configPath = path.isAbsolute(configFile) ? configFile : path.join(process.cwd(), configFile); customConfig = require(configPath); } catch (error) { console.warn(`āš ļø Gagal memuat konfigurasi dari ${configFile}, menggunakan default:`, error.message); } } const { csvPath, xmlPath } = preparePaths(csvFilename); ensureDirExists(path.dirname(xmlPath)); const launchConfig = config(csvFilename, customConfig); console.log('šŸš€ Konfigurasi Launch:', JSON.stringify(launchConfig, null, 2)); const layer = getLayerFromFilename(csvFilename); customConfig.mapItemData = (data) => ({ ...data, Layer: layer, ExecutionType: data['Automation Status'] === 'Automated' ? 'automated' : 'manual' }); const launchId = await startLaunch(launchConfig.reportPortal); const processOptions = { requiredFields: customConfig.requiredFields, csvOptions: customConfig.csvOptions, mapItemData: customConfig.mapItemData, fieldMappings: customConfig.fieldMappings, validationOptions: customConfig.validationOptions }; const result = await processCSV(csvPath, xmlPath, launchId, launchConfig.reportPortal, processOptions); await finishLaunch(launchId, launchConfig.reportPortal); console.log('\nāœ… Proses selesai!'); console.log(`šŸ“Š XML Report: ${xmlPath}`); console.log(`- Launch ID: ${launchId}`); } catch (error) { console.error('\nāŒ Error utama:', error.message); console.error(error.stack); process.exit(1); } } function getLayerFromFilename(filename) { const lower = filename.toLowerCase(); if (lower.includes('api')) return 'API'; if (lower.includes('ui')) return 'UI'; if (lower.includes('unit')) return 'UNIT'; return 'OTHER'; } if (require.main === module) { // hanya jalan kalau dijalankan langsung dari CLI const args = process.argv.slice(2); if (args.length === 0) { console.log(` šŸ“¦ upload-test-manual This package provides a CLI to upload CSV to ReportPortal. Usage: npx upload-test-manual <csv-file> [optional-config.js] To use programmatically: const uploadConfig = require('upload-test-manual')('./file.csv'); `); process.exit(0); } main(); }