Skip to content

Commit

Permalink
test: cache (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Sep 8, 2020
1 parent d09693e commit 3a61586
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/loader.js
Expand Up @@ -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);
});
});
});
Expand Down
130 changes: 129 additions & 1 deletion test/TestCache.test.js
Expand Up @@ -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');
Expand Down

0 comments on commit 3a61586

Please sign in to comment.