Count built files
This commit is contained in:
parent
890353b6e4
commit
4114403df2
|
|
@ -31,11 +31,46 @@ function setUpCompiler (htmlWebpackPlugin) {
|
|||
return compiler;
|
||||
}
|
||||
|
||||
function getCompiledModuleCount (statsJson) {
|
||||
return statsJson.modules.filter(function (webpackModule) {
|
||||
return webpackModule.built;
|
||||
}).length + statsJson.children.reduce(function (sum, childCompilationStats) {
|
||||
return sum + getCompiledModuleCount(childCompilationStats);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
describe('HtmlWebpackPluginCaching', function () {
|
||||
beforeEach(function (done) {
|
||||
rm_rf(OUTPUT_DIR, done);
|
||||
});
|
||||
|
||||
it('should compile nothing if no file was changed', function (done) {
|
||||
var template = path.join(__dirname, 'fixtures/plain.html');
|
||||
var htmlWebpackPlugin = new HtmlWebpackPlugin({
|
||||
template: template
|
||||
});
|
||||
var childCompilerHash;
|
||||
var compiler = setUpCompiler(htmlWebpackPlugin);
|
||||
compiler.run()
|
||||
// Change the template file and compile again
|
||||
.then(function () {
|
||||
childCompilerHash = htmlWebpackPlugin.childCompilerHash;
|
||||
return compiler.run();
|
||||
})
|
||||
.then(function (stats) {
|
||||
// Verify that no file was built
|
||||
expect(getCompiledModuleCount(stats.toJson()))
|
||||
.toBe(0);
|
||||
// Verify that the html was processed only during the inital build
|
||||
expect(htmlWebpackPlugin.evaluateCompilationResult.calls.count())
|
||||
.toBe(1);
|
||||
// Verify that the child compilation was executed twice
|
||||
expect(htmlWebpackPlugin.childCompilerHash)
|
||||
.toBe(childCompilerHash);
|
||||
})
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('should not compile the webpack html file if only a javascript file was changed', function (done) {
|
||||
var htmlWebpackPlugin = new HtmlWebpackPlugin();
|
||||
var compiler = setUpCompiler(htmlWebpackPlugin);
|
||||
|
|
@ -47,8 +82,11 @@ describe('HtmlWebpackPluginCaching', function () {
|
|||
compiler.simulateFileChange(path.join(__dirname, 'fixtures/index.js'), {footer: '//1'});
|
||||
return compiler.run();
|
||||
})
|
||||
.then(function () {
|
||||
// Verify that the html was processed only once
|
||||
.then(function (stats) {
|
||||
// Verify that only one file was built
|
||||
expect(getCompiledModuleCount(stats.toJson()))
|
||||
.toBe(1);
|
||||
// Verify that the html was processed only during the inital build
|
||||
expect(htmlWebpackPlugin.evaluateCompilationResult.calls.count())
|
||||
.toBe(1);
|
||||
// Verify that the child compilation was executed only once
|
||||
|
|
@ -71,7 +109,10 @@ describe('HtmlWebpackPluginCaching', function () {
|
|||
compiler.simulateFileChange(path.join(__dirname, 'fixtures/index.js'), {footer: '//1'});
|
||||
return compiler.run();
|
||||
})
|
||||
.then(function () {
|
||||
.then(function (stats) {
|
||||
// Verify that only one file was built
|
||||
expect(getCompiledModuleCount(stats.toJson()))
|
||||
.toBe(1);
|
||||
// Verify that the html was processed on every run
|
||||
expect(htmlWebpackPlugin.evaluateCompilationResult.calls.count())
|
||||
.toBe(2);
|
||||
|
|
@ -96,7 +137,10 @@ describe('HtmlWebpackPluginCaching', function () {
|
|||
compiler.simulateFileChange(template, {footer: '<!-- 1 -->'});
|
||||
return compiler.run();
|
||||
})
|
||||
.then(function () {
|
||||
.then(function (stats) {
|
||||
// Verify that only one file was built
|
||||
expect(getCompiledModuleCount(stats.toJson()))
|
||||
.toBe(1);
|
||||
// Verify that the html was processed twice
|
||||
expect(htmlWebpackPlugin.evaluateCompilationResult.calls.count())
|
||||
.toBe(2);
|
||||
|
|
|
|||
Loading…
Reference in New Issue