Skip to content

Commit df8560c

Browse files
committed
test: write an e2e test
1 parent bd028cf commit df8560c

5 files changed

Lines changed: 44 additions & 197 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
const integrations = Sentry.getDefaultIntegrations({}).filter(
6+
defaultIntegration => defaultIntegration.name === 'CultureContext',
7+
);
8+
9+
const client = new Sentry.BrowserClient({
10+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
11+
transport: Sentry.makeFetchTransport,
12+
stackParser: Sentry.defaultStackParser,
13+
integrations: integrations,
14+
});
15+
16+
const scope = new Sentry.Scope();
17+
scope.setClient(client);
18+
client.init();
19+
20+
window._sentryScope = scope;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window._sentryScope.captureException(new Error('test error'));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/core';
3+
import { sentryTest } from '../../../utils/fixtures';
4+
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
5+
6+
sentryTest('cultureContextIntegration captures locale, timezone, and calendar', async ({ getLocalTestUrl, page }) => {
7+
const url = await getLocalTestUrl({ testDir: __dirname });
8+
9+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
10+
11+
expect(eventData.exception?.values).toHaveLength(1);
12+
13+
expect(eventData.contexts?.culture).toEqual({
14+
locale: expect.any(String),
15+
timezone: expect.any(String),
16+
calendar: expect.any(String),
17+
});
18+
});

packages/browser/src/integrations/culturecontext.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { CultureContext, IntegrationFn } from '@sentry/core';
2-
import { defineIntegration, GLOBAL_OBJ } from '@sentry/core';
2+
import { defineIntegration } from '@sentry/core';
3+
import { WINDOW } from '../helpers';
34

45
const INTEGRATION_NAME = 'CultureContext';
56

@@ -40,11 +41,12 @@ export const cultureContextIntegration = defineIntegration(_cultureContextIntegr
4041
*/
4142
function getCultureContext(): CultureContext | undefined {
4243
try {
43-
if (typeof (GLOBAL_OBJ as { Intl?: typeof Intl }).Intl === 'undefined') {
44+
const intl = (WINDOW as { Intl?: typeof Intl }).Intl;
45+
if (!intl) {
4446
return undefined;
4547
}
4648

47-
const options = Intl.DateTimeFormat().resolvedOptions();
49+
const options = intl.DateTimeFormat().resolvedOptions();
4850

4951
return {
5052
locale: options.locale,

packages/browser/test/integrations/culturecontext.test.ts

Lines changed: 0 additions & 194 deletions
This file was deleted.

0 commit comments

Comments
 (0)