testing.ts 2.6 KB
Newer Older
aaronchen2k2k's avatar
aaronchen2k2k 已提交
1
import moment from "moment";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
2 3 4 5 6 7 8
import {AutoTestTools, TestTools, BuildTools} from "@/utils/const";

function addItems(item, list, map) {
    const lowerCase = item.toLowerCase()
    list.push(lowerCase)
    map[lowerCase] = item
}
9 10 11 12

export function getUnitTestFrameworks(): any {
    const list = new Array<string>()
    const map = {}
13
    TestTools.forEach((item) => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
14
        addItems(item, list, map)
15 16 17 18 19 20 21 22
    })

    return {list: list, map: map}
}
export function getUnitTestTools(): any {
    const data = {}
    const map = {}

23
    Object.keys(BuildTools).forEach((key) => {
24 25
        if (! (key in data)) data[key] = []

26
        BuildTools[key].forEach(item => {
27 28 29 30 31 32 33 34 35 36 37 38 39
            const lowerCase = item.toLowerCase()
            data[key].push(lowerCase)
            map[lowerCase] = item
        })
    })

    return {data: data, map: map}
}

export function getAutoTestTools(): any {
    const list = new Array<string>()
    const map = {}
    AutoTestTools.forEach((item) => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
40
        addItems(item, list, map)
41 42 43 44
    })

    return {list: list, map: map}
}
aaronchen2k2k's avatar
aaronchen2k2k 已提交
45

aaronchen2k2k's avatar
aaronchen2k2k 已提交
46
const execByMap = {
Z
zhaoke 已提交
47 48 49 50
    case: 'by_case',
    module: 'by_module',
    suite: 'by_suite',
    task: 'by_task',
aaronchen2k2k's avatar
aaronchen2k2k 已提交
51
}
aaronchen2k2k's avatar
aaronchen2k2k 已提交
52
export const testToolMap = {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
53 54 55 56 57 58 59 60
    junit: 'JUnit',
    testng: 'TestNG',
    phpunit: 'PHPUnit',
    pytest: 'PyTest',
    jest: 'Jest',
    cppunit: 'CppUnit',
    gtest: 'GTest',
    qtest: 'QTest',
雨爱无痕 已提交
61
    gotest: 'GoTest',
aaronchen2k2k's avatar
aaronchen2k2k 已提交
62
    allure: 'Allure',
aaronchen2k2k's avatar
aaronchen2k2k 已提交
63 64 65

    robotframework: 'RobotFramework',
    cypress: 'Cypress',
aaronchen2k2k's avatar
aaronchen2k2k 已提交
66 67 68 69

    playwright: 'Playwright',
    puppeteer: 'Puppeteer',

aaronchen2k2k's avatar
aaronchen2k2k 已提交
70 71 72
    autoit: 'AutoIt',
    selenium: 'Selenium',
    appium: 'Appium',
aaronchen2k2k's avatar
aaronchen2k2k 已提交
73 74
}
export function execByDef(record) {
Z
zhaoke 已提交
75 76
    if (record.execBy) return execByMap[record.execBy] ? execByMap[record.execBy]: '';
    else return testToolMap[record.testTool] ? testToolMap[record.testTool]: '';
aaronchen2k2k's avatar
aaronchen2k2k 已提交
77
}
aaronchen2k2k's avatar
aaronchen2k2k 已提交
78 79 80 81 82 83 84 85 86 87 88
export function momentTimeDef(tm) {
    return moment.unix(tm).format("YYYY-MM-DD HH:mm:ss")
}
export function percentDef(numb, total) {
    if (total == 0) return '0%'
    return Number(numb / total * 100).toFixed(2) + '%'
}

const osMap = {
    windows: 'Windows',
    linux: 'Linux',
H
Hao Sun 已提交
89
    mac: 'mac',
aaronchen2k2k's avatar
aaronchen2k2k 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102
}
export function testEnvDef(code) {
    return osMap[code]
}
const testTypeMap = {
    func: 'Functional Testing',
    unit: 'Unit Testing',
    auto: 'Automated Testing',
}
export function testTypeDef(code) {
    return testTypeMap[code]
}
export function resultStatusDef(code) {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
103 104 105 106 107
    if (code === true || code === 'pass') {
        return 'pass'
    } else {
        return 'fail'
    }
aaronchen2k2k's avatar
aaronchen2k2k 已提交
108
}
109 110 111 112 113 114

export function expectDesc(str) {
    return str === '' ? 'pass' : str
}
export function actualDesc(str) {
    return str === 'N/A' ? '' : str
H
Hao Sun 已提交
115
}