@testmonitor/testmonitor-cli
Version:
The TestMonitor CLI lets you interact with the TestMonitor platform directly from your terminal or CI pipelines.
88 lines (77 loc) • 3.03 kB
JavaScript
import 'dotenv/config';
import fs from 'fs';
import { Command } from 'commander';
import { APIClient } from '../../lib/api-client.js';
import { Logger } from '../../lib/logger.js';
export async function handleSubmitJUnitXML(options, { client } = {}) {
const {
domain,
token,
file,
name,
automationType,
milestoneId,
milestoneName,
preserveNames,
skipRootSuite,
testEnvironmentId,
} = options;
const log = new Logger();
if (!fs.existsSync(file)) {
log.error(`File not found at path ${file}`);
process.exit(1);
}
const apiClient = client || new APIClient({ domain });
try {
const { data } = await log.spin(
'Submitting...',
() =>
apiClient.submitJUnitReport({
token,
filePath: file,
name,
automationType,
milestoneId,
milestoneName,
preserveNames,
skipRootSuite,
testEnvironmentId,
}),
{
successMessage: 'Report submitted.',
errorMessage: 'Failed to submit.',
}
);
log.line();
log.table([
['JUnit file', data.name],
['Test run code', data.test_run.code],
['Test run URL', data.test_run.links.show],
]);
} catch (error) {
const message = error.response?.data?.message || error.message;
log.line();
log.error(message, error);
process.exit(1);
}
}
// Command to submit a JUnit XML file
export const submitJUnitXMLCommand = new Command('submit')
.name('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('-t, --token <id>', 'Your JUnit token')
.requiredOption('-f, --file <path>', 'Path to your JUnit XML file')
.option(
'-a, --automation-type <type>',
'The automation test type (e.g., cucumber, jest, playwright, phpunit, ranorex, selenium).'
)
.option('-m, --milestone-id <id>', 'Milestone ID for the new test run (required if not set in configuration)')
.option('-o, --milestone-name <name>', 'Find or create a milestone by name for the test run.')
.option('-n, --name <name>', 'Custom name for the test run (auto-generated if omitted).')
.option('-p, --preserve-names', 'Preserve test case names exactly as in the XML file.')
.option('-s, --skip-root-suite', 'Skip the root suite and start from nested suites.')
.option('-e, --test-environment-id <id>', 'Test environment ID for the new test run.')
.option('-v, --verbose', 'Enable verbose debug output.')
.action((options) => handleSubmitJUnitXML(options));