jest.config.js 1.3 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 38 39 40 41
const {
    readFileSync,
    readdirSync
} = require('fs')
const {
    extname,
    resolve
} = require('path')

const describeRE = /describe\(["|'](.*)["|']/
const testsRE = /test\(["|'](.*)["|']/g

function parse(content) {
    const describes = content.match(describeRE)
    if (!describes) {
        return
    }
    const describe = describes[1]
    const tests = []
    let test
    while (test = testsRE.exec(content)) {
        tests.push(test[1])
    }
    return {
        describe,
        tests
    }
}

function parseDescribes() {
    const dir = resolve(__dirname, 'uni_modules/uts-tests/utssdk')
    const describes = []
    readdirSync(dir).forEach(file => {
        if (extname(file) === '.uts') {
            describes.push(parse(readFileSync(resolve(dir, file), 'utf8')))
        }
    })
    return describes
};

module.exports = {
雪洛's avatar
雪洛 已提交
42
    testTimeout: 20000,
Y
yurj26 已提交
43 44 45
    reporters: [
        'default'
    ],
46
    setupFiles: ['./jest.global.js'],
Y
yurj26 已提交
47 48 49 50 51 52 53 54
    globals: {
        describes: parseDescribes()
    },
    watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
    moduleFileExtensions: ['js', 'json'],
    rootDir: __dirname,
    testMatch: ["<rootDir>/pages/**/*test.[jt]s?(x)"],
    testPathIgnorePatterns: ['/node_modules/']
55
}