欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解使用mocha對webpack打包的項目進行"冒煙測試"的大致流程

 更新時間:2020年04月27日 09:33:30   作者:Felix  
這篇文章主要介紹了詳解使用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ù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論