-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add console warning for wrong database config (#1059)
* Add console warning for wrong database config * Add DevBadge
- Loading branch information
Showing
8 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"app_id": "history-analyst-dad", | ||
"app_key": "be606bcfa3db4377bf488900281aa1cc", | ||
"development": true, | ||
"wpcc_client_id": "0", | ||
"wpcc_redirect_url": "https://simplenote.com" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
|
||
const DevBadge = () => { | ||
return <div className="dev-badge">DEV</div>; | ||
}; | ||
|
||
export default DevBadge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.dev-badge { | ||
position: absolute; | ||
opacity: .8; | ||
z-index: 1; | ||
right: 12px; | ||
bottom: 12px; | ||
padding: 2px 4px; | ||
background: $gray-lightest; | ||
color: $gray-darkest; | ||
font-size: .75rem; | ||
line-height: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const isDevConfig = config => { | ||
const isDev = Boolean(config.development); | ||
const whichDB = isDev ? 'Development' : 'Production'; | ||
const shouldWarn = | ||
process.env.NODE_ENV === 'production' && config.development; | ||
const consoleMode = shouldWarn ? 'warn' : 'info'; | ||
console[consoleMode](`Simperium config: ${whichDB}`); // eslint-disable-line no-console | ||
|
||
return isDev; | ||
}; | ||
|
||
export default isDevConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import isDevConfig from './'; | ||
|
||
describe('isDevConfig', () => { | ||
const unmockedConsole = global.console; | ||
|
||
beforeEach(() => { | ||
global.console = { | ||
info: jest.fn(), | ||
warn: jest.fn(), | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
global.process.env.NODE_ENV = 'test'; | ||
global.console = unmockedConsole; | ||
}); | ||
|
||
it('should return a boolean of whether config is dev or not', () => { | ||
expect(isDevConfig({ development: true })).toBe(true); | ||
expect(isDevConfig({})).toBe(false); | ||
}); | ||
|
||
it('should console.warn when NODE_ENV is production and Simperium is not', () => { | ||
global.process.env.NODE_ENV = 'production'; | ||
global.console.warn = jest.fn(); | ||
const config = { development: true }; | ||
isDevConfig(config); | ||
expect(global.console.warn).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters