Skip to content

Commit

Permalink
test: fix (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Sep 17, 2020
1 parent 978793e commit 0b537c6
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 182 deletions.
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
Loading

0 comments on commit 0b537c6

Please sign in to comment.