@checksum-ai/runtime 1.0.4 → 1.0.5
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/LICENSE +1 -0
- package/cli.js +16 -0
- package/index.js +50 -50
- package/package.json +1 -1
- package/postinstall.js +15 -0
- package/cli.ts +0 -225
package/LICENSE
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Checksum license
|
package/cli.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var g=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var k=(c,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of f(e))!d.call(c,o)&&o!==t&&l(c,o,{get:()=>e[o],enumerable:!(s=m(e,o))||s.enumerable});return c};var C=(c,e,t)=>(t=c!=null?g(p(c)):{},k(e||!c||!c.__esModule?l(t,"default",{value:c,enumerable:!0}):t,c));var i=require("fs"),r=C(require("child_process")),n=require("path"),y="checksum",u=class{constructor(){this.checksumConfig=void 0}async execute(){var e;switch(process.argv[2]){case"install":this.install();break;case"run":if(((e=process.argv)==null?void 0:e[3])==="--help"){await this.printHelp("run");break}await this.run(process.argv.slice(3));break;default:await this.printHelp()}process.exit(0)}async execCmd(e){let t=await r.spawn(e,{shell:!0,stdio:"inherit"});return new Promise((o,a)=>{t.on("exit",h=>{h===0?o(!0):a(new Error(`Checsum failed execution with code: ${h} for command: "${e}`))})})}async getCmdOutput(e){return new Promise(function(t,s){r.exec(e,(o,a,h)=>{if(o){s(`Error executing command: ${o.message}`);return}t(a)})})}async printHelp(e){switch(e){default:console.log(`
|
|
2
|
+
Checksum CLI
|
|
3
|
+
Usage: checksum [command] [options]
|
|
4
|
+
|
|
5
|
+
Commands:
|
|
6
|
+
install installs checksum files and folders
|
|
7
|
+
run runs checksum tests
|
|
8
|
+
help prints this help message
|
|
9
|
+
`);break;case"run":try{let t="npx playwright test --help",s=(await this.getCmdOutput(t)).replace(/npx playwright test/g,"yarn checksum run").split(`
|
|
10
|
+
`);s.splice(5,0," --checksum-config=<config> Checksum configuration in JSON format").join(`
|
|
11
|
+
`),console.log(s.join(`
|
|
12
|
+
`))}catch(t){console.log("Error",t.message)}break}}async run(e){e=this.getChecksumConfig(e);let t=`npx playwright test --config ${(0,n.join)(this.getRootDirPath(),"playwright.config.ts")} ${e.join(" ")}`;try{this.buildVolatileConfig(),await this.execCmd(t)}catch(s){console.log("Error",s.message)}finally{this.cleanup()}}buildVolatileConfig(){if(!this.checksumConfig)return;let e=this.getVolatileConfigPath(),t=`
|
|
13
|
+
import { RunMode, getChecksumConfig } from "@checksum-ai/runtime";
|
|
14
|
+
|
|
15
|
+
export default getChecksumConfig(${JSON.stringify(this.checksumConfig,null,2)});
|
|
16
|
+
`;(0,i.writeFileSync)(e,t)}cleanup(){let e=this.getVolatileConfigPath();(0,i.existsSync)(e)&&(0,i.rmSync)(e)}getVolatileConfigPath(){return(0,n.join)(this.getRootDirPath(),"checksum.config.tmp.ts")}getChecksumConfig(e){for(let t of e)if(t.startsWith("--checksum-config"))try{return this.checksumConfig=JSON.parse(t.split("=")[1]),e.filter(s=>s!==t)}catch(s){console.log("Error parsing checksum config",s.message),this.checksumConfig=void 0}return e}install(){console.log("Creating Checksum directory and necessary files to run your tests");let e=this.getRootDirPath();if((0,i.existsSync)(this.getRootDirPath())||(0,i.mkdirSync)(e),!(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","login.ts","README.md"].forEach(t=>{(0,i.copyFileSync)((0,n.join)(this.getChecksumRootOrigin(),t),(0,n.join)(e,t))}),(0,i.mkdirSync)((0,n.join)(e,"tests"),{recursive:!0}),["esra","har","trace","log"].forEach(t=>{(0,i.mkdirSync)((0,n.join)(e,"test-data",t),{recursive:!0})})}getRootDirPath(){return(0,n.join)(process.cwd(),y)}getChecksumRootOrigin(){return(0,n.join)(process.cwd(),"node_modules","@checksum-ai","runtime","checksum-root")}};(async()=>await new u().execute())();
|