Skip to content

Commit

Permalink
fix: use log instead of warn during dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Nov 26, 2020
1 parent 8e10f8a commit 4770eb5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 deletions.
3 changes: 2 additions & 1 deletion packages/dnb-design-system-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"make-ui-lib-pages:dev": "nodemon --exec 'yarn make-ui-lib-pages' --ext js --watch '../dnb-ui-lib/src/**/*' --watch '**/makeDemosFactory.js' --watch '**/tasks/*' --watch '**/Template.js' --watch '**/template.md'",
"reset": "rm -rf ./node_modules && yarn clean",
"serve": "gatsby serve -p 8000",
"start": "cross-env DEBUG=gatsby:query-watcher GATSBY_HOT_LOADER=fast-refresh GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND=1 GATSBY_EXPERIMENTAL_FAST_DEV=true gatsby develop",
"start": "cross-env DEBUG=gatsby:query-watcher GATSBY_HOT_LOADER=fast-refresh gatsby develop",
"start-dev": "cross-env DEBUG=gatsby:query-watcher GATSBY_HOT_LOADER=fast-refresh GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND=1 GATSBY_EXPERIMENTAL_FAST_DEV=true gatsby develop",
"test": "jest --watch",
"test-ci": "jest --ci",
"test:staged": "jest --bail --findRelatedTests ",
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-ui-lib/src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default class Button extends React.PureComponent {
let usedSize = size
let content = Button.getContent(this.props) || text

if (variant === 'tertiary' && content && !icon) {
if (variant === 'tertiary' && content && !icon && icon !== false) {
warn(
`A Tertiary Button requires an icon. Please declare an icon to: ${content}`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ props.tooltip = null
props.icon_position = 'right'

beforeAll(() => {
jest.spyOn(global.console, 'warn')
jest.spyOn(global.console, 'log')
})

describe('Button component', () => {
Expand Down Expand Up @@ -150,9 +150,9 @@ describe('Button component', () => {

it('will warn when tertiary is used without an icon', () => {
process.env.NODE_ENV = 'development'
global.console.warn = jest.fn()
global.console.log = jest.fn()
mount(<Component text="Button" variant="tertiary" />)
expect(global.console.warn).toBeCalled()
expect(global.console.log).toBeCalled()
})

it('has no size when only setting text', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/dnb-ui-lib/src/components/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ class DropdownInstance extends React.PureComponent {
) : (
<Button
variant="secondary"
icon={false} // only to suppress the warning about the icon when tertiary variant is used
size={size === 'default' ? 'medium' : size}
ref={this._refButton}
{...triggerParams}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ exports[`Dropdown markup have to match snapshot 1`] = `
element={null}
global_status_id={null}
href={null}
icon={null}
icon={false}
icon_position="right"
icon_size={null}
id="dropdown-id"
Expand Down Expand Up @@ -553,7 +553,7 @@ exports[`Dropdown markup have to match snapshot 1`] = `
element={null}
global_status_id={null}
href={null}
icon={null}
icon={false}
icon_position="right"
icon_size={null}
id="dropdown-id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ beforeAll(() => {
navigator.maxTouchPoints = 2 // mocking touch
defineNavigator()

jest.spyOn(global.console, 'warn')
jest.spyOn(global.console, 'log')
})
afterAll(() => {
document.documentElement.removeAttribute('data-is-touch')
Expand Down Expand Up @@ -613,18 +613,18 @@ describe('"matchAll" should', () => {
describe('"warn" should', () => {
const text = 'warning text'

it('print a console.warn', () => {
it('print a console.log', () => {
process.env.NODE_ENV = 'development'
global.console.warn = jest.fn()
global.console.log = jest.fn()
warn(text)
expect(global.console.warn).toBeCalled()
expect(global.console.warn).toHaveBeenCalledWith(text)
expect(global.console.log).toBeCalled()
expect(global.console.log).toHaveBeenCalledWith('Eufemia:', text)
})

it('not print a console.warn in production', () => {
it('not print a console.log in production', () => {
process.env.NODE_ENV = 'production'
global.console.warn = jest.fn()
global.console.log = jest.fn()
warn(text)
expect(global.console.warn).not.toBeCalled()
expect(global.console.log).not.toBeCalled()
})
})
12 changes: 3 additions & 9 deletions packages/dnb-ui-lib/src/shared/component-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,16 +636,10 @@ export const warn = (...e) => {
if (
typeof process !== 'undefined' &&
typeof console !== 'undefined' &&
process.env.NODE_ENV !== 'production'
process.env.NODE_ENV !== 'production' &&
typeof console.log === 'function'
) {
if (
process.env.NODE_ENV === 'test' &&
typeof console.log === 'function'
) {
console.log(...e)
} else if (typeof console.warn === 'function') {
console.warn(...e)
}
console.log('Eufemia:', ...e)
}
}

Expand Down

0 comments on commit 4770eb5

Please sign in to comment.