diff --git a/src/loader.js b/src/loader.js index 9cbd2563..ff9e7f84 100644 --- a/src/loader.js +++ b/src/loader.js @@ -125,7 +125,7 @@ export function pitch(request) { // Remove all chunk assets compilation.chunks.forEach((chunk) => { chunk.files.forEach((file) => { - delete compilation.assets[file]; // eslint-disable-line no-param-reassign + compilation.deleteAsset(file); }); }); }); diff --git a/test/TestCache.test.js b/test/TestCache.test.js index 32d9785b..9dbc9383 100644 --- a/test/TestCache.test.js +++ b/test/TestCache.test.js @@ -15,7 +15,135 @@ const fileSystemCacheDirectory = path.resolve( del.sync(fileSystemCacheDirectory); describe('TestCache', () => { - it('should work', async () => { + it('should work without cache', async () => { + if (webpack.version[0] !== '4') { + const casesDirectory = path.resolve(__dirname, 'cases'); + const directoryForCase = path.resolve(casesDirectory, 'simple'); + // eslint-disable-next-line import/no-dynamic-require, global-require + const webpackConfig = require(path.resolve( + directoryForCase, + 'webpack.config.js' + )); + + const compiler1 = webpack({ + ...webpackConfig, + mode: 'development', + context: directoryForCase, + cache: false, + }); + + await new Promise((resolve, reject) => { + compiler1.run((error, stats) => { + if (error) { + reject(error); + + return; + } + + expect(stats.compilation.warnings).toHaveLength(0); + expect(stats.compilation.errors).toHaveLength(0); + + compiler1.close(() => { + resolve(); + }); + }); + }); + + const compiler2 = webpack({ + ...webpackConfig, + mode: 'development', + context: directoryForCase, + cache: false, + }); + + await new Promise((resolve, reject) => { + compiler2.run((error, stats) => { + if (error) { + reject(error); + + return; + } + + expect(stats.compilation.warnings).toHaveLength(0); + expect(stats.compilation.errors).toHaveLength(0); + + compiler2.close(() => { + resolve(); + }); + }); + }); + } else { + expect(true).toBe(true); + } + }); + + it('should work with the "memory" cache', async () => { + if (webpack.version[0] !== '4') { + const casesDirectory = path.resolve(__dirname, 'cases'); + const directoryForCase = path.resolve(casesDirectory, 'simple'); + // eslint-disable-next-line import/no-dynamic-require, global-require + const webpackConfig = require(path.resolve( + directoryForCase, + 'webpack.config.js' + )); + + const compiler1 = webpack({ + ...webpackConfig, + mode: 'development', + context: directoryForCase, + cache: { + type: 'memory', + }, + }); + + await new Promise((resolve, reject) => { + compiler1.run((error, stats) => { + if (error) { + reject(error); + + return; + } + + expect(stats.compilation.warnings).toHaveLength(0); + expect(stats.compilation.errors).toHaveLength(0); + + compiler1.close(() => { + resolve(); + }); + }); + }); + + const compiler2 = webpack({ + ...webpackConfig, + mode: 'development', + context: directoryForCase, + cache: { + type: 'memory', + }, + }); + + await new Promise((resolve, reject) => { + compiler2.run((error, stats) => { + if (error) { + reject(error); + + return; + } + + expect(stats.compilation.warnings).toHaveLength(0); + expect(stats.compilation.errors).toHaveLength(0); + + compiler2.close(() => { + resolve(); + }); + }); + }); + } else { + expect(true).toBe(true); + } + }); + + it('should work with the "filesystem" cache', async () => { if (webpack.version[0] !== '4') { const casesDirectory = path.resolve(__dirname, 'cases'); const directoryForCase = path.resolve(casesDirectory, 'simple');