|
| 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 WebpackConfig = require('../../lib/WebpackConfig'); |
| 14 | +const RuntimeConfig = require('../../lib/config/RuntimeConfig'); |
| 15 | +const handlebarsLoader = require('../../lib/loaders/handlebars'); |
| 16 | + |
| 17 | +function createConfig() { |
| 18 | + const runtimeConfig = new RuntimeConfig(); |
| 19 | + runtimeConfig.context = __dirname; |
| 20 | + runtimeConfig.babelRcFileExists = false; |
| 21 | + |
| 22 | + return new WebpackConfig(runtimeConfig); |
| 23 | +} |
| 24 | + |
| 25 | +describe('loaders/handlebars', () => { |
| 26 | + it('getLoaders() basic usage', () => { |
| 27 | + const config = createConfig(); |
| 28 | + config.enableHandlebarsLoader(); |
| 29 | + |
| 30 | + const actualLoaders = handlebarsLoader.getLoaders(config); |
| 31 | + expect(actualLoaders).to.have.lengthOf(1); |
| 32 | + expect(actualLoaders[0].options).to.be.empty; |
| 33 | + }); |
| 34 | + |
| 35 | + it('getLoaders() with options callback', () => { |
| 36 | + const config = createConfig(); |
| 37 | + config.enableHandlebarsLoader((options) => { |
| 38 | + options.debug = true; |
| 39 | + }); |
| 40 | + |
| 41 | + const actualLoaders = handlebarsLoader.getLoaders(config); |
| 42 | + expect(actualLoaders).to.have.lengthOf(1); |
| 43 | + expect(actualLoaders[0].options.debug).to.be.true; |
| 44 | + }); |
| 45 | + |
| 46 | + it('getLoaders() with options callback that returns an object', () => { |
| 47 | + const config = createConfig(); |
| 48 | + config.enableHandlebarsLoader((options) => { |
| 49 | + options.debug = true; |
| 50 | + |
| 51 | + // This should override the original config |
| 52 | + return { foo: true }; |
| 53 | + }); |
| 54 | + |
| 55 | + const actualLoaders = handlebarsLoader.getLoaders(config); |
| 56 | + expect(actualLoaders).to.have.lengthOf(1); |
| 57 | + expect(actualLoaders[0].options).to.deep.equal({ foo: true }); |
| 58 | + }); |
| 59 | +}); |
0 commit comments