| 4 | import logger from "../../config/logger"; |
| 5 | |
| 6 | class WdaGoIOS { |
| 7 | controlPort: number; |
| 8 | streamPort: number; |
| 9 | udid: string; |
| 10 | version: number; |
| 11 | private runWdaProc?: SubProcess; |
| 12 | private tunnelProc?: SubProcess; |
| 13 | |
| 14 | constructor(udid: string, version: number, controlPort: number, streamPort: number) { |
| 15 | this.udid = udid; |
| 16 | this.version = version; |
| 17 | this.controlPort = controlPort; |
| 18 | this.streamPort = streamPort; |
| 19 | } |
| 20 | |
| 21 | async start(): Promise<void> { |
| 22 | await this.startTunnel(); |
| 23 | const args = getRunTestCommandArgs(this.udid, this.controlPort, this.streamPort); |
| 24 | this.runWdaProc = new SubProcess(APP_ENV.GO_IOS, args); |
| 25 | this.runWdaProc.on("output", (stdout, stderr) => { |
| 26 | logger.error(`stderr: ${stderr}`); |
| 27 | }); |
| 28 | this.runWdaProc.on("die", this.onProcessDie); |
| 29 | await this.runWdaProc.start(0); |
| 30 | return await new Promise((f) => setTimeout(f, 5000)); |
| 31 | } |
| 32 | |
| 33 | async startTunnel(): Promise<void> { |
| 34 | this.tunnelProc = new SubProcess(APP_ENV.GO_IOS, ["tunnel", "start", "--userspace", "--udid", this.udid]); |
| 35 | this.tunnelProc.on("output", (stdout, stderr) => { |
| 36 | logger.error(`stderr: ${stderr}`); |
| 37 | }); |
| 38 | this.tunnelProc.on("die", this.onProcessDie); |
| 39 | await this.tunnelProc.start(0); |
| 40 | await new Promise((f) => setTimeout(f, 5000)); |
| 41 | } |
| 42 | |
| 43 | async stop(): Promise<void> { |
| 44 | if (this.tunnelProc) { |
| 45 | await this.tunnelProc.stop("SIGINT"); |
| 46 | logger.info("tunnel for device stopped successfully."); |
| 47 | } |
| 48 | |
| 49 | if (this.runWdaProc) { |
| 50 | await this.runWdaProc.stop("SIGINT"); |
| 51 | logger.info("runwda process stopped"); |
| 52 | this.removeListeners(); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | removeListeners(): void { |
| 57 | if (this.tunnelProc) { |
| 58 | this.tunnelProc.removeAllListeners(); |
| 59 | } |
| 60 | |
| 61 | if (this.runWdaProc) { |
| 62 | this.runWdaProc.removeAllListeners(); |
| 63 | } |
nothing calls this directly
no outgoing calls
no test coverage detected