Step 1: Delete the './dist' directory before packaging begins
rimraf('./dist', () => { constprodConfig = require('../../lib/') webpack(prodConfig, (err, stats) \=> { if (err) { (err) (2) } (({ color:true, modules:false, children:false })) // Step 3: Add the test rules to the package(resolve(\_\_dirname, './')) (resolve(\_\_dirname, './')) () }) })
Step 2: Create new test rules
const glob = require('glob'); describe('Checking generated html files',() \=> { it('should generate html files', (done) \=> { constfiles = ('./dist/+(index|search).html') if () { done() } else { thrownewError('no html files generated') } }); });
Tip: Special explanation about the() method:
- pattern {String}: Match pattern.
- options {Object}
- return: {Array<String>}: The file name in matching mode.
Here we focus on this pattern. This pattern is a string, not a regular, and it has its own matching rules, for example:
'./dist/+(index|search).html'
The way to change to regular is:
/\.\/dist\/(index|search)\.html/
Can't agree, you must distinguish
For details, please move here:/isaacs/node-glob
This is the article about the general process of using mocha to perform "smoking test" on projects packaged by webpack. For more related mocha webpack, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!