-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vue): Expose
initVueApp
method to initialize vue app later
- Loading branch information
Showing
5 changed files
with
126 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export * from '@sentry/browser'; | ||
|
||
export { init } from './sdk'; | ||
export { init, initVueApp } from './sdk'; | ||
export { vueRouterInstrumentation } from './router'; | ||
export { attachErrorHandler } from './errorhandler'; | ||
export { createTracingMixins } from './tracing'; |
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
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,81 @@ | ||
import { logger } from '@sentry/utils'; | ||
import { createApp } from 'vue'; | ||
|
||
import * as Sentry from '../../src'; | ||
import { Hub, makeMain } from '../../src'; | ||
|
||
const PUBLIC_DSN = 'https://username@domain/123'; | ||
|
||
describe('Sentry.initVueApp', () => { | ||
let loggerWarnings: unknown[] = []; | ||
let warnings: unknown[] = []; | ||
|
||
beforeEach(() => { | ||
warnings = []; | ||
loggerWarnings = []; | ||
|
||
jest.spyOn(logger, 'warn').mockImplementation((message: unknown) => { | ||
loggerWarnings.push(message); | ||
}); | ||
|
||
jest.spyOn(console, 'warn').mockImplementation((message: unknown) => { | ||
warnings.push(message); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('warns when called before SDK.init()', () => { | ||
const hub = new Hub(); | ||
makeMain(hub); | ||
|
||
const app = createApp({ | ||
template: '<div>hello</div>', | ||
}); | ||
|
||
Sentry.initVueApp(app); | ||
|
||
expect(loggerWarnings).toEqual([ | ||
'[@sentry/vue]: Cannot initialize as no Client available. Make sure to call `Sentry.init` before calling `initVueApp()`.', | ||
]); | ||
expect(warnings).toEqual([]); | ||
}); | ||
|
||
it('warns when mounting before SDK.initVueApp()', () => { | ||
Sentry.init({ dsn: PUBLIC_DSN, app: false, autoSessionTracking: false }); | ||
|
||
const el = document.createElement('div'); | ||
const app = createApp({ | ||
template: '<div>hello</div>', | ||
}); | ||
|
||
app.mount(el); | ||
|
||
Sentry.initVueApp(app); | ||
|
||
expect(warnings).toEqual([ | ||
'[@sentry/vue]: Misconfigured SDK. Vue app is already mounted. Make sure to call `app.mount()` after `Sentry.init()`.', | ||
]); | ||
expect(loggerWarnings).toEqual([]); | ||
}); | ||
|
||
it('works when calling SDK.initVueApp()', () => { | ||
Sentry.init({ dsn: PUBLIC_DSN, app: false, autoSessionTracking: false }); | ||
|
||
const el = document.createElement('div'); | ||
const app = createApp({ | ||
template: '<div>hello</div>', | ||
}); | ||
|
||
Sentry.initVueApp(app); | ||
|
||
app.mount(el); | ||
|
||
expect(warnings).toEqual([]); | ||
expect(loggerWarnings).toEqual([]); | ||
|
||
expect(app.config.errorHandler).toBeDefined(); | ||
}); | ||
}); |