@checksum-ai/runtime 1.0.53 → 1.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli.js CHANGED
@@ -16,4 +16,4 @@ show-report [options] [report] show HTML report
16
16
  import { RunMode, getChecksumConfig } from "@checksum-ai/runtime";
17
17
 
18
18
  export default getChecksumConfig(${JSON.stringify(this.config,null,2)});
19
- `;(0,i.writeFileSync)(t,e)}cleanup(){var t,e;this.deleteVolatileConfig(),(t=this.testRunMonitorProcess)==null||t.stdin.write("cli:shutdown"),(e=this.testRunMonitorProcess)==null||e.kill()}async getSession(){try{if(!this.config.options.hostReports)return this.setIsolatedMode(),!0;let t=this.config.apiKey;if(!t||t==="<API key>")return this.printError("No API key found in checksum config - please set it in the config file - checksum.config.ts"),this.shutdown(1),!1;let e=JSON.stringify(await this.getEnvInfo()),s=await fetch(`${this.CHECKSUM_API_URL}/client-api/test-runs`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",ChecksumAppCode:t},body:e});return this.testSession=(await s.json()).uuid,!0}catch{return console.log("Error connecting to Checksum, the report will not be hosted"),this.setIsolatedMode(),!0}}setIsolatedMode(){this.isolationMode=!0,this.testSession="isolated-session"}async sendTestRunEnd(t){if(!this.isolationMode)try{let e=JSON.stringify({...t,endedAt:Date.now()});await this.updateTestRun(`${this.CHECKSUM_API_URL}/client-api/test-runs/${this.testSession}`,"PATCH",e)}catch(e){return console.log("Error sending test run end",e.message),null}}async sendUploadsComplete(){if(!this.isolationMode)try{await this.updateTestRun(`${this.CHECKSUM_API_URL}/client-api/test-runs/${this.testSession}/uploads-completed`,"PATCH")}catch(t){console.log("Error sending test run uploads complete",t.message)}}async updateTestRun(t,e,s=void 0){return(await fetch(t,{method:e,headers:{Accept:"application/json","Content-Type":"application/json",ChecksumAppCode:this.config.apiKey},body:s})).json()}async getEnvInfo(){let t={commitHash:"",branch:"branch",environment:process.env.CI?"CI":"local",name:"name",startedAt:Date.now()};try{t.commitHash=(await this.getCmdOutput("git rev-parse HEAD")).toString().trim()}catch(e){console.log("Error getting git hash",e.message)}try{t.branch=(await this.getCmdOutput("git rev-parse --abbrev-ref HEAD")).toString().trim()}catch(e){console.log("Error getting branch",e.message)}try{t.name=(await this.getCmdOutput("git log -1 --pretty=%B")).toString().trim()}catch(e){console.log("Error getting name",e.message)}return t}getVolatileConfigPath(){return(0,r.join)(this.getRootDirPath(),"checksum.config.tmp.ts")}deleteVolatileConfig(){let t=this.getVolatileConfigPath();(0,i.existsSync)(t)&&(0,i.rmSync)(t)}setChecksumConfig(){this.config={...require((0,r.join)(this.getRootDirPath(),"checksum.config.ts")).default||{},...this.volatileChecksumConfig||{}},this.config.apiURL&&(this.CHECKSUM_API_URL=this.config.apiURL)}processChecksumArguments(t){this.deleteVolatileConfig();for(let e of t)if(e.startsWith("--checksum-config"))try{this.volatileChecksumConfig=JSON.parse(e.split("=")[1]),t=t.filter(s=>s!==e)}catch(s){console.log("Error parsing checksum config",s.message),this.volatileChecksumConfig=void 0}}install(){console.log("Creating Checksum directory and necessary files to run your tests");let t=this.getRootDirPath();if((0,i.existsSync)(this.getRootDirPath())||(0,i.mkdirSync)(t),!(0,i.existsSync)(this.getChecksumRootOrigin()))throw new Error("Could not find checksum root directory, please install @checksum-ai/runtime package");["checksum.config.ts","playwright.config.ts","example.checksum.spec.ts","login.ts","README.md"].forEach(e=>{let s=(0,r.join)(t,e);(0,i.existsSync)(s)||(0,i.copyFileSync)((0,r.join)(this.getChecksumRootOrigin(),e),s)}),(0,i.mkdirSync)((0,r.join)(t,"tests"),{recursive:!0}),["esra","har","trace","log"].forEach(e=>{(0,i.mkdirSync)((0,r.join)(t,"test-data",e),{recursive:!0})})}getRootDirPath(){return(0,r.join)(process.cwd(),d)}getChecksumRootOrigin(){return(0,r.join)(process.cwd(),"node_modules","@checksum-ai","runtime","checksum-root")}};u(h,"ChecksumCLI");(async()=>await new h().execute())();
19
+ `;(0,i.writeFileSync)(t,e)}cleanup(){var t,e;this.deleteVolatileConfig(),(t=this.testRunMonitorProcess)==null||t.stdin.write("cli:shutdown"),(e=this.testRunMonitorProcess)==null||e.kill()}async getSession(){try{if(!this.config.options.hostReports)return this.setIsolatedMode(),!0;let t=this.config.apiKey;if(!t||t==="<API key>")return this.printError("No API key found in checksum config - please set it in the config file - checksum.config.ts"),this.shutdown(1),!1;let e=JSON.stringify(await this.getEnvInfo()),s=await fetch(`${this.CHECKSUM_API_URL}/client-api/test-runs`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",ChecksumAppCode:t},body:e});return this.testSession=(await s.json()).uuid,!0}catch{return console.log("Error connecting to Checksum, the report will not be hosted"),this.setIsolatedMode(),!0}}setIsolatedMode(){this.isolationMode=!0,this.testSession="isolated-session"}async sendTestRunEnd(t){if(!this.isolationMode)try{let e=JSON.stringify({...t,endedAt:Date.now()});await this.updateTestRun(`${this.CHECKSUM_API_URL}/client-api/test-runs/${this.testSession}`,"PATCH",e)}catch(e){return console.log("Error sending test run end",e.message),null}}async sendUploadsComplete(){if(!this.isolationMode)try{await this.updateTestRun(`${this.CHECKSUM_API_URL}/client-api/test-runs/${this.testSession}/uploads-completed`,"PATCH")}catch(t){console.log("Error sending test run uploads complete",t.message)}}async updateTestRun(t,e,s=void 0){return(await fetch(t,{method:e,headers:{Accept:"application/json","Content-Type":"application/json",ChecksumAppCode:this.config.apiKey},body:s})).json()}async getEnvInfo(){let t={commitHash:"",branch:"branch",environment:process.env.CI?"CI":"local",name:"name",startedAt:Date.now()};try{t.commitHash=(await this.getCmdOutput("git rev-parse HEAD")).toString().trim()}catch(e){console.log("Error getting git hash",e.message)}try{t.branch=(await this.getCmdOutput("git rev-parse --abbrev-ref HEAD")).toString().trim()}catch(e){console.log("Error getting branch",e.message)}try{t.name=(await this.getCmdOutput("git log -1 --pretty=%B")).toString().trim()}catch(e){console.log("Error getting name",e.message)}return t}getVolatileConfigPath(){return(0,r.join)(this.getRootDirPath(),"checksum.config.tmp.ts")}deleteVolatileConfig(){let t=this.getVolatileConfigPath();(0,i.existsSync)(t)&&(0,i.rmSync)(t)}setChecksumConfig(){this.config={...require((0,r.join)(this.getRootDirPath(),"checksum.config.ts")).default||{},...this.volatileChecksumConfig||{}},this.config.apiURL&&(this.CHECKSUM_API_URL=this.config.apiURL)}processChecksumArguments(t){this.deleteVolatileConfig();for(let e of t)if(e.startsWith("--checksum-config"))try{this.volatileChecksumConfig=JSON.parse(e.split("=")[1]),t=t.filter(s=>s!==e)}catch(s){console.log("Error parsing checksum config",s.message),this.volatileChecksumConfig=void 0}}install(){console.log("Creating Checksum directory and necessary files to run your tests");let t=this.getRootDirPath();if((0,i.existsSync)(this.getRootDirPath())||(0,i.mkdirSync)(t),!(0,i.existsSync)(this.getChecksumRootOrigin()))throw new Error("Could not find checksum root directory, please install @checksum-ai/runtime package");[...(0,i.existsSync)((0,r.join)(t,"checksum.config.ts"))?[]:["example.checksum.spec.ts","github-actions.example.yml"],"checksum.config.ts","playwright.config.ts","login.ts","README.md",".gitignore"].forEach(s=>{let o=(0,r.join)(t,s);(0,i.existsSync)(o)||(0,i.copyFileSync)((0,r.join)(this.getChecksumRootOrigin(),s),o)}),(0,i.mkdirSync)((0,r.join)(t,"tests"),{recursive:!0}),["esra","har","trace","log"].forEach(s=>{(0,i.mkdirSync)((0,r.join)(t,"test-data",s),{recursive:!0})})}getRootDirPath(){return(0,r.join)(process.cwd(),d)}getChecksumRootOrigin(){return(0,r.join)(process.cwd(),"node_modules","@checksum-ai","runtime","checksum-root")}};u(h,"ChecksumCLI");(async()=>await new h().execute())();