UNPKG

@testmonitor/testmonitor-cli

Version:

The TestMonitor CLI lets you interact with the TestMonitor platform directly from your terminal or CI pipelines.

3 lines (2 loc) 6.22 kB
#!/usr/bin/env node var T=Object.defineProperty;var U=(n,e)=>()=>(n&&(e=n(n=0)),e);var L=(n,e)=>{for(var t in e)T(n,t,{get:e[t],enumerable:!0})};var v={};L(v,{default:()=>D});var D,_=U(()=>{D={name:"@testmonitor/testmonitor-cli",type:"module",version:"1.0.0",description:"The TestMonitor CLI lets you interact with the TestMonitor platform directly from your terminal or CI pipelines.",keywords:["testmonitor","cli"],homepage:"https://www.testmonitor.com/",bugs:{url:"https://github.com/testmonitor/testmonitor-cli/issues"},repository:{type:"git",url:"git+https://github.com/testmonitor/testmonitor-cli.git"},author:"TestMonitor | we are Cerios B.V.",main:"src/index.js",bin:{"testmonitor-cli":"dist/index.js"},scripts:{start:"node src/index.js",build:"node esbuild.config.js",prepare:"npm run build",lint:"eslint .","lint:fix":"eslint . --fix",test:"NODE_OPTIONS='--experimental-vm-modules' jest","test:watch":"NODE_OPTIONS='--experimental-vm-modules' jest --watch","test:coverage":"NODE_OPTIONS='--experimental-vm-modules' jest --coverage"},dependencies:{axios:"^1.7.9",chalk:"^5.4.1",commander:"^14.0.0",dotenv:"^17.2.0",ora:"^8.2.0","strip-ansi":"^7.1.0",table:"^6.9.0"},devDependencies:{chai:"^5.2.0",esbuild:"^0.25.6",eslint:"^9.31.0","eslint-config-prettier":"^10.1.5","eslint-formatter-junit":"^8.40.0","eslint-plugin-import":"^2.32.0","eslint-plugin-jest":"^28.14.0","eslint-plugin-jsdoc":"^51.4.1",jest:"^29.7.0","jest-junit":"^16.0.0",prettier:"^3.6.2"},engines:{node:">=18.0.0"}}});import"dotenv/config";import{Command as B}from"commander";async function h(){return"1.0.0"}import{Command as A}from"commander";import"dotenv/config";import q from"fs";import{Command as X}from"commander";import $ from"os";import I from"fs";import S from"axios";import x from"form-data";var E=await h(),R=`NodeJS/${process.nodeVersion}`,J=`${$.platform()} ${$.release()}`,N=`TestMonitorCLI/${E} (${R}; ${J}; +https://www.testmonitor.com/)`,f=class{constructor({domain:e,httpClient:t}){this.baseURL=`https://${e}/api/v1`,this.httpClient=t||S.create({baseURL:this.baseURL,headers:{"User-Agent":N}})}async get(e,t={}){return this._request("get",e,null,t)}async post(e,t={},o={}){return this._request("post",e,t,o)}async put(e,t={},o={}){return this._request("put",e,t,o)}async delete(e,t={}){return this._request("delete",e,null,t)}async _request(e,t,o,s){let c={...o instanceof x?o.getHeaders():{"Content-Type":"application/json"},...s.headers||{}};try{return(await this.httpClient.request({method:e,url:t,data:o,headers:c,...s})).data}catch(a){let u=a.response?.data?.message||a.message;throw new Error(u)}}async submitJUnitReport({token:e,filePath:t,name:o,automationType:s,milestoneId:i,milestoneName:c,preserveNames:a,skipRootSuite:u,testEnvironmentId:b}){let p=new x;p.append("token",e),p.append("report",I.createReadStream(t));let w={name:o,milestone:c,milestone_id:i,preserve_names:a?1:null,skip_root_suite:u?1:null,test_environment_id:b,type:s};for(let[r,d]of Object.entries(w))d!=null&&p.append(r,d);return this.post("/reporters/junit/submit",p)}};import l from"chalk";import P from"ora";import{table as V}from"table";var g=class{#e="TestMonitor";info(e){console.log(`${this.#e}: ${e}`)}success(e){console.log(`${this.#e}: ${l.green(e)}`)}warn(e){console.warn(`${this.#e}: ${l.yellow(e)}`)}error(e,t){let o=`${this.#e}: ${l.red(e)}`;console.error(o),process.env.DEBUG&&t instanceof Error&&console.error(l.gray(t.stack||t.message))}debug(e){process.env.DEBUG&&console.log(`${this.#e}: ${e}`)}line(e=""){console.log(e)}async spin(e,t,o={}){let s=P({text:`${this.#e}: ${e}`,color:"green"}).start();try{let i=await t();return s.succeed(`${this.#e}: ${l.green(o.successMessage||e)}`),i}catch(i){throw s.fail(`${this.#e}: ${l.red(o.errorMessage||e)}`),i}}table(e,t){let o=V(e,{singleLine:!0,...t});console.log(o)}};async function F(n,{client:e}={}){let{domain:t,token:o,file:s,name:i,automationType:c,milestoneId:a,milestoneName:u,preserveNames:b,skipRootSuite:p,testEnvironmentId:w}=n,r=new g;q.existsSync(s)||(r.error(`File not found at path ${s}`),process.exit(1));let d=e||new f({domain:t});try{let{data:m}=await r.spin("Submitting...",()=>d.submitJUnitReport({token:o,filePath:s,name:i,automationType:c,milestoneId:a,milestoneName:u,preserveNames:b,skipRootSuite:p,testEnvironmentId:w}),{successMessage:"Report submitted.",errorMessage:"Failed to submit."});r.line(),r.table([["JUnit file",m.name],["Test run code",m.test_run.code],["Test run URL",m.test_run.links.show]])}catch(m){let O=m.response?.data?.message||m.message;r.line(),r.error(O,m),process.exit(1)}}var j=new X("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(n=>F(n));var C=new A("junit").name("junit").description("Commands for JUnit XML report submission.").helpOption("-h, --help","Display help for command.");C.addCommand(j);var M=C;var y=new B;y.name("testmonitor-cli").version(await h(),"-v, --version","Display the current CLI version.").description("CLI tool for interacting with the TestMonitor API.").helpCommand(!1).helpOption("-h, --help","Display help for command.");y.on("option:verbose",function(){process.env.VERBOSE=this.opts().verbose});y.addCommand(M);y.parse(process.argv);