@checksum-ai/runtime 1.0.72 → 1.0.74
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 +2 -2
- package/package.json +1 -1
- package/test-run-monitor.js +3 -33
package/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var k=Object.create;var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var u=(n,t)=>p(n,"name",{value:t,configurable:!0});var S=(n,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of P(t))!T.call(n,s)&&s!==e&&p(n,s,{get:()=>t[s],enumerable:!(o=R(t,s))||o.enumerable});return n};var E=(n,t,e)=>(e=n!=null?k(x(n)):{},S(t||!n||!n.__esModule?p(e,"default",{value:n,enumerable:!0}):e,n));var r=require("fs"),g=E(require("child_process")),i=require("path");var m="checksum";var f=!1;function C(n){f=n}u(C,"setLogToConsole");function c(...n){f&&console.log(...n)}u(c,"log");function
|
|
1
|
+
var k=Object.create;var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var u=(n,t)=>p(n,"name",{value:t,configurable:!0});var S=(n,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of P(t))!T.call(n,s)&&s!==e&&p(n,s,{get:()=>t[s],enumerable:!(o=R(t,s))||o.enumerable});return n};var E=(n,t,e)=>(e=n!=null?k(x(n)):{},S(t||!n||!n.__esModule?p(e,"default",{value:n,enumerable:!0}):e,n));var r=require("fs"),g=E(require("child_process")),i=require("path");var m="checksum";var f=!1;function C(n){f=n}u(C,"setLogToConsole");function c(...n){f&&console.log(...n)}u(c,"log");function y({isInit:n,excludeLogin:t}){return[...n?["example.checksum.spec.ts","github-actions.example.yml"]:[],...t?[]:["login.ts"],"checksum.config.ts","playwright.config.ts","README.md",".gitignore.example"]}u(y,"getRuntimeFiles");var h=class{constructor(){this.TEST_RUN_MONITOR_PATH=(0,i.join)(__dirname,"test-run-monitor.js");this.CHECKSUM_API_URL="https://api.checksum.ai";this.CHECKSUM_APP_URL="https://app.checksum.ai";this.didFail=!1;this.isolationMode=!1;this.debugMode=!1;this.completeIndicators={upload:!1,tests:!1,report:!1};this.guardReturn=async(t,e=1e3,o="guardReturnTimedOut")=>{let s="guard-timed-out",a=u(async()=>(await this.awaitSleep(e+1e3),s),"guard"),l=await Promise.race([t,a()]);if(typeof l=="string"&&l===s)throw new Error(o);return l};this.awaitSleep=t=>new Promise(e=>setTimeout(e,t));this.printError=t=>{console.log("\x1B[31m%s\x1B[0m",t)}}async execute(){switch(process.argv.find(t=>t==="--help"||t==="-h")&&(await this.printHelp(process.argv[2]),process.exit(0)),process.argv.find(t=>t==="--clidebug")&&(this.debugMode=!0,C(!0)),process.argv[2]){case"init":this.install();break;case"test":await this.test(process.argv.slice(3));break;case"show-report":this.showReport(process.argv.slice(3));break;default:await this.printHelp()}process.exit(0)}async execCmd(t,e={}){let o={...process.env,...e},s=await g.spawn(t,{env:o,shell:!0,stdio:"inherit"});return new Promise((l,w)=>{s.on("exit",d=>{d===0?l(!0):w(new Error(`Checsum failed execution with code: ${d} `))})})}async getCmdOutput(t){return new Promise(function(e,o){g.exec(t,(s,a,l)=>{if(s){o(`Error executing command: ${s.message}`);return}e(a)})})}async printHelp(t){switch(t){default:console.log(`
|
|
2
2
|
Checksum CLI
|
|
3
3
|
Usage: checksum [command] [options]
|
|
4
4
|
|
|
@@ -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,r.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()),o=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 o.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{c("Sending test run end",t);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 sendProcessingError(){if(!this.isolationMode)try{await this.updateTestRun(`${this.CHECKSUM_API_URL}/client-api/test-runs/${this.testSession}/process-error`,"PATCH")}catch(t){console.log("Error sending test run processing error",t.message)}}async updateTestRun(t,e,o=void 0){let s=await fetch(t,{method:e,headers:{Accept:"application/json","Content-Type":"application/json",ChecksumAppCode:this.config.apiKey},body:o});return c("Received update test run response from url:",t),await this.logApiResponse(s),s}async logApiResponse(t){try{if(!t.ok){c("HTTP Error:",t.status,t.statusText);let o=await t.text();c("Error Details:",o);return}t.headers.get("Content-Type").includes("application/json")?t.json().then(o=>{c("API Response:",o)}):t.text().then(o=>{c("API Response:",o)})}catch(e){c("Error logging API response",e.message)}}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,i.join)(this.checksumRoot,"checksum.config.tmp.ts")}deleteVolatileConfig(){let t=this.getVolatileConfigPath();(0,r.existsSync)(t)&&(0,r.rmSync)(t)}setChecksumConfig(){this.config={...require((0,i.join)(this.checksumRoot,"checksum.config.ts")).default||{},...this.volatileChecksumConfig||{}},this.debugMode&&(this.config.options.printLogs=!0),this.config.apiURL&&(this.CHECKSUM_API_URL=this.config.apiURL)}processChecksumArguments(t){this.deleteVolatileConfig();for(let e=0;e<t.length;e++){let o=t[e];if(o.startsWith("--checksum-config"))try{this.volatileChecksumConfig=JSON.parse(o.split("=")[1]),t.splice(e,1)}catch(s){console.log("Error parsing checksum config",s.message),this.volatileChecksumConfig=void 0}o==="--clidebug"&&t.splice(e,1)}}install(){console.log("Creating Checksum directory and necessary files to run your tests")
|
|
19
|
+
`;(0,r.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()),o=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 o.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{c("Sending test run end",t);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 sendProcessingError(){if(!this.isolationMode)try{await this.updateTestRun(`${this.CHECKSUM_API_URL}/client-api/test-runs/${this.testSession}/process-error`,"PATCH")}catch(t){console.log("Error sending test run processing error",t.message)}}async updateTestRun(t,e,o=void 0){let s=await fetch(t,{method:e,headers:{Accept:"application/json","Content-Type":"application/json",ChecksumAppCode:this.config.apiKey},body:o});return c("Received update test run response from url:",t),await this.logApiResponse(s),s}async logApiResponse(t){try{if(!t.ok){c("HTTP Error:",t.status,t.statusText);let o=await t.text();c("Error Details:",o);return}t.headers.get("Content-Type").includes("application/json")?t.json().then(o=>{c("API Response:",o)}):t.text().then(o=>{c("API Response:",o)})}catch(e){c("Error logging API response",e.message)}}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,i.join)(this.checksumRoot,"checksum.config.tmp.ts")}deleteVolatileConfig(){let t=this.getVolatileConfigPath();(0,r.existsSync)(t)&&(0,r.rmSync)(t)}setChecksumConfig(){this.config={...require((0,i.join)(this.checksumRoot,"checksum.config.ts")).default||{},...this.volatileChecksumConfig||{}},this.debugMode&&(this.config.options.printLogs=!0),this.config.apiURL&&(this.CHECKSUM_API_URL=this.config.apiURL)}processChecksumArguments(t){this.deleteVolatileConfig();for(let e=0;e<t.length;e++){let o=t[e];if(o.startsWith("--checksum-config"))try{this.volatileChecksumConfig=JSON.parse(o.split("=")[1]),t.splice(e,1)}catch(s){console.log("Error parsing checksum config",s.message),this.volatileChecksumConfig=void 0}o==="--clidebug"&&t.splice(e,1)}}install(){console.log("Creating Checksum directory and necessary files to run your tests");try{this.findChecksumRootOrigin()}catch(o){console.log(o.message),process.exit(1)}let t=(0,i.join)(process.cwd(),m);if((0,r.existsSync)(t)||(0,r.mkdirSync)(t),!(0,r.existsSync)(this.getChecksumRootOrigin()))throw new Error("Could not find checksum root directory, please install @checksum-ai/runtime package");let e=(0,r.existsSync)((0,i.join)(t,"checksum.config.ts"));y({isInit:!e}).forEach(o=>{let s=(0,i.join)(t,o);(0,r.existsSync)(s)||(0,r.copyFileSync)((0,i.join)(this.getChecksumRootOrigin(),o),s)}),(0,r.mkdirSync)((0,i.join)(t,"tests"),{recursive:!0}),["esra","har","trace","log"].forEach(o=>{(0,r.mkdirSync)((0,i.join)(t,"test-data",o),{recursive:!0})})}getChecksumRootOrigin(){return(0,i.join)(this.projectRootDirectory,"node_modules","@checksum-ai","runtime","checksum-root")}locateChecksumLibs(){try{this.findChecksumRootOrigin(),this.findChecksumRoot(),c("Project root found at",this.projectRootDirectory),c("Checksum root found at",this.checksumRoot)}catch(t){console.log(t.message),process.exit(1)}}findChecksumRootOrigin(){let t=process.cwd();for(let e=0;e<6;e++){let o=(0,i.join)(t,"node_modules","@checksum-ai","runtime","checksum-root");if((0,r.existsSync)(o)){this.projectRootDirectory=t;return}if((0,i.parse)(t).root===t)break;t=(0,i.join)(t,"..")}throw new Error("Could not resolve checksum root origins")}findChecksumRoot(){let t=u(e=>{try{return(0,r.readdirSync)(e).includes("checksum.config.ts")}catch{return!1}},"containsChecksumConfig");try{let e=[this.projectRootDirectory];for(;e.length;){let o=e.pop(),s=(0,r.readdirSync)(o,{withFileTypes:!0});for(let a of s)if(a.isDirectory()){let l=(0,i.join)(o,a.name);if(a.name===m){if(t(l)){this.checksumRoot=l;return}}else e.push(l)}}}catch(e){throw e}throw new Error("Could not find checksum root folder. Run `npx checksumai init` to create one.")}};u(h,"ChecksumCLI");(async()=>await new h().execute())();
|