Skip to content

Commit babbed8

Browse files
committed
ref(test): Trigger top-level errors inside sandbox.
1 parent 9a7e276 commit babbed8

File tree

18 files changed

+117
-133
lines changed

18 files changed

+117
-133
lines changed

dev-packages/browser-integration-tests/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ or `init.js` is not defined in a case folder.
1414

1515
`subject.js` contains the logic that sets up the environment to be tested. It also can be defined locally and as a group
1616
fallback. Unlike `template.hbs` and `init.js`, it's not required to be defined for a group, as there may be cases that
17-
does not require a subject, instead the logic is injected using `injectScriptAndGetEvents` from `utils/helpers.ts`.
17+
does not require a subject.
1818

1919
`test.ts` is required for each test case, which contains the assertions (and if required the script injection logic).
2020
For every case, any set of `init.js`, `template.hbs` and `subject.js` can be defined locally, and each one of them will
2121
have precedence over the default definitions of the test group.
2222

2323
To test page multi-page navigations, you can specify additional `page-*.html` (e.g. `page-0.html`, `page-1.html`) files.
2424
These will also be compiled and initialized with the same `init.js` and `subject.js` files that are applied to
25-
`template.hbs/html`. Note: `page-*.html` file lookup **doesn not** fall back to the parent directories, meaning that
26-
page files have to be directly in the `test.ts` directory.
25+
`template.hbs/html`. Note: `page-*.html` file lookup **does not** fall back to the parent directories, meaning that page
26+
files have to be directly in the `test.ts` directory.
2727

2828
```
2929
suites/

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/non-string-arg/subject.js

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

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/non-string-arg/test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@ import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest, runScriptInSandbox } from '../../../../../utils/helpers';
66

77
sentryTest(
88
'should catch onerror calls with non-string first argument gracefully',
99
async ({ getLocalTestPath, page }) => {
1010
const url = await getLocalTestPath({ testDir: __dirname });
1111

12-
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
12+
await page.goto(url);
13+
14+
runScriptInSandbox(page, {
15+
content: `
16+
throw {
17+
type: 'Error',
18+
otherKey: 'otherValue',
19+
};
20+
`,
21+
});
22+
23+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page);
1324

1425
expect(eventData.exception?.values).toHaveLength(1);
1526
expect(eventData.exception?.values?.[0]).toMatchObject({

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown/subject.js

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

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown/test.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@ import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
5-
import { getMultipleSentryEnvelopeRequests } from '../../../../../utils/helpers';
5+
import { getMultipleSentryEnvelopeRequests, runScriptInSandbox } from '../../../../../utils/helpers';
66

77
sentryTest(
88
'should NOT catch an exception already caught [but rethrown] via Sentry.captureException',
99
async ({ getLocalTestPath, page }) => {
1010
const url = await getLocalTestPath({ testDir: __dirname });
1111

12-
const events = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { url });
12+
await page.goto(url);
13+
14+
runScriptInSandbox(page, {
15+
content: `
16+
try {
17+
foo();
18+
} catch (e) {
19+
Sentry.captureException(e);
20+
throw e;
21+
}
22+
`,
23+
});
24+
25+
const events = await getMultipleSentryEnvelopeRequests<Event>(page, 1);
1326

1427
expect(events[0].exception?.values).toHaveLength(1);
1528
expect(events[0].exception?.values?.[0]).toMatchObject({
@@ -24,19 +37,5 @@ sentryTest(
2437
frames: expect.any(Array),
2538
},
2639
});
27-
28-
// This is not a refernece error, but another generic error
29-
expect(events[1].exception?.values).toHaveLength(1);
30-
expect(events[1].exception?.values?.[0]).toMatchObject({
31-
type: 'Error',
32-
value: 'error 2',
33-
mechanism: {
34-
type: 'generic',
35-
handled: true,
36-
},
37-
stacktrace: {
38-
frames: expect.any(Array),
39-
},
40-
});
4140
},
4241
);

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/syntax-errors/subject.js

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

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/syntax-errors/test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest, runScriptInSandbox } from '../../../../../utils/helpers';
66

77
sentryTest('should catch syntax errors', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });
99

10-
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
10+
await page.goto(url);
11+
12+
runScriptInSandbox(page, {
13+
content: `
14+
foo{}; // SyntaxError
15+
`,
16+
});
17+
18+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page);
1119

1220
expect(eventData.exception?.values).toHaveLength(1);
1321
expect(eventData.exception?.values?.[0]).toMatchObject({

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-errors/subject.js

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

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-errors/test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest, runScriptInSandbox } from '../../../../../utils/helpers';
66

77
sentryTest('should catch thrown errors', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });
99

10-
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
10+
await page.goto(url);
11+
12+
runScriptInSandbox(page, {
13+
content: `
14+
throw new Error('realError');
15+
`,
16+
});
17+
18+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page);
1119

1220
expect(eventData.exception?.values).toHaveLength(1);
1321
expect(eventData.exception?.values?.[0]).toMatchObject({

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-objects/subject.js

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

0 commit comments

Comments
 (0)