Skip to content

Commit

Permalink
fix(plugin-vue): check global vue config exists before installing vue…
Browse files Browse the repository at this point in the history
… 2 handler
  • Loading branch information
yousif-bugsnag committed Jul 12, 2024
1 parent bf17211 commit 69e59db
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Fixed

- (plugin-vue) Check global vue config exists before installing vue 2 handler [#2171](https://github.com/bugsnag/bugsnag-js/pull/2171)

## [7.25.0] - 2024-07-03

### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = class BugsnagPluginVue {
}

load (client) {
if (this.Vue) {
if (this.Vue && this.Vue.config) {
installVue2(this.Vue, client)
return {
installVueErrorHandler: () => client._logger.warn('installVueErrorHandler() was called unnecessarily')
Expand Down
33 changes: 33 additions & 0 deletions packages/plugin-vue/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,39 @@ describe('bugsnag vue', () => {
errorHandler('oops', { $options: { name: 'MyComponent' } }, 1)
})

it('works with a global Vue instance (CDN build)', done => {
// In Vue 3.+ the global Vue.config has been replaced with app.config,
// but CDN builds still expose a global Vue object
const mockVue = {}
const mockVueApp: Vue3App = {
use: (plugin) => {
plugin.install(mockVueApp)
},
config: { errorHandler: undefined }
}
const client = new Client({ apiKey: 'API_KEYYY', plugins: [new BugsnagVuePlugin(mockVue)] })
// eslint-disable-next-line
const plugin = client.getPlugin('vue')!
expect(typeof plugin.install).toBe('function')

mockVueApp.use(plugin)
client._setDelivery(client => ({
sendEvent: (payload) => {
expect(payload.events[0].errors[0].errorClass).toBe('Error')
expect(payload.events[0].errors[0].errorMessage).toBe('oops')
expect(payload.events[0].errors[0].stacktrace[0].file).toBe(__filename)
expect(payload.events[0]._metadata.vue).toBeDefined()
expect(payload.events[0]._metadata.vue.component).toBe('MyComponent')
expect(payload.events[0]._metadata.vue.errorInfo).toBe('render function')
done()
},
sendSession: () => {}
}))
expect(typeof mockVueApp.config.errorHandler).toBe('function')
const errorHandler = mockVueApp.config.errorHandler as unknown as Vue3ErrorHandler
errorHandler(new Error('oops'), { $options: { name: 'MyComponent' } }, 1)
})

//
// VUE 2
//
Expand Down

0 comments on commit 69e59db

Please sign in to comment.