@checksum-ai/runtime 1.0.70 → 1.0.71
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/.DS_Store +0 -0
- package/checksumlib.js +3 -3
- package/index.js +1 -1
- package/package.json +1 -1
- package/test-run-monitor.js +4 -33
package/index.js
CHANGED
|
@@ -275,7 +275,7 @@ Executing locator ${this.getCurrentLocatorInChain().type} with ${typeof t=="stri
|
|
|
275
275
|
locators:
|
|
276
276
|
${this.selectionData.map(h=>h.generatedLocator).join(`
|
|
277
277
|
`)}`:"")),await ub(this.page.waitForLoadState("networkidle"));let p=c||!this.options.newAssertionsEnabled?[]:await this.evaluateWithChecksum(async()=>await window.checksum.testRunner.stopMonitoringAndGenerateAssertions());this.selectionData.forEach(h=>{c&&(h.esraMetadata=void 0,h.generatedLocator=void 0)}),this.runMode==="heal"&&(this.didHeal=!0),this.codeMirror.load(this.testInfo.file,this.checksumTestId),(L=(J=this.selectionData)==null?void 0:J[0].method)!=null&&L.name?this.codeMirror.updateChecksumStep(this.checksumStepInitialCallInTestFile.line,v,this.selectionData,!this.checksumStepStack.length):this.codeMirror.updateCommandFromLine((g=this.getCurrentLocatorChain())==null?void 0:g[0].line,this.getCurrentLocatorChain(),t,p,this.selectionData[0])}async onStepFailure(){await this.evaluateWithChecksum(async()=>{var t,c;return await((c=(t=window.checksum)==null?void 0:t.testRunner)==null?void 0:c.stopMonitoring())})}async initiateFallbackSequence(t,c,l,v){for(let b of this.fallbacks)try{b.toString()&&console.log(`Executing ${b.toString()}`);let J=await b.resolve({locator:c,method:l,args:v});if(!J){b.toString()&&console.log("Execution failed.");continue}return console.log("Executed successfully."),this.onFallbackSuccess(),this.runMode==="heal"&&(this.selectionData=J),await this.onStepSuccess(t,!1,!0),this.resetFallbacks(),!0}catch(J){pc(`Exception during ${b.toString()} `,J);continue}if(this.didFail=!0,await this.addFailPhase(),this.resetFallbacks(),this.originalActionError)throw this.originalActionError;let p=new Error("Checksum failed to recover from the errors. Please review the test, fix the code and try again.");throw p.stack="",p}async addFailPhase(){return this.phase="fail",this.page.evaluate(async()=>!0)}getTimeout(t,c){let l=["fill","dragTo"].includes(t)?1:0;return(c[l]??{}).timeout??3e4}async evaluateWithChecksum(t,c){return this.navigationPromise&&await this.navigationPromise,this.page.evaluate(t,c)}resetFallbacks(){this.fallbacks=[this.constructFallback(gy).init()]}sortFallbacks(){let t=[gy,py,Hp];this.fallbacks.sort((c,l)=>t.indexOf(c.constructor)-t.indexOf(l.constructor))}constructFallback(t){return new t(this.page,this.setPhase,{generateSelectionData:this.runMode!=="normal"})}};r(Lg,"ChecksumPage");var Ch=g1(j7()),z7=g1(require("path")),Sm=require("fs");var U7=r(e=>{let t=e;return t=y1(t,"'","\\'"),t=y1(t,/\\/g,"\\\\"),t=y1(t,/"/g,'\\"'),t=y1(t,`
|
|
278
|
-
`,"\\n"),t},"escapeString");var c2=class{constructor(t){this.appRules=t}toAssertionCode(t){switch(t.type){case"text_element_appear":case"text_element_disappear":return this.makeTextElementAssertion(t);case"page_url_change":{let c=this.appRules?this.appRules.resolvePageIdFromUrl(t.url):null;if(c!==t.url&&c!==null&&c!=="unknown-page"){let l=this.appRules.getPageRegexMatchingUrl(t.url);if(l){let v=l.toString().replace(
|
|
278
|
+
`,"\\n"),t},"escapeString");var c2=class{constructor(t){this.appRules=t}toAssertionCode(t){switch(t.type){case"text_element_appear":case"text_element_disappear":return this.makeTextElementAssertion(t);case"page_url_change":{let c=this.appRules?this.appRules.resolvePageIdFromUrl(t.url):null;if(c!==t.url&&c!==null&&c!=="unknown-page"){let l=this.appRules.getPageRegexMatchingUrl(t.url);if(l){let v=l.toString().replace(/(?<!\\)\//g,"\\/");return v.startsWith("^")&&(v=v.substring(1)),v.endsWith("$")&&(v=v.substring(0,v.length-1)),`await expect(page).toHaveURL(/${v}(\\?.*)?(\\#.*)?$/)`}throw new Error("None of the page URLs matched the assertion url.")}else return`await expect(page).toHaveURL("${t.url.toString().replace(/"/g,'\\"')}")`}default:throw new Error(`Unexpected value for assertion.type: ${t.type} in TestGeneratorCodegen.addAssertion`)}}makeTextElementAssertion(t){let l=`await expect(page.getByText("${U7(t.text.toString())}", { exact: true }))`;switch(t.type){case"text_element_appear":return`${l}.toBeVisible()`;case"text_element_disappear":return`${l}.not.toBeVisible()`}}};r(c2,"AssertionCodeGenerator");var bv=class{constructor(t){this.runMode=t;this.lines=[];this.linesOffsetFromOriginalFile=0;let c={getPageRegexMatchingUrl:()=>null,resolvePageIdFromUrl:()=>null};this.assertionCodeGenerator=new c2(c)}static init(t){return new bv(t)}static initWithContent(t,c){let l=new bv("normal");return l.lines=[t],l}async load(t,c){if(this.filename)return;this.filename=t,this.testId=c;let l=this.getProcessedFilename(this.filename);(0,Sm.existsSync)(l)&&(0,Sm.unlinkSync)(l),this.lines=["",...(0,Sm.readFileSync)(this.filename,"utf-8").split(`
|
|
279
279
|
`)];try{this.esraMetadataMap=await lb(th(l),c)}catch{console.log("[CodeMirror] Failed loading ESRA metadata for test file, creating new ESRA map"),this.esraMetadataMap={}}}addTestToCode(t,c){let l=Ch.createSourceFile("",this.lines.join(""),Ch.ScriptTarget.ES2015),v=this.findTitleInParentNode(this.getSourceFileChildren(l),l,t.description);if(v){let J=l.text.substring(0,v.pos)+c.generateSingleTestCode(t)+l.text.substring(v.end);return c.styleCode(J)}let p=this.getLastDescribeNode(this.getSourceFileChildren(l),l);if(p){let J=l.text.substring(0,l.text.substring(0,p.end).lastIndexOf("}")-1)+c.generateSingleTestCode(t)+"});";return c.styleCode(J)}let b=l.text+`
|
|
280
280
|
|
|
281
281
|
`+c.generateSingleTestCode(t);return c.styleCode(b)}findTitleInParentNode(t,c,l){for(let v of t)if(this.isDescribeNode(v,c)){let p=this.findTitleInParentNode(this.getDescribeNodeChildren(v,c),c,l);if(p)return p}else if(this.isTestNode(v,c)&&this.isTestWithTitle(v,l))return v}getLastDescribeNode(t,c){for(let l=t.length-1;l>=0;l--){let v=t[l];if(this.isDescribeNode(v,c)){let p=this.getLastDescribeNode(this.getDescribeNodeChildren(v,c),c);return p||v}}}isDescribeNode(t,c){return Ch.isExpressionStatement(t)&&t.expression.getText(c).startsWith("test.describe")}getDescribeNodeChildren(t,c){var l,v,p;return((p=(v=(l=t.expression)==null?void 0:l.arguments)==null?void 0:v[1].body)==null?void 0:p.statements)??[]}getSourceFileChildren(t){return t.statements}isTestNode(t,c){return Ch.isExpressionStatement(t)&&t.expression.getText(c).startsWith("test(")}isTestWithTitle(t,c){var l,v,p;return((p=(v=(l=t==null?void 0:t.expression)==null?void 0:l.arguments)==null?void 0:v[0])==null?void 0:p.text)===c}updateChecksumStep(t,c,l,v=!1){let[p,b]=v?this.getStepLineBoundries(t):this.getChecksumStepLineBoundries(t),J=this.lines.slice(p+this.linesOffsetFromOriginalFile,b+1+this.linesOffsetFromOriginalFile),L=this.generateChecksumStep(c,l);this.lines.splice(p+this.linesOffsetFromOriginalFile,J.length,...L),this.linesOffsetFromOriginalFile+=L.length-J.length}generateChecksumStep(t,c){return` await page.withChecksumStep("${t}", async () => {
|