-
-
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(bundles): Ensure CDN bundles always have a
Replay
export
- Loading branch information
Showing
11 changed files
with
160 additions
and
1 deletion.
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
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,46 @@ | ||
import type { Integration } from '@sentry/types'; | ||
|
||
/** | ||
* This is a shim for the Replay integration. | ||
* It is needed in order for the CDN bundles to continue working when users add/remove replay | ||
* from it, without changing their config. This is necessary for the loader mechanism. | ||
*/ | ||
export class ReplayShim implements Integration { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public static id: string = 'Replay'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public name: string = ReplayShim.id; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
public constructor(_options: any) { | ||
// eslint-disable-next-line no-console | ||
console.error('You are using new Replay() even though this bundle does not include the replay integration.'); | ||
} | ||
|
||
/** jsdoc */ | ||
public setupOnce(): void { | ||
// noop | ||
} | ||
|
||
/** jsdoc */ | ||
public start(): void { | ||
// noop | ||
} | ||
|
||
/** jsdoc */ | ||
public stop(): void { | ||
// noop | ||
} | ||
|
||
/** jsdoc */ | ||
public flush(): void { | ||
// noop | ||
} | ||
} | ||
|
||
export { ReplayShim as Replay }; |
22 changes: 22 additions & 0 deletions
22
packages/integration-tests/suites/replay/replayShim/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,22 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
// Replay should not actually work, but still not error out | ||
window.Replay = new Sentry.Replay({ | ||
flushMinDelay: 200, | ||
flushMaxDelay: 200, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 1, | ||
replaysSessionSampleRate: 1.0, | ||
replaysOnErrorSampleRate: 0.0, | ||
integrations: [window.Replay], | ||
}); | ||
|
||
// Ensure none of these break | ||
window.Replay.start(); | ||
window.Replay.stop(); | ||
window.Replay.flush(); |
9 changes: 9 additions & 0 deletions
9
packages/integration-tests/suites/replay/replayShim/template.html
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,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button onclick="console.log('Test log')">Click me</button> | ||
</body> | ||
</html> |
37 changes: 37 additions & 0 deletions
37
packages/integration-tests/suites/replay/replayShim/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,37 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
|
||
sentryTest( | ||
'exports a shim Replay integration for non-replay bundles', | ||
async ({ getLocalTestPath, page, forceFlushReplay }) => { | ||
const bundle = process.env.PW_BUNDLE; | ||
|
||
if (!bundle || !bundle.startsWith('bundle_') || bundle.includes('replay')) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const consoleMessages: string[] = []; | ||
page.on('console', msg => consoleMessages.push(msg.text())); | ||
|
||
let requestCount = 0; | ||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
requestCount++; | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
await forceFlushReplay(); | ||
|
||
expect(requestCount).toBe(0); | ||
expect(consoleMessages).toEqual([ | ||
'You are using new Replay() even though this bundle does not include the replay integration.', | ||
]); | ||
}, | ||
); |
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
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