2020-10-27 14:31:37 +08:00

39 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const fs = require('fs-extra');
const execa = require('execa');
const path = require('path');
const log = require('../helpers/log');
module.exports = function (config, rawArgv) {
const testDir = path.join(config.folders.PROJECT_DIR, 'test');
if (fs.pathExistsSync(testDir)) {
const bin = require.resolve('mochapack/bin/mochapack');
const argv = [
// ...nodeArgs,
bin,
'--recursive',
'--require',
require.resolve('../helpers/setup.js'),
'--webpack-config',
require.resolve('../configs/webpack.test.config.js'),
...rawArgv,
`${testDir}/**/*.spec.js`
];
const child = execa('node', argv, {
cwd: config.folders.CLI_DIR,
encoding: 'utf8',
stdio: 'inherit'
});
child.on('error', (e) => {
log.error('执行test失败');
log.error(JSON.stringify(e));
});
child.on('exit', (code) => {
if (code !== 0) {
log.message(`mochapack进程退出code ${code}.`);
}
});
} else {
log.warn('测试目录不存在请在项目根目录创建目录test');
}
};