The general process of “smoke test” for webpack packaged projects with mocha

Time:2020-10-18

Step 1: delete the ‘. / dist’ directory before packaging starts
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

    }))

//Step 3: add the test rules to the package
mocha.addFile(resolve(\_\_dirname, './html-test.js'))
mocha.addFile(resolve(\_\_dirname, './css-js-test.js'))
mocha.run()
})

})

Step 2: create a new test rule

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: About glob.sync (3) special description of the method:

  • pattern {String}: match pattern.
  • options {Object}
  • return: {Array<String>}: matches the file name in the pattern.

This pattern is a string,It’s not regularIt has its own matching rules, such as:
'./dist/+(index|search).html'
Instead, it is written as follows:
/\.\/dist\/(index|search)\.html/
If you can’t agree with each other, you must distinguish them
For details, please move here: https://github.com/isaacs/nod…

Recommended Today

Construction of Vue development environment and project creation under mac

start First of all, let’s take a look at the overall development environment of Vue. Homebrew: package manager under MAC system, similar to apt get under Linux, windows control panel – install and remove program Node.jsJavaScript runtime, which is similar to simultaneous interpretation in international conferences, can’t run various programming languages directly between different systems […]