提交 3c27f732 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

chore(automator): 更新自动化测试框架

上级 e614d7e9
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs"),t=require("path"),s=require("debug"),n=require("merge"),i=require("jsonc-parser"),o=require("licia/isRelative"),r=require("ws"),a=require("events"),c=require("licia/uuid"),p=require("licia/stringify"),l=require("licia/dateFormat"),u=require("licia/waitUntil"),h=require("os"),d=require("address"),m=require("default-gateway"),g=require("licia/isStr"),v=require("licia/getPort"),y=require("qrcode-terminal"),f=require("licia/fs"),w=require("licia/isFn"),P=require("licia/trim"),I=require("licia/startWith"),M=require("licia/isNum"),_=require("licia/sleep"),k=require("licia/isUndef"),E=require("child_process"),A=require("licia/toStr"),U=require("fs-extra");function T(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var N=T(e),b=T(t),C=T(s),R=T(o),O=T(r),D=T(c),S=T(p),j=T(l),x=T(u),$=T(h),q=T(d),F=T(m),L=T(g),H=T(v),W=T(y),X=T(f),B=T(w),V=T(P),J=T(I),G=T(M),z=T(_),Y=T(k),K=T(A);class Q extends a.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",(e=>{this.emit("message",e.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(e){this.ws.send(e)}close(){this.ws.close()}}const Z=new Map,ee=["onCompassChange","onThemeChange","onUserCaptureScreen","onWindowResize","onMemoryWarning","onAccelerometerChange","onKeyboardHeightChange","onNetworkStatusChange","onPushMessage","onLocationChange","onGetWifiList","onWifiConnected","onWifiConnectedWithPartialInfo","onSocketOpen","onSocketError","onSocketMessage","onSocketClose"];const te=new Map;function se(e,t){(null==e?void 0:e.success)&&"function"==typeof(null==e?void 0:e.success)&&(t?e.success(t):e.success()),(null==e?void 0:e.complete)&&"function"==typeof(null==e?void 0:e.complete)&&(t?e.complete(t):e.complete())}function ne(e,t){(null==e?void 0:e.fail)&&"function"==typeof(null==e?void 0:e.fail)&&(t?e.fail(t):e.fail()),(null==e?void 0:e.complete)&&"function"==typeof(null==e?void 0:e.complete)&&(t?e.complete(t):e.complete())}async function ie(e,t){const[s,n]=function(e){return L.default(e)?[!0,[e]]:[!1,e]}(t),i=await e(n);return s?i[0]:i}function oe(e){try{return require(e)}catch(t){return require(require.resolve(e,{paths:[process.cwd()]}))}}/^win/.test(process.platform);const re="Connection closed";class ae extends a.EventEmitter{constructor(e,t,s){super(),this.puppet=t,this.namespace=s,this.callbacks=new Map,this.transport=e,this.isAlive=!0,this.id=Date.now(),this.debug=C.default("automator:protocol:"+this.namespace),this.onMessage=e=>{var t,s;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&'"pong"'===e)return;this.debug(`${j.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:n,method:i,error:o,result:r,params:a}=JSON.parse(e);if(null===(t=null==r?void 0:r.method)||void 0===t?void 0:t.startsWith("on"))return void((e,t)=>{const s=Z.get(e.method);(null==s?void 0:s.has(t))&&s.get(t)(e.data)})(r,n);if(null===(s=null==r?void 0:r.method)||void 0===s?void 0:s.startsWith("Socket.")){return void((e,t,s)=>{const n=te.get(t);(null==n?void 0:n.has(e))&&n.get(e)(s)})(r.method.replace("Socket.",""),r.id,r.data)}if(!n)return this.puppet.emit(i,a);const{callbacks:c}=this;if(n&&c.has(n)){const e=c.get(n);c.delete(n),o?e.reject(Error(o.message||o.detailMessage||o.errMsg)):e.resolve(r)}},this.onClose=()=>{this.callbacks.forEach((e=>{e.reject(Error(re))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},s=!0){if(s&&this.puppet.adapter.has(e))return this.puppet.adapter.send(this,e,t);const n=D.default(),i=S.default({id:n,method:e,params:t});return"ping"!==e&&this.debug(`${j.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${i}`),new Promise(((e,t)=>{try{this.transport.send(i)}catch(e){t(Error(re))}this.callbacks.set(n,{resolve:e,reject:t})}))}dispose(){this.transport.close()}startHeartbeat(){"true"===process.env.UNI_APP_X&&("android"===process.env.UNI_APP_PLATFORM?this.startXAndroidHeartbeat():"ios"===process.env.UNI_APP_PLATFORM&&this.startXIosHeartbeat())}startXAndroidHeartbeat(){const e=new Map,t=oe("adbkit"),s=$.default.platform();let n="",i="";"darwin"===s?(n='dumpsys activity | grep "Run"',i="logcat -b crash | grep -C 10 io.dcloud.uniappx"):"win32"===s&&(n='dumpsys activity | findstr "Run"',i="logcat | findstr UncaughtExceptionHandler"),e.set(this.id,setInterval((async()=>{if(!this.isAlive){const o=t.createClient(),r=await o.listDevices();if(!r.length)throw Error("Device not found");const a=r[0].id,c=await o.getProperties(a);return("1"===c["ro.kernel.qemu"]||"goldfish"===c["ro.hardware"])&&"win32"===s&&(i="logcat | grep UncaughtExceptionHandler"),o.shell(a,n).then((function(e){let t,s="";e.on("data",(function(e){s+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{s.includes("io.dcloud.uniapp")||console.log("Stop the test process.")}),50)}))})),o.shell(a,i).then((e=>{let t,s="";e.on("data",(e=>{s+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{console.log(`crash log: ${s}`)}),50)}))})),clearInterval(e.get(this.id)),e.delete(this.id),void this.dispose()}this.send("ping"),this.isAlive=!1}),5e3))}startXIosHeartbeat(){const e=new Map;e.set(this.id,setInterval((async()=>{if(!this.isAlive)return console.log("Stop the test process."),clearInterval(e.get(this.id)),e.delete(this.id),void this.dispose();this.send("ping"),this.isAlive=!1}),5e3))}static createDevtoolConnection(e,t){return new Promise(((s,n)=>{const i=new O.default(e);i.addEventListener("open",(()=>{s(new ae(new Q(i),t,"devtool"))})),i.addEventListener("error",n)}))}static createRuntimeConnection(e,t,s){return new Promise(((n,i)=>{C.default("automator:runtime")(`${j.default("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);const o=new O.default.Server({port:e});x.default((async()=>{if(t.runtimeConnection)return!0}),s,1e3).catch((()=>{o.close(),i("Failed to connect to runtime, please make sure the project is running")})),o.on("connection",(function(e){C.default("automator:runtime")(`${j.default("yyyy-mm-dd HH:MM:ss:l")} connected`);const s=new ae(new Q(e),t,"runtime");t.setRuntimeConnection(s),s.startHeartbeat(),n(s)})),t.setRuntimeServer(o)}))}}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("fs"),e=require("path"),n=require("debug"),s=require("merge"),i=require("jsonc-parser"),o=require("licia/isRelative"),r=require("ws"),a=require("events"),c=require("licia/uuid"),p=require("licia/stringify"),l=require("licia/dateFormat"),u=require("licia/waitUntil"),h=require("os"),d=require("address"),m=require("default-gateway"),g=require("licia/isStr"),y=require("licia/getPort"),v=require("qrcode-terminal"),f=require("licia/fs"),w=require("licia/isFn"),P=require("licia/trim"),M=require("licia/startWith"),I=require("licia/isNum"),k=require("licia/sleep"),E=require("licia/isUndef"),A=require("child_process"),_=require("licia/toStr"),b=require("fs-extra");function T(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var C=T(t),U=T(e),N=T(n),O=T(o),R=T(r),S=T(c),D=T(p),j=T(l),x=T(u),$=T(h),q=T(d),L=T(m),F=T(g),H=T(y),W=T(v),X=T(f),B=T(w),V=T(P),J=T(M),G=T(I),z=T(k),Y=T(E),K=T(_);class Q extends a.EventEmitter{constructor(t){super(),this.ws=t,this.ws.addEventListener("message",(t=>{this.emit("message",t.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(t){this.ws.send(t)}close(){this.ws.close()}}const Z=new Map,tt=["onCompassChange","onThemeChange","onUserCaptureScreen","onWindowResize","onMemoryWarning","onAccelerometerChange","onKeyboardHeightChange","onNetworkStatusChange","onPushMessage","onLocationChange","onGetWifiList","onWifiConnected","onWifiConnectedWithPartialInfo","onSocketOpen","onSocketError","onSocketMessage","onSocketClose"];const et=new Map;function nt(t,e){(null==t?void 0:t.success)&&"function"==typeof(null==t?void 0:t.success)&&(e?t.success(e):t.success()),(null==t?void 0:t.complete)&&"function"==typeof(null==t?void 0:t.complete)&&(e?t.complete(e):t.complete())}function st(t,e){(null==t?void 0:t.fail)&&"function"==typeof(null==t?void 0:t.fail)&&(e?t.fail(e):t.fail()),(null==t?void 0:t.complete)&&"function"==typeof(null==t?void 0:t.complete)&&(e?t.complete(e):t.complete())}async function it(t,e){const[n,s]=function(t){return F.default(t)?[!0,[t]]:[!1,t]}(e),i=await t(s);return n?i[0]:i}function ot(t){try{return require(t)}catch(e){return require(require.resolve(t,{paths:[process.cwd()]}))}}/^win/.test(process.platform);const rt="Connection closed";class at extends a.EventEmitter{constructor(t,e,n){super(),this.puppet=e,this.namespace=n,this.callbacks=new Map,this.transport=t,this.isAlive=!0,this.id=Date.now(),this.debug=N.default("automator:protocol:"+this.namespace),this.onMessage=t=>{var e,n;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&'"pong"'===t)return;this.debug(`${j.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${t}`);const{id:s,method:i,error:o,result:r,params:a}=JSON.parse(t);if(null===(e=null==r?void 0:r.method)||void 0===e?void 0:e.startsWith("on"))return void((t,e)=>{const n=Z.get(t.method);(null==n?void 0:n.has(e))&&n.get(e)(t.data)})(r,s);if(null===(n=null==r?void 0:r.method)||void 0===n?void 0:n.startsWith("Socket.")){return void((t,e,n)=>{const s=et.get(e);(null==s?void 0:s.has(t))&&s.get(t)(n)})(r.method.replace("Socket.",""),r.id,r.data)}if(!s)return this.puppet.emit(i,a);const{callbacks:c}=this;if(s&&c.has(s)){const t=c.get(s);c.delete(s),o?t.reject(Error(o.message||o.detailMessage||o.errMsg)):t.resolve(r)}},this.onClose=()=>{this.callbacks.forEach((t=>{t.reject(Error(rt))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(t,e={},n=!0){if(n&&this.puppet.adapter.has(t))return this.puppet.adapter.send(this,t,e);const s=S.default(),i=D.default({id:s,method:t,params:e});return"ping"!==t&&this.debug(`${j.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${i}`),new Promise(((t,e)=>{try{this.transport.send(i)}catch(t){e(Error(rt))}this.callbacks.set(s,{resolve:t,reject:e})}))}dispose(){this.transport.close()}startHeartbeat(){"true"===process.env.UNI_APP_X&&("android"===process.env.UNI_APP_PLATFORM?this.startXAndroidHeartbeat():"ios"===process.env.UNI_APP_PLATFORM&&this.startXIosHeartbeat())}startXAndroidHeartbeat(){const t=new Map,e=ot("adbkit"),n=$.default.platform();let s="",i="";"darwin"===n?(s='dumpsys activity | grep "Run"',i="logcat -b crash | grep -C 10 io.dcloud.uniappx"):"win32"===n&&(s='dumpsys activity | findstr "Run"',i="logcat | findstr UncaughtExceptionHandler"),t.set(this.id,setInterval((async()=>{if(!this.isAlive){const o=e.createClient(),r=await o.listDevices();if(!r.length)throw Error("Device not found");const a=r[0].id,c=await o.getProperties(a);return("1"===c["ro.kernel.qemu"]||"goldfish"===c["ro.hardware"])&&"win32"===n&&(i="logcat | grep UncaughtExceptionHandler"),o.shell(a,s).then((function(t){let e,n="";t.on("data",(function(t){n+=t.toString(),e&&clearTimeout(e),e=setTimeout((()=>{n.includes("io.dcloud.uniapp")||console.log("Stop the test process.")}),50)}))})),o.shell(a,i).then((t=>{let e,n="";t.on("data",(t=>{n+=t.toString(),e&&clearTimeout(e),e=setTimeout((()=>{console.log(`crash log: ${n}`)}),50)}))})),clearInterval(t.get(this.id)),t.delete(this.id),void this.dispose()}this.send("ping"),this.isAlive=!1}),5e3))}startXIosHeartbeat(){const t=new Map;t.set(this.id,setInterval((async()=>{if(!this.isAlive)return console.log("Stop the test process."),clearInterval(t.get(this.id)),t.delete(this.id),void this.dispose();this.send("ping"),this.isAlive=!1}),5e3))}static createDevtoolConnection(t,e){return new Promise(((n,s)=>{const i=new R.default(t);i.addEventListener("open",(()=>{n(new at(new Q(i),e,"devtool"))})),i.addEventListener("error",s)}))}static createRuntimeConnection(t,e,n){return new Promise(((s,i)=>{N.default("automator:runtime")(`${j.default("yyyy-mm-dd HH:MM:ss:l")} port=${t}`);const o=new R.default.Server({port:t});x.default((async()=>{if(e.runtimeConnection)return!0}),n,1e3).catch((()=>{o.close(),i("Failed to connect to runtime, please make sure the project is running")})),o.on("connection",(function(t){N.default("automator:runtime")(`${j.default("yyyy-mm-dd HH:MM:ss:l")} connected`);const n=new at(new Q(t),e,"runtime");e.setRuntimeConnection(n),n.startHeartbeat(),s(n)})),e.setRuntimeServer(o)}))}}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册