提交 6bfd7f85 编写于 作者: W wangjinxin613

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

上级 238829ab
......@@ -43,6 +43,7 @@ module.exports = {
reporters: [
'default'
],
setupFiles: ['./jest.global.js'],
globals: {
describes: parseDescribes()
},
......@@ -51,4 +52,4 @@ module.exports = {
rootDir: __dirname,
testMatch: ["<rootDir>/pages/**/*test.[jt]s?(x)"],
testPathIgnorePatterns: ['/node_modules/']
}
}
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.
先完成此消息的编辑!
想要评论请 注册