index.test.js 1.0 KB
Newer Older
Y
yurj26 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
const ERR_RE = /expected:<(.*)> but was:<(.*)>/

let result;

beforeAll(async () => {
    await program.reLaunch('/pages/test/index')
    page = await program.currentPage()
    await page.waitFor(3000);
    const data = await page.data('result');
    result = data
})

function getApiFailed(describe, api) {
    const failed = result[describe]?.failed?.find(item => {
        return item.split(':')[0] === api
    })
    return failed
}

describes.forEach(d => {
    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('')
                    }
                }
            })
        })
   })
})