diff --git a/docs/markdown/misc/settings/README.md b/docs/markdown/misc/settings/README.md new file mode 100644 index 00000000000..8ddb63f3227 --- /dev/null +++ b/docs/markdown/misc/settings/README.md @@ -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: + + + +```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! diff --git a/docs/markdown/misc/settings/meta.json b/docs/markdown/misc/settings/meta.json new file mode 100644 index 00000000000..1ed130b5c74 --- /dev/null +++ b/docs/markdown/misc/settings/meta.json @@ -0,0 +1,3 @@ +{ + "title": "Settings" +} diff --git a/src/utils/env.js b/src/utils/env.js index 5395044e97e..800aebba97a 100644 --- a/src/utils/env.js +++ b/src/utils/env.js @@ -1,5 +1,7 @@ // Info about the current environment +// Constants + export const inBrowser = typeof document !== 'undefined' && typeof window !== 'undefined' export const isServer = !inBrowser @@ -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 diff --git a/src/utils/warn.js b/src/utils/warn.js index b1258e970d3..53f7f6ddeb9 100644 --- a/src/utils/warn.js +++ b/src/utils/warn.js @@ -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 diff --git a/src/utils/warn.spec.js b/src/utils/warn.spec.js new file mode 100644 index 00000000000..993f5a11c70 --- /dev/null +++ b/src/utils/warn.spec.js @@ -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}`) + }) + }) +})