From bdcf8c414c9f903caed0d7c5acb42228044b6f21 Mon Sep 17 00:00:00 2001 From: kisenka Date: Thu, 7 Jul 2016 11:46:24 +0300 Subject: [PATCH] Add plugin test to handle FILTER_SOURCES hook --- test/plugin.test.js | 46 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/test/plugin.test.js b/test/plugin.test.js index e2fd55e..e9b74f9 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -281,7 +281,7 @@ describe('Plugin', function () { }; var compiler = inMemoryCompiler({ - entry: './qwe', + entry: './entry', module: { loaders: [ { @@ -293,12 +293,54 @@ describe('Plugin', function () { plugins: [new Plugin, plugin] }); - compiler.inputFileSystem.writeFileSync('/qwe.js', 'qwe', 'utf-8'); + compiler.inputFileSystem.writeFileSync('/entry.js', 'qwe', 'utf-8'); compiler.run().then(function() { spiedPluginBody.should.have.callCount(1); }); }); + it('should filter sources via FILTER_SOURCES hook', function() { + var plugin = new Plugin(); + var filteredSources; + + var filterPlugin = { + apply: function(compiler) { + compiler.plugin('compilation', function(compilation) { + compilation.plugin(HOOKS.FILTER_SOURCES, function(sources, done) { + + var filtered = sources.filter(function(source) { + var isEntry1 = source.content.indexOf('entry1') != -1; + return isEntry1; + }); + + filteredSources = filtered; + done(null, filtered); + }); + }); + } + }; + + var compiler = inMemoryCompiler({ + entry: ['./entry1', './entry2'], + module: { + loaders: [ + { + test: /\.js$/, + loader: Plugin.extract() + } + ] + }, + plugins: [plugin, filterPlugin] + }); + + compiler.inputFileSystem.writeFileSync('/entry1.js', '/*entry1 content*/', 'utf-8'); + compiler.inputFileSystem.writeFileSync('/entry2.js', '/*entry2 content*/', 'utf-8'); + + compiler.run().then(function() { + filteredSources.should.be.an('array').and.to.have.lengthOf(1); + }); + }); + }); }); \ No newline at end of file