Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: cache #583

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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