Skip to content

Commit 7fd314c

Browse files
committed
Add test to make sure moduleMetadataIntegration can be lazy loaded
1 parent 59a7f00 commit 7fd314c

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
});

0 commit comments

Comments
 (0)