Skip to content

Commit 44d0351

Browse files
Winnie Hellmanntmorehouse
Winnie Hellmann
authored andcommitted
feat: add BOOTSTRAP_VUE_NO_WARN environment variable to hide warnings (#2826)
1 parent a17de35 commit 44d0351

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

docs/markdown/misc/settings/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Miscellaneous Settings
2+
3+
## Disabling BootstrapVue console warnings
4+
5+
BootstrapVue will warn (via `console.warn`) when you try and use a depreated prop, or pass
6+
an invalid value to certain props. These warnings are provided to help you ensure that your
7+
application is using the correct props and values.
8+
9+
In some cases, you may want to disable these warnings (not recommended). You can do so by
10+
setting the following process envinronment variable:
11+
12+
<!-- eslint-disable no-unused-vars -->
13+
14+
```js
15+
process.env.BOOTSTRAP_VUE_NO_WARN = true
16+
```
17+
18+
By ignoring warnings, you may find that your project fails/breaks when using future releases
19+
of bootstrapVue where deprecated props have been removed.
20+
21+
Warnings should be corrected before moving your project into production!

docs/markdown/misc/settings/meta.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"title": "Settings"
3+
}

src/utils/env.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Info about the current environment
22

3+
// Constants
4+
35
export const inBrowser = typeof document !== 'undefined' && typeof window !== 'undefined'
46

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

1012
export const hasPointerEvent = inBrowser && Boolean(window.PointerEvent || window.MSPointerEvent)
13+
14+
// Getters
15+
16+
export const getNoWarn = () => process && process.env && process.env.BOOTSTRAP_VUE_NO_WARN

src/utils/warn.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import { getNoWarn } from './env'
2+
13
/**
24
* Log a warning message to the console with bootstrap-vue formatting sugar.
35
* @param {string} message
46
*/
57
/* istanbul ignore next */
68
const warn = message => {
7-
console.warn(`[BootstrapVue warn]: ${message}`)
9+
if (!getNoWarn()) {
10+
console.warn(`[BootstrapVue warn]: ${message}`)
11+
}
812
}
913

1014
export default warn

src/utils/warn.spec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import warn from './warn'
2+
3+
describe('utils/warn', () => {
4+
const dummyWarning = 'A Rush Of Blood To The Head'
5+
6+
let originalProcess
7+
8+
beforeAll(() => {
9+
jest.spyOn(console, 'warn').mockImplementation(() => {})
10+
originalProcess = global.process
11+
})
12+
13+
afterEach(() => {
14+
console.warn.mockClear()
15+
global.process = originalProcess
16+
})
17+
18+
describe('with BOOTSTRAP_VUE_NO_WARN environment variable set', () => {
19+
beforeEach(() => {
20+
global.process = {
21+
env: {
22+
BOOTSTRAP_VUE_NO_WARN: true
23+
}
24+
}
25+
})
26+
27+
it('does not call console.warn()', () => {
28+
warn(dummyWarning)
29+
30+
expect(console.warn).not.toHaveBeenCalled()
31+
})
32+
})
33+
34+
describe('without process object', () => {
35+
beforeEach(() => {
36+
global.process = null
37+
})
38+
39+
it('calls console.warn()', () => {
40+
warn(dummyWarning)
41+
42+
expect(console.warn).toHaveBeenCalledWith(`[BootstrapVue warn]: ${dummyWarning}`)
43+
})
44+
})
45+
})

0 commit comments

Comments
 (0)