-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Console instrumentation: send a Faro error for console.error logs (#703)
- Loading branch information
1 parent
bc7e264
commit a43406f
Showing
4 changed files
with
89 additions
and
34 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
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
41 changes: 41 additions & 0 deletions
41
packages/web-sdk/src/instrumentations/console/instrumentation.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,41 @@ | ||
import { ExceptionEvent, initializeFaro, TransportItem } from '@grafana/faro-core'; | ||
import { mockConfig, MockTransport } from '@grafana/faro-core/src/testUtils'; | ||
|
||
import { makeCoreConfig } from '../../config'; | ||
|
||
import { ConsoleInstrumentation } from './instrumentation'; | ||
|
||
describe('ConsoleInstrumentation', () => { | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('send a faro error when console.error is called', () => { | ||
const mockTransport = new MockTransport(); | ||
|
||
initializeFaro( | ||
makeCoreConfig( | ||
mockConfig({ | ||
transports: [mockTransport], | ||
instrumentations: [new ConsoleInstrumentation()], | ||
unpatchedConsole: { | ||
error: jest.fn(), | ||
} as unknown as Console, | ||
}) | ||
)! | ||
); | ||
|
||
console.error('console.error no 1'); | ||
console.error('with object', { foo: 'bar', baz: 'bam' }); | ||
|
||
expect(mockTransport.items).toHaveLength(2); | ||
|
||
expect((mockTransport.items[0] as TransportItem<ExceptionEvent>)?.payload.type).toBe('Error'); | ||
expect((mockTransport.items[0] as TransportItem<ExceptionEvent>)?.payload.value).toBe('console.error no 1'); | ||
expect((mockTransport.items[1] as TransportItem<ExceptionEvent>)?.payload.type).toBe('Error'); | ||
expect((mockTransport.items[1] as TransportItem<ExceptionEvent>)?.payload.value).toBe( | ||
'with object {"foo":"bar","baz":"bam"}' | ||
); | ||
}); | ||
}); |
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