Add caching tests
This commit is contained in:
parent
75adbcb066
commit
890353b6e4
|
|
@ -45,7 +45,8 @@
|
|||
"style-loader": "^0.13.0",
|
||||
"underscore-template-loader": "^0.7.2",
|
||||
"url-loader": "^0.5.7",
|
||||
"webpack": "^1.12.14"
|
||||
"webpack": "^1.12.14",
|
||||
"webpack-recompilation-simulator": "^1.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"bluebird": "^3.3.4",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
* Integration and unit tests for all features but caching
|
||||
*/
|
||||
|
||||
/* eslint-env jasmine */
|
||||
'use strict';
|
||||
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Integration tests for caching
|
||||
*/
|
||||
|
||||
/* eslint-env jasmine */
|
||||
'use strict';
|
||||
|
||||
// Polyfill promisses for node 0.10.x
|
||||
if (!global.Promise) {
|
||||
require('es6-promise').polyfill();
|
||||
}
|
||||
|
||||
var path = require('path');
|
||||
var webpack = require('webpack');
|
||||
var rm_rf = require('rimraf');
|
||||
var WebpackRecompilationSimulator = require('webpack-recompilation-simulator');
|
||||
var HtmlWebpackPlugin = require('../index.js');
|
||||
|
||||
var OUTPUT_DIR = path.join(__dirname, '../dist');
|
||||
|
||||
function setUpCompiler (htmlWebpackPlugin) {
|
||||
spyOn(htmlWebpackPlugin, 'evaluateCompilationResult').and.callThrough();
|
||||
var compiler = new WebpackRecompilationSimulator(webpack({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
path: OUTPUT_DIR,
|
||||
filename: 'index_bundle.js'
|
||||
},
|
||||
plugins: [htmlWebpackPlugin]
|
||||
}));
|
||||
return compiler;
|
||||
}
|
||||
|
||||
describe('HtmlWebpackPluginCaching', function () {
|
||||
beforeEach(function (done) {
|
||||
rm_rf(OUTPUT_DIR, 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);
|
||||
var childCompilerHash;
|
||||
compiler.run()
|
||||
// Change a js file and compile again
|
||||
.then(function () {
|
||||
childCompilerHash = htmlWebpackPlugin.childCompilerHash;
|
||||
compiler.simulateFileChange(path.join(__dirname, 'fixtures/index.js'), {footer: '//1'});
|
||||
return compiler.run();
|
||||
})
|
||||
.then(function () {
|
||||
// Verify that the html was processed only once
|
||||
expect(htmlWebpackPlugin.evaluateCompilationResult.calls.count())
|
||||
.toBe(1);
|
||||
// Verify that the child compilation was executed only once
|
||||
expect(htmlWebpackPlugin.childCompilerHash)
|
||||
.toBe(childCompilerHash);
|
||||
})
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('should compile the webpack html file even if only a javascript file was changed if caching is disabled', function (done) {
|
||||
var htmlWebpackPlugin = new HtmlWebpackPlugin({
|
||||
cache: false
|
||||
});
|
||||
var childCompilerHash;
|
||||
var compiler = setUpCompiler(htmlWebpackPlugin);
|
||||
compiler.run()
|
||||
// Change a js file and compile again
|
||||
.then(function () {
|
||||
childCompilerHash = htmlWebpackPlugin.childCompilerHash;
|
||||
compiler.simulateFileChange(path.join(__dirname, 'fixtures/index.js'), {footer: '//1'});
|
||||
return compiler.run();
|
||||
})
|
||||
.then(function () {
|
||||
// Verify that the html was processed on every run
|
||||
expect(htmlWebpackPlugin.evaluateCompilationResult.calls.count())
|
||||
.toBe(2);
|
||||
// Verify that the child compilation was executed only once
|
||||
expect(htmlWebpackPlugin.childCompilerHash)
|
||||
.toBe(childCompilerHash);
|
||||
})
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('should compile the webpack html if the template 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;
|
||||
compiler.simulateFileChange(template, {footer: '<!-- 1 -->'});
|
||||
return compiler.run();
|
||||
})
|
||||
.then(function () {
|
||||
// Verify that the html was processed twice
|
||||
expect(htmlWebpackPlugin.evaluateCompilationResult.calls.count())
|
||||
.toBe(2);
|
||||
// Verify that the child compilation was executed twice
|
||||
expect(htmlWebpackPlugin.childCompilerHash)
|
||||
.not.toBe(childCompilerHash);
|
||||
})
|
||||
.then(done);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,4 +1,9 @@
|
|||
/* global describe, it, expect */
|
||||
/*
|
||||
* These integration tests compile all cases from the example folder
|
||||
* and matches them against their dist folder
|
||||
*/
|
||||
|
||||
/* eslint-env jasmine */
|
||||
'use strict';
|
||||
|
||||
// Workaround for css-loader issue
|
||||
|
|
|
|||
Loading…
Reference in New Issue