Skip to content

Commit 6446127

Browse files
authored
Fix content hash warning in production (#320)
* Reverse the condition for the warning message
1 parent 1e8548c commit 6446127

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Changes since last non-beta release.
99

1010
_Please add entries here for your pull requests that are not yet released._
1111

12+
### Fixed
13+
- Fixed the condition for showing warning for setting `useContentHash` to `false` in the production environment. [PR 320](https://github.com/shakacode/shakapacker/pull/320) by [ahangarha](https://github.com/ahangarha).
14+
1215
### Breaking changes
1316
- Removes defaults passed to `@babel/preset-typescript`. [PR 273](https://github.com/shakacode/shakapacker/pull/273) by [tomdracz](https://github.com/tomdracz).
1417

package/environments/__tests__/production.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ describe('Production specific config', () => {
2323
'js/[name]-[contenthash].chunk.js'
2424
)
2525
})
26+
27+
test("doesn't shows any warning message", () => {
28+
const consoleWarnSpy = jest.spyOn(console, 'warn');
29+
const config = require("../../config");
30+
config.useContentHash = true
31+
const environmnetConfig = require('../production')
32+
33+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
34+
expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
35+
)
36+
37+
consoleWarnSpy.mockRestore()
38+
})
2639
})
2740

2841
describe('with config.useContentHash = false', () => {
@@ -36,6 +49,19 @@ describe('Production specific config', () => {
3649
'js/[name]-[contenthash].chunk.js'
3750
)
3851
})
52+
53+
test('shows a warning message', () => {
54+
const consoleWarnSpy = jest.spyOn(console, 'warn');
55+
const config = require("../../config");
56+
config.useContentHash = false
57+
const environmnetConfig = require('../production')
58+
59+
expect(consoleWarnSpy).toHaveBeenCalledWith(
60+
expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
61+
)
62+
63+
consoleWarnSpy.mockRestore()
64+
})
3965
})
4066

4167
describe('with unset config.useContentHash', () => {
@@ -49,5 +75,18 @@ describe('Production specific config', () => {
4975
'js/[name]-[contenthash].chunk.js'
5076
)
5177
})
78+
79+
test("doesn't shows any warning message", () => {
80+
const consoleWarnSpy = jest.spyOn(console, 'warn');
81+
const config = require("../../config");
82+
delete config.useContentHash
83+
const environmnetConfig = require('../production')
84+
85+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
86+
expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
87+
)
88+
89+
consoleWarnSpy.mockRestore()
90+
})
5291
})
5392
})

package/environments/production.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const productionConfig = {
7777
}
7878
}
7979

80-
if (config.useContentHash === true) {
80+
if (config.useContentHash === false) {
8181
// eslint-disable-next-line no-console
8282
console.warn(`⚠️ WARNING
8383
Setting 'useContentHash' to 'false' in the production environment (specified by NODE_ENV environment variable) is not allowed!

0 commit comments

Comments
 (0)