詳解使用mocha對webpack打包的項目進行"冒煙測試"的大致流程
第一步: 打包開始之前刪除'./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
}))
// 第三步: 將測試規(guī)則添加到打包后
mocha.addFile(resolve(\_\_dirname, './html-test.js'))
mocha.addFile(resolve(\_\_dirname, './css-js-test.js'))
mocha.run()
})
})
第二步: 新建測試規(guī)則
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是字符串, 不是正則, 它有自己的匹配規(guī)則, 例如:
'./dist/+(index|search).html'
換成正則的寫法為:
/\.\/dist\/(index|search)\.html/
不能茍同, 一定要區(qū)分
具體請移步這里: https://github.com/isaacs/node-glob
到此這篇關于詳解使用mocha對webpack打包的項目進行"冒煙測試"的大致流程的文章就介紹到這了,更多相關mocha webpack 冒煙測試內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
JS實現(xiàn)求數(shù)組起始項到終止項之和的方法【基于數(shù)組擴展函數(shù)】
這篇文章主要介紹了JS實現(xiàn)求數(shù)組起始項到終止項之和的方法,基于數(shù)組擴展函數(shù)實現(xiàn)該功能,涉及javascript針對數(shù)組的簡單判斷、遍歷等相關操作技巧,需要的朋友可以參考下2017-06-06
JavaScript html5利用FileReader實現(xiàn)上傳功能
這篇文章主要為大家詳細介紹了JavaScript html5利用FileReader實現(xiàn)上傳功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03

