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…