@checksum-ai/runtime 1.0.71 → 1.0.72

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
@@ -10,7 +10,7 @@ show-report [options] [report] show HTML report
10
10
  `);break;case"test":try{let e="npx playwright test --help",o=(await this.getCmdOutput(e)).replace(/npx playwright/g,"yarn checksum").split(`
11
11
  `);o.splice(5,0," --checksum-config=<config> Checksum configuration in JSON format").join(`
12
12
  `),console.log(o.join(`
13
- `))}catch(e){console.log("Error",e.message)}break;case"show-report":try{let e="npx playwright show-report --help",o=(await this.getCmdOutput(e)).replace(/npx playwright/g,"yarn checksum");console.log(o)}catch(e){console.log("Error",e.message)}break}}async showReport(t){let e=`npx playwright show-report ${t.join(" ")}`;try{await this.execCmd(e)}catch(o){console.log("Error showing report",o.message)}}async test(t){if(this.locateChecksumLibs(),this.processChecksumArguments(t),this.setChecksumConfig(),!await this.getSession())return;let e;try{e=await this.guardReturn(this.startTestRunMonitor(this.testSession),1e4,"test run monitor timeout")}catch{console.log("Error starting test run monitor. Test results will not be available on checksum.")}this.buildVolatileConfig();let o={CHECKSUM_ROOT_FOLDER:this.checksumRoot};e&&(o.CHECKSUM_UPLOAD_AGENT_PORT=e),this.config.options.hostReports&&(o.PW_TEST_HTML_REPORT_OPEN="never");let s=`npx playwright test --config ${this.getPlaywrightConfigFile()} ${t.map(a=>`"${a}"`).join(" ")}`;await this.patchPlaywright();try{await this.execCmd(s,o),console.log("Tests execution finished")}catch(a){this.didFail=!0,console.log("Error during test",a.message)}finally{this.sendReportUploadRequest(),await this.patchPlaywright(!0),this.completeIndicators.tests=!0,await this.handleCompleteMessage()}}sendReportUploadRequest(){this.isolationMode||console.log("Waiting for test files to upload to Checksum..");let t=this.getPlaywrightReportPath();if(!(0,r.existsSync)(t)){console.log(`Could not find report file at ${t}`);return}c("Sending report upload request",t),this.testRunMonitorProcess.stdin.write(`cli:report=${t}`)}async patchPlaywright(t=!1){c("Patching playwright",t);let e=`node ${(0,i.join)(__dirname,"scripts/patch.js")}${t?" off":""}`;try{await this.execCmd(e)}catch(o){console.log("Error patching playwright",o.message)}}getPlaywrightReportPath(){var s,a;let t=(0,i.join)(this.projectRootDirectory,"playwright-report"),e=require(this.getPlaywrightConfigFile()),{reporter:o}=e;return o instanceof Array&&o.length>1&&((s=o[1])!=null&&s.outputFolder)&&(t=(a=o[1])==null?void 0:a.outputFolder),process.env.PLAYWRIGHT_HTML_REPORT&&(t=process.env.PLAYWRIGHT_HTML_REPORT),(0,i.join)(t,"index.html")}getPlaywrightConfigFile(){return(0,i.join)(this.checksumRoot,"playwright.config.ts")}startTestRunMonitor(t){return new Promise(e=>{console.log("Starting test run monitor"),this.testRunMonitorProcess=g.spawn("node",[this.TEST_RUN_MONITOR_PATH,JSON.stringify({sessionId:t,checksumApiURL:this.CHECKSUM_API_URL,apiKey:this.config.apiKey}),...this.isolationMode?["isolated"]:[]]),this.testRunMonitorProcess.stdout.on("data",o=>{let s=o.toString().trim();if(c("[trm] "+s),!s.startsWith("monitor"))return;let[a,l]=s.substring(s.indexOf(":")+1).split("=");a==="port"?e(l):this.handleTestRunMonitorMessage(a,l)}),this.testRunMonitorProcess.on("exit",(o,s)=>{console.log(`test run monitor process exited with code ${o} and signal ${s}`)}),this.testRunMonitorProcess.on("error",o=>{console.error(`Error starting test run monitor: ${o.message}`)})})}async handleTestRunMonitorMessage(t,e){switch(c(`Handling test run monitor message ${this.isolationMode?"(isolation mode)":""}`,t,e),t){case"complete-with-errors":console.log("Error uploading test files to Checksum"),this.sendProcessingError().then(()=>{this.completeIndicators.upload=!0});break;case"complete":this.isolationMode||console.log("Test files uploaded successfully"),this.sendUploadsComplete().then(()=>{this.completeIndicators.upload=!0});break;case"report-uploaded":{if(this.isolationMode){this.completeIndicators.report=!0;break}console.log("Report generated and uploaded to Checksum");let o={};try{o=JSON.parse(e)}catch(s){console.log("Error parsing stats",s.message)}await this.sendTestRunEnd(o),this.completeIndicators.report=!0,console.log(`*******************
13
+ `))}catch(e){console.log("Error",e.message)}break;case"show-report":try{let e="npx playwright show-report --help",o=(await this.getCmdOutput(e)).replace(/npx playwright/g,"yarn checksum");console.log(o)}catch(e){console.log("Error",e.message)}break}}async showReport(t){let e=`npx playwright show-report ${t.join(" ")}`;try{await this.execCmd(e)}catch(o){console.log("Error showing report",o.message)}}async test(t){if(this.locateChecksumLibs(),this.processChecksumArguments(t),this.setChecksumConfig(),!await this.getSession())return;let e;try{e=await this.guardReturn(this.startTestRunMonitor(this.testSession),1e4,"test run monitor timeout")}catch{console.log("Error starting test run monitor. Test results will not be available on checksum.")}this.buildVolatileConfig();let o={CHECKSUM_ROOT_FOLDER:this.checksumRoot};e&&(o.CHECKSUM_UPLOAD_AGENT_PORT=e),this.config.options.hostReports&&(o.PW_TEST_HTML_REPORT_OPEN="never");let s=`npx playwright test --config ${this.getPlaywrightConfigFile()} ${t.map(a=>`"${a}"`).join(" ")}`;await this.patchPlaywright();try{await this.execCmd(s,o),console.log("Tests execution finished")}catch(a){this.didFail=!0,console.log("Error during test",a.message)}finally{this.sendReportUploadRequest(),await this.patchPlaywright(!0),this.completeIndicators.tests=!0,await this.handleCompleteMessage()}}sendReportUploadRequest(){this.isolationMode||console.log("Waiting for test files to upload to Checksum..");let t=this.getPlaywrightReportPath();if(!(0,r.existsSync)(t)){console.log(`Could not find report file at ${t}`);return}c("Sending report upload request",t),this.testRunMonitorProcess.stdin.write(`cli:report=${t}`)}async patchPlaywright(t=!1){c("Patching playwright",t);let e=`node ${(0,i.join)(__dirname,"scripts/patch.js")}${t?" off":""}`;try{await this.execCmd(e,{PROJECT_ROOT:this.projectRootDirectory})}catch(o){console.log("Error patching playwright",o.message)}}getPlaywrightReportPath(){var s,a;let t=(0,i.join)(this.projectRootDirectory,"playwright-report"),e=require(this.getPlaywrightConfigFile()),{reporter:o}=e;return o instanceof Array&&o.length>1&&((s=o[1])!=null&&s.outputFolder)&&(t=(a=o[1])==null?void 0:a.outputFolder),process.env.PLAYWRIGHT_HTML_REPORT&&(t=process.env.PLAYWRIGHT_HTML_REPORT),(0,i.join)(t,"index.html")}getPlaywrightConfigFile(){return(0,i.join)(this.checksumRoot,"playwright.config.ts")}startTestRunMonitor(t){return new Promise(e=>{console.log("Starting test run monitor"),this.testRunMonitorProcess=g.spawn("node",[this.TEST_RUN_MONITOR_PATH,JSON.stringify({sessionId:t,checksumApiURL:this.CHECKSUM_API_URL,apiKey:this.config.apiKey}),...this.isolationMode?["isolated"]:[]]),this.testRunMonitorProcess.stdout.on("data",o=>{let s=o.toString().trim();if(c("[trm] "+s),!s.startsWith("monitor"))return;let[a,l]=s.substring(s.indexOf(":")+1).split("=");a==="port"?e(l):this.handleTestRunMonitorMessage(a,l)}),this.testRunMonitorProcess.on("exit",(o,s)=>{console.log(`test run monitor process exited with code ${o} and signal ${s}`)}),this.testRunMonitorProcess.on("error",o=>{console.error(`Error starting test run monitor: ${o.message}`)})})}async handleTestRunMonitorMessage(t,e){switch(c(`Handling test run monitor message ${this.isolationMode?"(isolation mode)":""}`,t,e),t){case"complete-with-errors":console.log("Error uploading test files to Checksum"),this.sendProcessingError().then(()=>{this.completeIndicators.upload=!0});break;case"complete":this.isolationMode||console.log("Test files uploaded successfully"),this.sendUploadsComplete().then(()=>{this.completeIndicators.upload=!0});break;case"report-uploaded":{if(this.isolationMode){this.completeIndicators.report=!0;break}console.log("Report generated and uploaded to Checksum");let o={};try{o=JSON.parse(e)}catch(s){console.log("Error parsing stats",s.message)}await this.sendTestRunEnd(o),this.completeIndicators.report=!0,console.log(`*******************
14
14
  * Checksum report URL: ${this.CHECKSUM_APP_URL}/#/test-runs/${this.testSession}
15
15
  *******************`);break}default:console.warn(`Unhandled test run monitor message: ${t}=${e}`)}}async handleCompleteMessage(){for(;;)Object.keys(this.completeIndicators).find(t=>!this.completeIndicators[t])?(c(this.completeIndicators),await this.awaitSleep(1e3)):(console.log("Checksum test run complete"),this.shutdown(this.didFail?1:0))}shutdown(t=0){this.cleanup(),process.exit(t)}buildVolatileConfig(){if(!this.volatileChecksumConfig)return;let t=this.getVolatileConfigPath(),e=`
16
16
  import { RunMode, getChecksumConfig } from "@checksum-ai/runtime";