Skip to content

Commit 0b537c6

Browse files
test: fix (#318)
1 parent 978793e commit 0b537c6

9 files changed

+300
-182
lines changed

package-lock.json

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"schema-utils": "^2.7.1",
4949
"serialize-javascript": "^5.0.1",
5050
"source-map": "^0.6.1",
51-
"terser": "^5.3.1",
51+
"terser": "^5.3.2",
5252
"webpack-sources": "^1.4.3"
5353
},
5454
"devDependencies": {
@@ -70,10 +70,10 @@
7070
"file-loader": "^6.1.0",
7171
"husky": "^4.3.0",
7272
"jest": "^26.4.2",
73-
"lint-staged": "^10.3.0",
73+
"lint-staged": "^10.4.0",
7474
"memfs": "^3.2.0",
7575
"npm-run-all": "^4.1.5",
76-
"prettier": "^2.1.1",
76+
"prettier": "^2.1.2",
7777
"standard-version": "^9.0.0",
7878
"uglify-js": "^3.10.4",
7979
"webpack": "^4.44.1",

test/TerserPlugin.test.js

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,68 @@ describe('TerserPlugin', () => {
908908
}
909909
});
910910

911+
it('should work and use memory cache out of box', async () => {
912+
const compiler = getCompiler({
913+
...(getCompiler.isWebpack4() ? { cache: true } : {}),
914+
entry: {
915+
js: path.resolve(__dirname, './fixtures/entry.js'),
916+
mjs: path.resolve(__dirname, './fixtures/entry.mjs'),
917+
importExport: path.resolve(
918+
__dirname,
919+
'./fixtures/import-export/entry.js'
920+
),
921+
AsyncImportExport: path.resolve(
922+
__dirname,
923+
'./fixtures/async-import-export/entry.js'
924+
),
925+
},
926+
cache: true,
927+
output: {
928+
path: path.resolve(__dirname, './dist'),
929+
filename: '[name].js',
930+
chunkFilename: '[id].[name].js',
931+
},
932+
});
933+
934+
new TerserPlugin().apply(compiler);
935+
936+
const stats = await compile(compiler);
937+
938+
if (getCompiler.isWebpack4()) {
939+
expect(
940+
Object.keys(stats.compilation.assets).filter(
941+
(assetName) => stats.compilation.assets[assetName].emitted
942+
).length
943+
).toBe(5);
944+
} else {
945+
expect(stats.compilation.emittedAssets.size).toBe(5);
946+
}
947+
948+
expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
949+
expect(getWarnings(stats)).toMatchSnapshot('errors');
950+
expect(getErrors(stats)).toMatchSnapshot('warnings');
951+
952+
await new Promise(async (resolve) => {
953+
const newStats = await compile(compiler);
954+
955+
if (getCompiler.isWebpack4()) {
956+
expect(
957+
Object.keys(newStats.compilation.assets).filter(
958+
(assetName) => newStats.compilation.assets[assetName].emitted
959+
).length
960+
).toBe(0);
961+
} else {
962+
expect(newStats.compilation.emittedAssets.size).toBe(0);
963+
}
964+
965+
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
966+
expect(getWarnings(newStats)).toMatchSnapshot('errors');
967+
expect(getErrors(newStats)).toMatchSnapshot('warnings');
968+
969+
resolve();
970+
});
971+
});
972+
911973
it('should work and use memory cache when the "cache" option is "true"', async () => {
912974
const compiler = getCompiler({
913975
entry: {
@@ -961,7 +1023,7 @@ describe('TerserPlugin', () => {
9611023
expect(newStats.compilation.emittedAssets.size).toBe(0);
9621024
}
9631025

964-
expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
1026+
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
9651027
expect(getWarnings(newStats)).toMatchSnapshot('errors');
9661028
expect(getErrors(newStats)).toMatchSnapshot('warnings');
9671029

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

1027-
expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
1089+
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
10281090
expect(getWarnings(newStats)).toMatchSnapshot('errors');
10291091
expect(getErrors(newStats)).toMatchSnapshot('warnings');
10301092

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

1089-
expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
1151+
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
10901152
expect(getWarnings(newStats)).toMatchSnapshot('errors');
10911153
expect(getErrors(newStats)).toMatchSnapshot('warnings');
10921154

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

1153-
expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
1215+
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
11541216
expect(getWarnings(newStats)).toMatchSnapshot('errors');
11551217
expect(getErrors(newStats)).toMatchSnapshot('warnings');
11561218

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

1208-
expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
1270+
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
12091271
expect(getWarnings(newStats)).toMatchSnapshot('errors');
12101272
expect(getErrors(newStats)).toMatchSnapshot('warnings');
12111273

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

1265-
expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
1327+
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
12661328
expect(getWarnings(newStats)).toMatchSnapshot('errors');
12671329
expect(getErrors(newStats)).toMatchSnapshot('warnings');
12681330

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

1324-
expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
1386+
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
13251387
expect(getWarnings(newStats)).toMatchSnapshot('errors');
13261388
expect(getErrors(newStats)).toMatchSnapshot('warnings');
13271389

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

1385-
expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
1447+
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
13861448
expect(getWarnings(newStats)).toMatchSnapshot('errors');
13871449
expect(getErrors(newStats)).toMatchSnapshot('warnings');
13881450

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

1446-
expect(readsAssets(compiler, stats)).toMatchSnapshot('assets');
1508+
expect(readsAssets(compiler, newStats)).toMatchSnapshot('assets');
14471509
expect(getWarnings(newStats)).toMatchSnapshot('errors');
14481510
expect(getErrors(newStats)).toMatchSnapshot('warnings');
14491511

0 commit comments

Comments
 (0)