第一步: 打包开始之前删除’./dist’目录
rimraf('./dist', () => {
constprodConfig = require('../../lib/webpack.prod')
webpack(prodConfig, (err, stats) \=> {
if (err) {
console.log(err)
process.exit(2)
}
console.log(stats.toString({
color:true,
modules:false,
children:false
}))
// 第三步: 将测试规则添加到打包后
mocha.addFile(resolve(\_\_dirname, './html-test.js'))
mocha.addFile(resolve(\_\_dirname, './css-js-test.js'))
mocha.run()
})
})
第二步: 新建测试规则
const glob = require('glob');
describe('Checking generated html files',() \=> {
it('should generate html files', (done) \=> {
constfiles = glob.sync('./dist/+(index|search).html')
if (files.length) {
done()
} else {
thrownewError('no html files generated')
}
});
});
Tip: 关于glob.sync()方法的特别说明:
pattern {String}
options {Object}
return: {Array<String>}
这里重点说说这个pattern, 这个pattern是字符串, 不是正则 , 它有自己的匹配规则, 例如:
'./dist/+(index|search).html'
换成正则的写法为:
/\.\/dist\/(index|search)\.html/
不能苟同, 一定要区分
最后|资源分享
下面这些是我的收集和整理的资料,对于开始学习【软件测试】或是技能进阶的朋友来说,绝对是最全面的教程仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你
关注【程序媛木子】微信公众号测试资源将免费获取。