-
-
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(browser/v7): Add test for captureConsole (#11830)
Adding tests for #11829 on v7.
- Loading branch information
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
dev-packages/browser-integration-tests/suites/integrations/captureConsole/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,10 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
import { captureConsoleIntegration } from '@sentry/integrations'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
integrations: [captureConsoleIntegration()], | ||
autoSessionTracking: false, | ||
}); |
8 changes: 8 additions & 0 deletions
8
dev-packages/browser-integration-tests/suites/integrations/captureConsole/subject.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,8 @@ | ||
console.log('console log'); | ||
console.warn('console warn'); | ||
console.error('console error'); | ||
console.info('console info'); | ||
console.trace('console trace'); | ||
|
||
console.error(new Error('console error with error object')); | ||
console.trace(new Error('console trace with error object')); |
113 changes: 113 additions & 0 deletions
113
dev-packages/browser-integration-tests/suites/integrations/captureConsole/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,113 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests } from '../../../utils/helpers'; | ||
|
||
sentryTest('it captures console messages correctly', async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const [, events] = await Promise.all([page.goto(url), getMultipleSentryEnvelopeRequests<Event>(page, 7)]); | ||
|
||
expect(events).toHaveLength(7); | ||
|
||
const logEvent = events.find(event => event.message === 'console log'); | ||
const warnEvent = events.find(event => event.message === 'console warn'); | ||
const infoEvent = events.find(event => event.message === 'console info'); | ||
const errorEvent = events.find(event => event.message === 'console error'); | ||
const traceEvent = events.find(event => event.message === 'console trace'); | ||
const errorWithErrorEvent = events.find(event => !!event.exception); | ||
const traceWithErrorEvent = events.find(event => event.message === 'Error: console trace with error object'); | ||
|
||
expect(logEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'log', | ||
logger: 'console', | ||
extra: { | ||
arguments: ['console log'], | ||
}, | ||
}), | ||
); | ||
expect(logEvent?.exception).toBeUndefined(); | ||
expect(warnEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'warning', | ||
logger: 'console', | ||
extra: { | ||
arguments: ['console warn'], | ||
}, | ||
}), | ||
); | ||
expect(warnEvent?.exception).toBeUndefined(); | ||
expect(infoEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'info', | ||
logger: 'console', | ||
extra: { | ||
arguments: ['console info'], | ||
}, | ||
}), | ||
); | ||
expect(infoEvent?.exception).toBeUndefined(); | ||
expect(errorEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'error', | ||
logger: 'console', | ||
extra: { | ||
arguments: ['console error'], | ||
}, | ||
}), | ||
); | ||
expect(errorEvent?.exception).toBeUndefined(); | ||
expect(traceEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'log', | ||
logger: 'console', | ||
extra: { | ||
arguments: ['console trace'], | ||
}, | ||
}), | ||
); | ||
expect(traceEvent?.exception).toBeUndefined(); | ||
expect(errorWithErrorEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'error', | ||
logger: 'console', | ||
extra: { | ||
arguments: [ | ||
{ | ||
message: 'console error with error object', | ||
name: 'Error', | ||
stack: expect.any(String), | ||
}, | ||
], | ||
}, | ||
exception: expect.any(Object), | ||
}), | ||
); | ||
expect(errorWithErrorEvent?.exception?.values?.[0].value).toBe('console error with error object'); | ||
expect(traceWithErrorEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'log', | ||
logger: 'console', | ||
extra: { | ||
arguments: [ | ||
{ | ||
message: 'console trace with error object', | ||
name: 'Error', | ||
stack: expect.any(String), | ||
}, | ||
], | ||
}, | ||
}), | ||
); | ||
expect(traceWithErrorEvent?.exception).toBeUndefined(); | ||
}); |