Skip to content

Commit

Permalink
test(hooks): Test the correct hook order execution
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon committed Jul 13, 2018
1 parent 2123d2a commit 34d905d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions spec/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,53 @@ describe('HtmlWebpackPlugin', () => {
});
});

it('fires the events in the correct order', done => {
const hookCallOrder = [
'beforeHtmlGeneration',
'beforeHtmlProcessing',
'alterAssetTags',
'afterHtmlProcessing',
'afterEmit'
];
let eventsFired = [];
let hookLength = 0;
const examplePlugin = {
apply: function (compiler) {
compiler.plugin('compilation', compilation => {
const hooks = HtmlWebpackPlugin.getHooks(compilation);
hookLength = hooks.length;
// Hook into all hooks
Object.keys(hooks).forEach((hookName) => {
hooks[hookName].tapAsync('HtmlWebpackPluginTest', (object, callback) => {
eventsFired.push(hookName);
callback();
});
});
});
}
};
const shouldExpectWarnings = webpackMajorVersion < 4;
testHtmlPlugin({
mode: 'production',
entry: {
app: path.join(__dirname, 'fixtures/index.js')
},
output: {
path: OUTPUT_DIR,
filename: '[name]_bundle.js'
},
plugins: [
new HtmlWebpackPlugin(),
examplePlugin
]
}, [], null, () => {
expect(hookLength).not.toBe(0);
expect(eventsFired).toEqual(hookCallOrder);
done();
}, false,
shouldExpectWarnings);
});

it('works with commons chunk plugin', done => {
testHtmlPlugin({
mode: 'production',
Expand Down

0 comments on commit 34d905d

Please sign in to comment.