File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed
dev-packages/browser-integration-tests/suites/integrations/lazyLoad/moduleMetadataIntegration Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ import * as Sentry from '@sentry/browser' ;
2+
3+ Sentry . init ( {
4+ dsn :
'https://[email protected] /1337' , 5+ integrations : [ ] ,
6+ } ) ;
7+
8+ window . Sentry = {
9+ ...Sentry ,
10+ } ;
Original file line number Diff line number Diff line change 1+ window . _testLazyLoadIntegration = async function run ( ) {
2+ const integration = await window . Sentry . lazyLoadIntegration ( 'moduleMetadataIntegration' ) ;
3+
4+ window . Sentry . getClient ( ) ?. addIntegration ( integration ( ) ) ;
5+
6+ window . _integrationLoaded = true ;
7+ } ;
Original file line number Diff line number Diff line change 1+ import { expect } from '@playwright/test' ;
2+ import { SDK_VERSION } from '@sentry/browser' ;
3+
4+ import { sentryTest } from '../../../../utils/fixtures' ;
5+
6+ sentryTest ( 'it allows to lazy load the moduleMetadata integration' , async ( { getLocalTestUrl, page } ) => {
7+ const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
8+
9+ await page . route ( `https://browser.sentry-cdn.com/${ SDK_VERSION } /modulemetadata.min.js` , route => {
10+ return route . fulfill ( {
11+ status : 200 ,
12+ contentType : 'application/javascript;' ,
13+ body : "window.Sentry.moduleMetadataIntegration = () => ({ name: 'ModuleMetadata' })" ,
14+ } ) ;
15+ } ) ;
16+
17+ await page . goto ( url ) ;
18+
19+ const hasIntegration = await page . evaluate ( '!!window.Sentry.getClient()?.getIntegrationByName("ModuleMetadata")' ) ;
20+ expect ( hasIntegration ) . toBe ( false ) ;
21+
22+ const scriptTagsBefore = await page . evaluate < number > ( 'document.querySelectorAll("script").length' ) ;
23+
24+ await page . evaluate ( 'window._testLazyLoadIntegration()' ) ;
25+ await page . waitForFunction ( 'window._integrationLoaded' ) ;
26+
27+ const scriptTagsAfter = await page . evaluate < number > ( 'document.querySelectorAll("script").length' ) ;
28+
29+ const hasIntegration2 = await page . evaluate ( '!!window.Sentry.getClient()?.getIntegrationByName("ModuleMetadata")' ) ;
30+ expect ( hasIntegration2 ) . toBe ( true ) ;
31+
32+ expect ( scriptTagsAfter ) . toBe ( scriptTagsBefore + 1 ) ;
33+ } ) ;
You can’t perform that action at this time.
0 commit comments