basicTest.test.js 2.0 KB
Newer Older
Y
yurj26 已提交
1 2 3 4 5
const ERR_RE = /expected:<(.*)> but was:<(.*)>/

let result;

beforeAll(async () => {
6 7 8 9 10
  await program.reLaunch('/pages/index/basicTest')
  page = await program.currentPage()
  await page.waitFor(3000);
  const data = await page.data();
  result = data['result']
Y
yurj26 已提交
11 12 13
})

function getApiFailed(describe, api) {
14 15 16 17
  const failed = result[describe]?.failed?.find(item => {
    return item.split(':')[0] === api
  })
  return failed
Y
yurj26 已提交
18 19 20
}

describes.forEach(d => {
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  d?.describe && describe(d.describe, () => {
    d?.tests && d.tests.forEach(api => {
      it(api, () => {
        const failed = getApiFailed(d.describe, api)
        if (failed) {
          const parts = failed.split('\n')
          const matches = parts[1].match(ERR_RE)
          if (matches?.length) {
            expect(matches[2]).toEqual(matches[1])
          } else {
            expect(parts[1]).toEqual('')
          }
        }
      })
    })
  })
Y
yurj26 已提交
37
})
38

39
if (process.env.UNI_PROJECT_TYPE === '2.0' && process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
W
wangjinxin613 已提交
40 41 42 43
  describe('testTypeFromAppJs',  () => {
    it("jest_testTypeFromAppJs", async () => {
      const res = await page.callMethod('jest_testTypeFromAppJs')
      expect(res).toEqual(true)
44 45 46 47 48 49 50 51 52
    })     
  })
}

if (process.env.UNI_PROJECT_TYPE === '2.0' && (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || process.env.uniTestPlatformInfo.startsWith('android'))) {
  describe('testCallbackKeepAlive',  () => {
    it("jest_testCallbackKeepAlive", async () => {
      const res = await page.callMethod('jest_testCallbackKeepAlive')
      expect(res).toEqual(true)
W
wangjinxin613 已提交
53
    })
54 55 56 57 58
  })
}

if (process.env.UNI_PROJECT_TYPE === '1.0' && (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || process.env.uniTestPlatformInfo.startsWith('android'))) {
  describe('testCallbackKeepAlive',  () => {
lizhongyi_'s avatar
lizhongyi_ 已提交
59 60 61 62
    it("jest_testCallbackKeepAlive", async () => {
      const res = await page.callMethod('jest_testCallbackKeepAlive')
      expect(res).toEqual(true)
    })
63 64
  })
}