Skip to content

Commit

Permalink
test: cache (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Sep 18, 2020
1 parent fd03615 commit 58a574b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
50 changes: 49 additions & 1 deletion test/CopyPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CopyPlugin from '../src';

import { run, runEmit, runChange } from './helpers/run';

import { readAssets } from './helpers';
import { readAssets, getCompiler, compile } from './helpers';

const FIXTURES_DIR = path.join(__dirname, 'fixtures');

Expand Down Expand Up @@ -633,6 +633,54 @@ describe('CopyPlugin', () => {
.then(done)
.catch(done);
});

it('should work and do not emit unchanged assets', async () => {
const compiler = getCompiler();

new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, './fixtures/directory'),
},
],
}).apply(compiler);

const { stats } = await compile(compiler);

if (webpack.version[0] === '4') {
expect(
Object.keys(stats.compilation.assets).filter(
(assetName) => stats.compilation.assets[assetName].emitted
).length
).toBe(5);
} else {
expect(stats.compilation.emittedAssets.size).toBe(5);
}

expect(readAssets(compiler, stats)).toMatchSnapshot('assets');
expect(stats.compilation.errors).toMatchSnapshot('errors');
expect(stats.compilation.warnings).toMatchSnapshot('warnings');

await new Promise(async (resolve) => {
const { stats: newStats } = await compile(compiler);

if (webpack.version[0] === '4') {
expect(
Object.keys(newStats.compilation.assets).filter(
(assetName) => newStats.compilation.assets[assetName].emitted
).length
).toBe(4);
} else {
expect(newStats.compilation.emittedAssets.size).toBe(4);
}

expect(readAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(newStats.compilation.errors).toMatchSnapshot('errors');
expect(newStats.compilation.warnings).toMatchSnapshot('warnings');

resolve();
});
});
});

describe('logging', () => {
Expand Down
28 changes: 28 additions & 0 deletions test/__snapshots__/CopyPlugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,31 @@ Object {
],
}
`;

exports[`CopyPlugin watch mode should work and do not emit unchanged assets: assets 1`] = `
Object {
".dottedfile": "dottedfile contents
",
"directoryfile.txt": "new",
"nested/deep-nested/deepnested.txt": "",
"nested/nestedfile.txt": "",
}
`;

exports[`CopyPlugin watch mode should work and do not emit unchanged assets: assets 2`] = `
Object {
".dottedfile": "dottedfile contents
",
"directoryfile.txt": "new",
"nested/deep-nested/deepnested.txt": "",
"nested/nestedfile.txt": "",
}
`;

exports[`CopyPlugin watch mode should work and do not emit unchanged assets: errors 1`] = `Array []`;

exports[`CopyPlugin watch mode should work and do not emit unchanged assets: errors 2`] = `Array []`;

exports[`CopyPlugin watch mode should work and do not emit unchanged assets: warnings 1`] = `Array []`;

exports[`CopyPlugin watch mode should work and do not emit unchanged assets: warnings 2`] = `Array []`;

0 comments on commit 58a574b

Please sign in to comment.