|
| 1 | +/* |
| 2 | + * This file is part of the Symfony Webpack Encore package. |
| 3 | + * |
| 4 | + * (c) Fabien Potencier <[email protected]> |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +const expect = require('chai').expect; |
| 13 | +const WebpackNotifier = require('webpack-notifier'); |
| 14 | +const WebpackConfig = require('../../lib/WebpackConfig'); |
| 15 | +const RuntimeConfig = require('../../lib/config/RuntimeConfig'); |
| 16 | +const notifierPluginUtil = require('../../lib/plugins/notifier'); |
| 17 | + |
| 18 | +function createConfig() { |
| 19 | + const runtimeConfig = new RuntimeConfig(); |
| 20 | + runtimeConfig.context = __dirname; |
| 21 | + runtimeConfig.babelRcFileExists = false; |
| 22 | + |
| 23 | + return new WebpackConfig(runtimeConfig); |
| 24 | +} |
| 25 | + |
| 26 | +describe('plugins/notifier', () => { |
| 27 | + it('disabled by default', () => { |
| 28 | + const config = createConfig(); |
| 29 | + const plugins = []; |
| 30 | + |
| 31 | + notifierPluginUtil(plugins, config); |
| 32 | + expect(plugins.length).to.equal(0); |
| 33 | + }); |
| 34 | + |
| 35 | + it('explicitly disabled', () => { |
| 36 | + const config = createConfig(); |
| 37 | + const plugins = []; |
| 38 | + |
| 39 | + config.enableBuildNotifications(false); |
| 40 | + |
| 41 | + notifierPluginUtil(plugins, config); |
| 42 | + expect(plugins.length).to.equal(0); |
| 43 | + }); |
| 44 | + |
| 45 | + it('enabled with default settings', () => { |
| 46 | + const config = createConfig(); |
| 47 | + const plugins = []; |
| 48 | + |
| 49 | + config.enableBuildNotifications(); |
| 50 | + |
| 51 | + notifierPluginUtil(plugins, config); |
| 52 | + expect(plugins.length).to.equal(1); |
| 53 | + expect(plugins[0].plugin).to.be.instanceof(WebpackNotifier); |
| 54 | + expect(plugins[0].plugin.options.title).to.equal('Webpack Encore'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('enabled with options callback', () => { |
| 58 | + const config = createConfig(); |
| 59 | + const plugins = []; |
| 60 | + |
| 61 | + config.enableBuildNotifications(true, (options) => { |
| 62 | + options.title = 'foo'; |
| 63 | + }); |
| 64 | + |
| 65 | + notifierPluginUtil(plugins, config); |
| 66 | + expect(plugins.length).to.equal(1); |
| 67 | + expect(plugins[0].plugin).to.be.instanceof(WebpackNotifier); |
| 68 | + expect(plugins[0].plugin.options.title).to.equal('foo'); |
| 69 | + }); |
| 70 | +}); |
0 commit comments