-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(loader): Improve loader tests & update loader
- Loading branch information
Showing
17 changed files
with
75 additions
and
40 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
packages/browser-integration-tests/loader-suites/loader/noOnLoad/init.js
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,3 +1 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; |
3 changes: 0 additions & 3 deletions
3
packages/browser-integration-tests/loader-suites/loader/noOnLoad/pageloadTransaction/init.js
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,4 +1 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
window._testBaseTimestamp = performance.timeOrigin / 1000; |
2 changes: 0 additions & 2 deletions
2
packages/browser-integration-tests/loader-suites/loader/noOnLoad/replay/init.js
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,3 +1 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; |
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
5 changes: 1 addition & 4 deletions
5
...es/browser-integration-tests/loader-suites/loader/onLoad/captureExceptionInOnLoad/init.js
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,7 +1,4 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.onLoad(function () { | ||
Sentry.init(); | ||
Sentry.captureException('Test exception'); | ||
}); |
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
3 changes: 0 additions & 3 deletions
3
packages/browser-integration-tests/loader-suites/loader/onLoad/customBrowserTracing/init.js
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
20 changes: 20 additions & 0 deletions
20
packages/browser-integration-tests/loader-suites/loader/onLoad/customInit/init.js
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,20 @@ | ||
window.__sentryOnLoad = 0; | ||
|
||
setTimeout(() => { | ||
Sentry.onLoad(function () { | ||
window.__hadSentry = window.sentryIsLoaded(); | ||
|
||
Sentry.init({ | ||
sampleRate: 0.5, | ||
}); | ||
|
||
window.__sentryOnLoad++; | ||
}); | ||
}); | ||
|
||
window.sentryIsLoaded = () => { | ||
const __sentry = window.__SENTRY__; | ||
|
||
// If there is a global __SENTRY__ that means that in any of the callbacks init() was already invoked | ||
return !!(!(typeof __sentry === 'undefined') && __sentry.hub && __sentry.hub.getClient()); | ||
}; |
34 changes: 34 additions & 0 deletions
34
packages/browser-integration-tests/loader-suites/loader/onLoad/customInit/test.ts
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,34 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { LOADER_CONFIGS } from '../../../../utils/generatePlugin'; | ||
|
||
const bundle = process.env.PW_BUNDLE || ''; | ||
const isLazy = LOADER_CONFIGS[bundle]?.lazy; | ||
|
||
sentryTest('always calls onLoad init correctly', async ({ getLocalTestUrl, page }) => { | ||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
|
||
// We want to test that if we are _not_ lazy, we are correctly calling onLoad init() | ||
// But if we are lazy and call `forceLoad`, we also call the onLoad init() correctly | ||
if (isLazy) { | ||
expect(await page.evaluate('window.__sentryOnLoad')).toEqual(0); | ||
await page.evaluate('Sentry.forceLoad()'); | ||
} | ||
|
||
await page.waitForFunction('window.__sentryOnLoad && window.sentryIsLoaded()'); | ||
|
||
expect(await page.evaluate('window.__hadSentry')).toEqual(false); | ||
expect(await page.evaluate('window.__sentryOnLoad')).toEqual(1); | ||
expect(await page.evaluate('Sentry.getCurrentHub().getClient().getOptions().sampleRate')).toEqual(0.5); | ||
}); |
4 changes: 0 additions & 4 deletions
4
packages/browser-integration-tests/loader-suites/loader/onLoad/customIntegrations/init.js
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
4 changes: 0 additions & 4 deletions
4
.../browser-integration-tests/loader-suites/loader/onLoad/customIntegrationsFunction/init.js
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
4 changes: 0 additions & 4 deletions
4
packages/browser-integration-tests/loader-suites/loader/onLoad/customReplay/init.js
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
4 changes: 0 additions & 4 deletions
4
packages/browser-integration-tests/loader-suites/loader/onLoad/init.js
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,7 +1,3 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.onLoad(function () { | ||
Sentry.init({}); | ||
}); |
3 changes: 0 additions & 3 deletions
3
packages/browser-integration-tests/loader-suites/loader/onLoad/pageloadTransaction/init.js
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
4 changes: 0 additions & 4 deletions
4
packages/browser-integration-tests/loader-suites/loader/onLoad/replay/init.js
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,7 +1,3 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.onLoad(function () { | ||
Sentry.init({}); | ||
}); |