Skip to content

feat: add BOOTSTRAP_VUE_NO_WARN environment variable to hide warnings #2826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/markdown/misc/settings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Miscellaneous Settings

## Disabling BootstrapVue console warnings

BootstrapVue will warn (via `console.warn`) when you try and use a depreated prop, or pass
an invalid value to certain props. These warnings are provided to help you ensure that your
application is using the correct props and values.

In some cases, you may want to disable these warnings (not recommended). You can do so by
setting the following process envinronment variable:

<!-- eslint-disable no-unused-vars -->

```js
process.env.BOOTSTRAP_VUE_NO_WARN = true
```

By ignoring warnings, you may find that your project fails/breaks when using future releases
of bootstrapVue where deprecated props have been removed.

Warnings should be corrected before moving your project into production!
3 changes: 3 additions & 0 deletions docs/markdown/misc/settings/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"title": "Settings"
}
6 changes: 6 additions & 0 deletions src/utils/env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Info about the current environment

// Constants

export const inBrowser = typeof document !== 'undefined' && typeof window !== 'undefined'

export const isServer = !inBrowser
Expand All @@ -8,3 +10,7 @@ export const hasTouchSupport =
inBrowser && ('ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0)

export const hasPointerEvent = inBrowser && Boolean(window.PointerEvent || window.MSPointerEvent)

// Getters

export const getNoWarn = () => process && process.env && process.env.BOOTSTRAP_VUE_NO_WARN
6 changes: 5 additions & 1 deletion src/utils/warn.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { getNoWarn } from './env'

/**
* Log a warning message to the console with bootstrap-vue formatting sugar.
* @param {string} message
*/
/* istanbul ignore next */
const warn = message => {
console.warn(`[BootstrapVue warn]: ${message}`)
if (!getNoWarn()) {
console.warn(`[BootstrapVue warn]: ${message}`)
}
}

export default warn
45 changes: 45 additions & 0 deletions src/utils/warn.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import warn from './warn'

describe('utils/warn', () => {
const dummyWarning = 'A Rush Of Blood To The Head'

let originalProcess

beforeAll(() => {
jest.spyOn(console, 'warn').mockImplementation(() => {})
originalProcess = global.process
})

afterEach(() => {
console.warn.mockClear()
global.process = originalProcess
})

describe('with BOOTSTRAP_VUE_NO_WARN environment variable set', () => {
beforeEach(() => {
global.process = {
env: {
BOOTSTRAP_VUE_NO_WARN: true
}
}
})

it('does not call console.warn()', () => {
warn(dummyWarning)

expect(console.warn).not.toHaveBeenCalled()
})
})

describe('without process object', () => {
beforeEach(() => {
global.process = null
})

it('calls console.warn()', () => {
warn(dummyWarning)

expect(console.warn).toHaveBeenCalledWith(`[BootstrapVue warn]: ${dummyWarning}`)
})
})
})