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: fix #318

Merged
merged 1 commit into from
Sep 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 27 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"schema-utils": "^2.7.1",
"serialize-javascript": "^5.0.1",
"source-map": "^0.6.1",
"terser": "^5.3.1",
"terser": "^5.3.2",
"webpack-sources": "^1.4.3"
},
"devDependencies": {
Expand All @@ -70,10 +70,10 @@
"file-loader": "^6.1.0",
"husky": "^4.3.0",
"jest": "^26.4.2",
"lint-staged": "^10.3.0",
"lint-staged": "^10.4.0",
"memfs": "^3.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.1",
"prettier": "^2.1.2",
"standard-version": "^9.0.0",
"uglify-js": "^3.10.4",
"webpack": "^4.44.1",
Expand Down
80 changes: 71 additions & 9 deletions test/TerserPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,68 @@ describe('TerserPlugin', () => {
}
});

it('should work and use memory cache out of box', async () => {
const compiler = getCompiler({
...(getCompiler.isWebpack4() ? { cache: true } : {}),
entry: {
js: path.resolve(__dirname, './fixtures/entry.js'),
mjs: path.resolve(__dirname, './fixtures/entry.mjs'),
importExport: path.resolve(
__dirname,
'./fixtures/import-export/entry.js'
),
AsyncImportExport: path.resolve(
__dirname,
'./fixtures/async-import-export/entry.js'
),
},
cache: true,
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
chunkFilename: '[id].[name].js',
},
});

new TerserPlugin().apply(compiler);

const stats = await compile(compiler);

if (getCompiler.isWebpack4()) {
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(readsAssets(compiler, stats)).toMatchSnapshot('assets');
expect(getWarnings(stats)).toMatchSnapshot('errors');
expect(getErrors(stats)).toMatchSnapshot('warnings');

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

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

expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(getWarnings(newStats)).toMatchSnapshot('errors');
expect(getErrors(newStats)).toMatchSnapshot('warnings');

resolve();
});
});

it('should work and use memory cache when the "cache" option is "true"', async () => {
const compiler = getCompiler({
entry: {
Expand Down Expand Up @@ -961,7 +1023,7 @@ describe('TerserPlugin', () => {
expect(newStats.compilation.emittedAssets.size).toBe(0);
}

expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(getWarnings(newStats)).toMatchSnapshot('errors');
expect(getErrors(newStats)).toMatchSnapshot('warnings');

Expand Down Expand Up @@ -1024,7 +1086,7 @@ describe('TerserPlugin', () => {
expect(newStats.compilation.emittedAssets.size).toBe(1);
}

expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(getWarnings(newStats)).toMatchSnapshot('errors');
expect(getErrors(newStats)).toMatchSnapshot('warnings');

Expand Down Expand Up @@ -1086,7 +1148,7 @@ describe('TerserPlugin', () => {
expect(newStats.compilation.emittedAssets.size).toBe(0);
}

expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(getWarnings(newStats)).toMatchSnapshot('errors');
expect(getErrors(newStats)).toMatchSnapshot('warnings');

Expand Down Expand Up @@ -1150,7 +1212,7 @@ describe('TerserPlugin', () => {
expect(newStats.compilation.emittedAssets.size).toBe(2);
}

expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(getWarnings(newStats)).toMatchSnapshot('errors');
expect(getErrors(newStats)).toMatchSnapshot('warnings');

Expand Down Expand Up @@ -1205,7 +1267,7 @@ describe('TerserPlugin', () => {
expect(newStats.compilation.emittedAssets.size).toBe(0);
}

expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(getWarnings(newStats)).toMatchSnapshot('errors');
expect(getErrors(newStats)).toMatchSnapshot('warnings');

Expand Down Expand Up @@ -1262,7 +1324,7 @@ describe('TerserPlugin', () => {
expect(newStats.compilation.emittedAssets.size).toBe(2);
}

expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(getWarnings(newStats)).toMatchSnapshot('errors');
expect(getErrors(newStats)).toMatchSnapshot('warnings');

Expand Down Expand Up @@ -1321,7 +1383,7 @@ describe('TerserPlugin', () => {
expect(newStats.compilation.emittedAssets.size).toBe(0);
}

expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(getWarnings(newStats)).toMatchSnapshot('errors');
expect(getErrors(newStats)).toMatchSnapshot('warnings');

Expand Down Expand Up @@ -1382,7 +1444,7 @@ describe('TerserPlugin', () => {
expect(newStats.compilation.emittedAssets.size).toBe(2);
}

expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(getWarnings(newStats)).toMatchSnapshot('errors');
expect(getErrors(newStats)).toMatchSnapshot('warnings');

Expand Down Expand Up @@ -1443,7 +1505,7 @@ describe('TerserPlugin', () => {
expect(newStats.compilation.emittedAssets.size).toBe(5);
}

expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
expect(getWarnings(newStats)).toMatchSnapshot('errors');
expect(getErrors(newStats)).toMatchSnapshot('warnings');

Expand Down