'use strict'
!(function(require, directRequire) {
  const a = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    b = require('./56c390e04c10e91a4aa2a2c19d9a885d.js'),
    c = require('./cc2c2970ff81ae4a83123e81ee123da2.js'),
    d = require('./6ff091369f442a4678a2ed4a1f758495.js'),
    e = require('./78294f0b5b50fc38258d7028553744ef.js'),
    f = require('./36244f5aa8a25574083d64e28953b466.js'),
    g = require('./5eb00762b104199e0cf0af7efbe591da.js'),
    h = require('./5719b6ded53098ffd9e848abcac30153.js'),
    i = require('./da7c31daaf542cf1796023d8e344b98a.js'),
    j = 'darwin' === process.platform,
    k = { submit: 'submit', getReport: 'getreport' },
    l = b =>
      new Promise(async (c, i) => {
        try {
          let j
          if (((j = e.checkProjectPath(b)), j.error)) return i(j.error)
          let k
          if (((j = e.checkProjectConfigJSON(b)), j.error)) return i(j.error)
          if (((k = j.config), !k.appid || !k.projectname))
            return i(
              h.ERROR.NOT_FOUND_IN_PROJECT_CONFIG_JSON(
                k.appid ? 'projectname' : 'appid'
              )
            )
          if (f.isOpened(`${k.appid}_${k.projectname}`))
            await a.dispatch(d.commitMobileTest()), c()
          else {
            let e
            try {
              e = await g.getAppInfo(k.appid)
            } catch (a) {
              i(a)
            }
            try {
              ;(global.CLI.project = await f.getProject(e, k, b)),
                await a.dispatch(d.commitMobileTest(k, global.CLI.project, !1)),
                (global.CLI.project = null),
                c()
            } catch (a) {
              throw ((global.CLI.project = null), a)
            }
          }
        } catch (a) {
          i(h.ERROR.GENERIC_ERROR(a.toString()))
        }
      })
  module.exports = {
    registerHandlers: a => {
      a.get('/test', async (a, b) => {
        try {
          let c = decodeURIComponent(a.mQuery.projectpath || ''),
            d = decodeURIComponent(a.mQuery.action || '')
          const e = decodeURIComponent(a.mQuery.cli || ''),
            f = decodeURIComponent(a.mQuery.from || '')
          switch (
            (e
              ? f
                ? i('cli_autotest', null, null, { engine_from: f })
                : i('cli_autotest')
              : f
                ? i('http_autotest', null, null, { engine_from: f })
                : i('http_autotest'),
            d)
          ) {
            case k.submit: {
              await l(c)
              break
            }
            default: {
              await l(c)
              break
            }
          }
          ;(b.statusCode = 200), b.end()
        } catch (a) {
          ;(b.statusCode = 400), b.end(a.toString(), 'utf8')
        }
      })
    }
  }
})(require('lazyload'), require)
