提交 8e254a8c 编写于 作者: W wangjinxin613

fix: 修复 jest 高版本全局变量找不到的问题

上级 b79125fe
...@@ -43,6 +43,7 @@ module.exports = { ...@@ -43,6 +43,7 @@ module.exports = {
reporters: [ reporters: [
'default' 'default'
], ],
setupFiles: ['./jest.global.js'],
globals: { globals: {
describes: parseDescribes() describes: parseDescribes()
}, },
......
const {
readFileSync,
readdirSync
} = require('fs')
const {
extname,
resolve
} = require('path')
module.exports = async function (globalConfig, projectConfig) {
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
};
global.describes = parseDescribes();
};
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册