|
| 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 chai = require('chai'); |
| 13 | +chai.use(require('chai-fs')); |
| 14 | +chai.use(require('chai-subset')); |
| 15 | +const path = require('path'); |
| 16 | +const testSetup = require('../helpers/setup'); |
| 17 | + |
| 18 | +function createWebpackConfig(outputDirName = '', testName, command, argv = {}) { |
| 19 | + // We need a static named test dir for the cache to work |
| 20 | + let testAppDir = testSetup.createTestAppDir(null, testName + '/test'); |
| 21 | + const webpackConfig = testSetup.createWebpackConfig( |
| 22 | + testAppDir, |
| 23 | + outputDirName, |
| 24 | + command, |
| 25 | + argv, |
| 26 | + ); |
| 27 | + |
| 28 | + webpackConfig.enableSingleRuntimeChunk(); |
| 29 | + webpackConfig.enableBuildCache({ config: [__filename] }, (cache) => { |
| 30 | + cache.cacheDirectory = path.resolve(testAppDir, '..', '.webpack-cache'); |
| 31 | + }); |
| 32 | + |
| 33 | + return webpackConfig; |
| 34 | +} |
| 35 | + |
| 36 | +describe('Functional persistent cache tests using webpack', function() { |
| 37 | + // being functional tests, these can take quite long |
| 38 | + this.timeout(10000); |
| 39 | + |
| 40 | + describe('Basic scenarios.', () => { |
| 41 | + it('Persistent caching does not cause problems', (done) => { |
| 42 | + const config = createWebpackConfig('www/build', 'basic_cache', 'dev'); |
| 43 | + config.setPublicPath('/build'); |
| 44 | + config.addEntry('main', './js/code_splitting'); |
| 45 | + |
| 46 | + testSetup.runWebpack(config, (webpackAssert) => { |
| 47 | + // sanity check |
| 48 | + webpackAssert.assertManifestPath( |
| 49 | + 'build/main.js', |
| 50 | + '/build/main.js', |
| 51 | + ); |
| 52 | + |
| 53 | + done(); |
| 54 | + }); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe('copyFiles() allows to copy files and folders', () => { |
| 59 | + it('Persistent caching does not cause problems', (done) => { |
| 60 | + const config = createWebpackConfig('www/build', 'copy_files_cache', 'production'); |
| 61 | + config.addEntry('main', './js/no_require'); |
| 62 | + config.setPublicPath('/build'); |
| 63 | + config.enableVersioning(true); |
| 64 | + config.copyFiles([{ |
| 65 | + from: './images', |
| 66 | + includeSubdirectories: false, |
| 67 | + }]); |
| 68 | + |
| 69 | + testSetup.runWebpack(config, (webpackAssert) => { |
| 70 | + webpackAssert.assertDirectoryContents([ |
| 71 | + 'entrypoints.json', |
| 72 | + 'runtime.[hash:8].js', |
| 73 | + 'main.[hash:8].js', |
| 74 | + 'manifest.json', |
| 75 | + 'symfony_logo.[hash:8].png', |
| 76 | + 'symfony_logo_alt.[hash:8].png', |
| 77 | + ]); |
| 78 | + |
| 79 | + webpackAssert.assertManifestPath( |
| 80 | + 'build/symfony_logo.png', |
| 81 | + '/build/symfony_logo.91beba37.png', |
| 82 | + ); |
| 83 | + |
| 84 | + webpackAssert.assertManifestPath( |
| 85 | + 'build/symfony_logo_alt.png', |
| 86 | + '/build/symfony_logo_alt.f880ba14.png', |
| 87 | + ); |
| 88 | + |
| 89 | + done(); |
| 90 | + }); |
| 91 | + }); |
| 92 | + }); |
| 93 | +}); |
0 commit comments