Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vue): Check if SDK is initialized before app is mounted (#6227)
* feat(vue): Check if SDK is initialized before app is mounted * feat(vue): Actually `console.warn` when not passing app/Vue
- Loading branch information
Showing
4 changed files
with
243 additions
and
10 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
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,93 @@ | ||
import { createApp } from 'vue'; | ||
|
||
import * as Sentry from './../../src'; | ||
|
||
describe('Sentry.init', () => { | ||
let _consoleWarn: any; | ||
let warnings: string[] = []; | ||
|
||
beforeEach(() => { | ||
warnings = []; | ||
// eslint-disable-next-line no-console | ||
_consoleWarn = console.warn; | ||
// eslint-disable-next-line no-console | ||
console.warn = jest.fn((message: string) => { | ||
warnings.push(message); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
// eslint-disable-next-line no-console | ||
console.warn = _consoleWarn; | ||
}); | ||
|
||
it('does not warn when correctly setup (Vue 3)', () => { | ||
const el = document.createElement('div'); | ||
const app = createApp({ | ||
template: '<div>hello</div>', | ||
}); | ||
|
||
Sentry.init({ | ||
app, | ||
defaultIntegrations: false, | ||
}); | ||
|
||
app.mount(el); | ||
|
||
expect(warnings).toEqual([]); | ||
}); | ||
|
||
it('does not warn when correctly setup (Vue 2)', () => { | ||
const el = document.createElement('div'); | ||
const app = createApp({ | ||
template: '<div>hello</div>', | ||
}); | ||
|
||
Sentry.init({ | ||
// this is a bit "hacky", but good enough to test what we want | ||
Vue: app, | ||
defaultIntegrations: false, | ||
}); | ||
|
||
app.mount(el); | ||
|
||
expect(warnings).toEqual([]); | ||
}); | ||
|
||
it('warns when mounting before SDK init', () => { | ||
const el = document.createElement('div'); | ||
const app = createApp({ | ||
template: '<div>hello</div>', | ||
}); | ||
|
||
app.mount(el); | ||
|
||
Sentry.init({ | ||
app, | ||
defaultIntegrations: false, | ||
}); | ||
|
||
expect(warnings).toEqual([ | ||
'[@sentry/vue]: Misconfigured SDK. Vue app is already mounted. Make sure to call `app.mount()` after `Sentry.init()`.', | ||
]); | ||
}); | ||
|
||
it('warns when not passing app & Vue', () => { | ||
const el = document.createElement('div'); | ||
const app = createApp({ | ||
template: '<div>hello</div>', | ||
}); | ||
|
||
Sentry.init({ | ||
defaultIntegrations: false, | ||
}); | ||
|
||
app.mount(el); | ||
|
||
expect(warnings).toEqual([ | ||
`[@sentry/vue]: Misconfigured SDK. Vue specific errors will not be captured. | ||
Update your \`Sentry.init\` call with an appropriate config option: | ||
\`app\` (Application Instance - Vue 3) or \`Vue\` (Vue Constructor - Vue 2).`, | ||
]); | ||
}); | ||
}); |
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