@testmonitor/testmonitor-cli
Version:
TestMonitor CLI tool
64 lines (58 loc) • 2.29 kB
JavaScript
import { Command } from 'commander';
import { SubmitReport } from '../actions/SubmitReport.js';
import fs from 'fs';
import chalk from 'chalk';
import 'dotenv/config';
const submitCommand = new Command('submit')
.description('Submit a JUnit XML file to your TestMonitor instance.')
.helpOption('-h, --help', 'Display help for command')
.requiredOption('-d, --domain <domain>', 'Your TestMonitor domain name (e.g., mydomain.testmonitor.com)')
.requiredOption('-i, --integration-id <id>', 'The JUnit integration ID')
.requiredOption('-f, --file <path>', 'Path to your JUnit XML file')
.option('-m, --milestone-id <id>', 'The milestone ID for the new test run (required if not configured in your JUnit configuration)')
.option('-o, --milestone-name <name>', 'Finds or creates a milestone matching the name for the new test run')
.option('-n, --name <name>', 'The name for the new test run (will be auto-generated if not provided)')
.option('-p, --preserve-names', 'Preserve test case names exactly as they appear in the XML file.')
.option('-s, --skip-root-suite', 'Skip the root test suite and start from its nested suites.')
.option('-e, --test-environment-id <id>', 'The test environment ID for the new test run')
.option('-t, --type <type>', 'The automation test type (cypress, playwright, phpunit, selenium)')
.option('-v, --verbose', 'Output additional debug information')
.action(async (options) => {
const {
domain,
integrationId,
file,
name,
milestoneId,
milestoneName,
preserveNames,
skipRootSuite,
testEnvironmentId,
type,
verbose
} = options;
const apiKey = process.env.TESTMONITOR_TOKEN;
if (!apiKey) {
console.error(chalk.red('Error') + ': TESTMONITOR_TOKEN environment variable is not set.');
process.exit(1);
}
if (!fs.existsSync(file)) {
console.error(chalk.red('Error') + `: File not found at path ${file}`);
process.exit(1);
}
const action = new SubmitReport({
domain,
apiKey,
integrationId,
file,
name,
type,
milestoneId,
milestoneName,
preserveNames,
skipRootSuite,
testEnvironmentId
});
await action.run();
});
export default submitCommand;