Skip to content

Commit

Permalink
fix: regenerate contenthash when you update terser or change options
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 21, 2018
1 parent 8cd50d7 commit 7dc3360
Show file tree
Hide file tree
Showing 18 changed files with 450 additions and 412 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ jobs:
name: Submit coverage data to codecov.
command: bash <(curl -s https://codecov.io/bash)
when: on_success
node6-canary:
node8-canary:
docker:
- image: webpackcontrib/circleci-node10:latest
- image: webpackcontrib/circleci-node8:latest
<<: *canary_tests

workflows:
Expand Down Expand Up @@ -136,7 +136,7 @@ workflows:
filters:
tags:
only: /.*/
- node6-canary:
- node8-canary:
requires:
- analysis
- node6-latest
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ environment:
- nodejs_version: '11'
webpack_version: latest
job_part: test
- nodejs_version: '6'
- nodejs_version: '8'
webpack_version: next
job_part: next
job_part: test
build: 'off'
matrix:
fast_finish: true
Expand Down
120 changes: 64 additions & 56 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bugs": "https://github.com/webpack-contrib/terser-webpack-plugin/issues",
"main": "dist/cjs.js",
"engines": {
"node": ">= 6.9.0 <7.0.0 || >= 8.9.0"
"node": ">= 6.9.0"
},
"scripts": {
"start": "npm run build -- -w",
Expand All @@ -35,7 +35,7 @@
"dist"
],
"peerDependencies": {
"webpack": "^4.3.0"
"webpack": "^4.0.0"
},
"dependencies": {
"cacache": "^11.0.2",
Expand Down
26 changes: 25 additions & 1 deletion test/TerserPlugin.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import RequestShortener from 'webpack/lib/RequestShortener';
import MainTemplate from 'webpack/lib/MainTemplate';
import ChunkTemplate from 'webpack/lib/ChunkTemplate';

import TerserPlugin from '../src/index';

Expand Down Expand Up @@ -42,7 +44,17 @@ describe('TerserPlugin', () => {
});
});

it.only('should works regenerate hash', () => {
it('should regenerate hash', () => {
const originalMainTemplateUpdateHashForChunk =
MainTemplate.prototype.updateHashForChunk;
const originalChunkTemplateUpdateHashForChunk =
ChunkTemplate.prototype.updateHashForChunk;
const mockMainTemplateUpdateHashForChunk = jest.fn();
const mockChunkTemplateUpdateHashFocChunk = jest.fn();

MainTemplate.prototype.updateHashForChunk = mockMainTemplateUpdateHashForChunk;
ChunkTemplate.prototype.updateHashForChunk = mockChunkTemplateUpdateHashFocChunk;

const compiler = createCompiler({
entry: {
js: `${__dirname}/fixtures/entry.js`,
Expand All @@ -66,13 +78,25 @@ describe('TerserPlugin', () => {
expect(errors).toMatchSnapshot('errors');
expect(warnings).toMatchSnapshot('warnings');

// On each chunk we have 2 calls (we have 1 async chunk and 4 initial).
// First call do `webpack`.
// Second call do `TerserPlugin`.

// We have 1 async chunk (1 * 2 = 2 calls for ChunkTemplate)
expect(mockMainTemplateUpdateHashForChunk).toHaveBeenCalledTimes(8);
// We have 4 initial chunks (4 * 2 = 8 calls for MainTemplate)
expect(mockChunkTemplateUpdateHashFocChunk).toHaveBeenCalledTimes(2);

for (const file in stats.compilation.assets) {
if (
Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)
) {
expect(stats.compilation.assets[file].source()).toMatchSnapshot(file);
}
}

MainTemplate.prototype.updateHashForChunk = originalMainTemplateUpdateHashForChunk;
ChunkTemplate.prototype.updateHashForChunk = originalChunkTemplateUpdateHashForChunk;
});
});

Expand Down
Loading

0 comments on commit 7dc3360

Please sign in to comment.