Skip to content

Commit

Permalink
#936: Add failing test for copy files persistent cache manifest key bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvandevijver committed May 18, 2021
1 parent 972c882 commit ac91584
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 25 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"description": "Webpack Encore is a simpler way to integrate Webpack into your application",
"main": "index.js",
"scripts": {
"test": "mocha --reporter spec test --recursive",
"test": "run-s test:*",
"test:normal": "mocha --reporter spec test --recursive --ignore test/persistent-cache/*",
"test:persistent-cache-clear": "cross-env CLEAR_PERSISTENT_CACHE=true npm run test:persistent-cache:base",
"test:persistent-cache": "npm run test:persistent-cache:base",
"test:persistent-cache:base": "mocha --reporter spec test/persistent-cache --recursive",
"lint": "eslint lib test index.js .eslintrc.js",
"travis:lint": "npm run lint"
},
Expand Down Expand Up @@ -66,6 +70,7 @@
"chai-fs": "^2.0.0",
"chai-subset": "^1.6.0",
"core-js": "^3.0.0",
"cross-env": "^7.0.3",
"eslint": "^6.7.0 || ^7.0.0",
"eslint-loader": "^4.0.0",
"eslint-plugin-header": "^3.0.0",
Expand All @@ -80,6 +85,7 @@
"less": "^4.0.0",
"less-loader": "^7.0.0 || ^8.0.0",
"mocha": "^8.2.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.1.0",
"postcss-loader": "^4.0.0 || ^5.0.0",
"preact": "^8.2.1 || ^10.0.0",
Expand Down
18 changes: 0 additions & 18 deletions test/functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,23 +753,6 @@ describe('Functional tests using webpack', function() {
});
});

it('Persistent caching does not cause problems', (done) => {
const config = createWebpackConfig('www/build', 'dev');
config.setPublicPath('/build');
config.addEntry('main', './js/code_splitting');
config.enableBuildCache({ config: [__filename] });

testSetup.runWebpack(config, (webpackAssert) => {
// sanity check
webpackAssert.assertManifestPath(
'build/main.js',
'/build/main.js'
);

done();
});
});

describe('addCacheGroup()', () => {
it('addCacheGroup() to extract a vendor into its own chunk', (done) => {
const config = createWebpackConfig('www/build', 'dev');
Expand Down Expand Up @@ -1295,7 +1278,6 @@ module.exports = {
});
});


it('When enabled, react JSX is transformed!', (done) => {
const config = createWebpackConfig('www/build', 'dev');
config.setPublicPath('/build');
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const testFixturesDir = path.join(__dirname, '../', '../', 'fixtures');

let servers = [];

function createTestAppDir(rootDir = tmpDir) {
const testAppDir = path.join(rootDir, Math.random().toString(36).substring(7));
function createTestAppDir(rootDir = null, subDir = null) {
const testAppDir = path.join(rootDir ? rootDir : tmpDir, subDir ? subDir : Math.random().toString(36).substring(7));

// copy the fixtures into this new directory
fs.copySync(testFixturesDir, testAppDir);
Expand Down
100 changes: 100 additions & 0 deletions test/persistent-cache/functional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* This file is part of the Symfony Webpack Encore package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

'use strict';

const chai = require('chai');
chai.use(require('chai-fs'));
chai.use(require('chai-subset'));
const path = require('path');
const testSetup = require('../helpers/setup');

function createWebpackConfig(outputDirName = '', testName, command, argv = {}) {
// We need a static named test dir for the cache to work
let testAppDir = testSetup.createTestAppDir(null, testName + '/test');
const webpackConfig = testSetup.createWebpackConfig(
testAppDir,
outputDirName,
command,
argv,
);

webpackConfig.enableSingleRuntimeChunk();
webpackConfig.enableBuildCache({ config: [__filename] }, (cache) => {
cache.cacheDirectory = path.resolve(testAppDir, '..', '.webpack-cache');
});

return webpackConfig;
}

describe('Functional persistent cache tests using webpack', function() {
// being functional tests, these can take quite long
this.timeout(10000);

before(() => {
// Only clear the temp folder when explicitly requested
if (process.env.CLEAR_PERSISTENT_CACHE) {
testSetup.emptyTmpDir();
}
});

describe('Basic scenarios.', () => {
it('Persistent caching does not cause problems', (done) => {
const config = createWebpackConfig('www/build', 'basic_cache', 'dev');
config.setPublicPath('/build');
config.addEntry('main', './js/code_splitting');

testSetup.runWebpack(config, (webpackAssert) => {
// sanity check
webpackAssert.assertManifestPath(
'build/main.js',
'/build/main.js',
);

done();
});
});
});

describe('copyFiles() allows to copy files and folders', () => {
it('Persistent caching does not cause problems', (done) => {
const config = createWebpackConfig('www/build', 'copy_files_cache', 'production');
config.addEntry('main', './js/no_require');
config.setPublicPath('/build');
config.enableVersioning(true);
config.copyFiles([{
from: './images',
includeSubdirectories: false,
}]);

testSetup.runWebpack(config, (webpackAssert) => {
webpackAssert.assertDirectoryContents([
'entrypoints.json',
'runtime.[hash:8].js',
'main.[hash:8].js',
'manifest.json',
'symfony_logo.[hash:8].png',
'symfony_logo_alt.[hash:8].png',
]);

webpackAssert.assertManifestPath(
'build/symfony_logo.png',
'/build/symfony_logo.91beba37.png',
);

webpackAssert.assertManifestPath(
'build/symfony_logo_alt.png',
'/build/symfony_logo_alt.f880ba14.png',
);

done();
});
});
});
});
Loading

0 comments on commit ac91584

Please sign in to comment.