-
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.
feat: provide getIgnoreUrls function (#732)
- Loading branch information
1 parent
c3b314f
commit bd41a14
Showing
5 changed files
with
61 additions
and
0 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
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 |
---|---|---|
|
@@ -9,3 +9,5 @@ export { | |
} from './webStorage'; | ||
|
||
export { throttle } from './throttle'; | ||
|
||
export { getIgnoreUrls } from './url'; |
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 @@ | ||
import { faro } from '@grafana/faro-core'; | ||
import type { Transport } from '@grafana/faro-core'; | ||
|
||
/** | ||
* Get all configured ignore URLs. | ||
*/ | ||
export function getIgnoreUrls() { | ||
return faro.transports.transports.flatMap((transport: Transport) => transport.getIgnoreUrls()); | ||
} |
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,45 @@ | ||
import { BaseTransport, initializeFaro, VERSION } from '@grafana/faro-core'; | ||
import type { Patterns, TransportItem } from '@grafana/faro-core'; | ||
import { mockConfig } from '@grafana/faro-core/src/testUtils'; | ||
|
||
import { getIgnoreUrls } from './url'; | ||
|
||
class MockTransport extends BaseTransport { | ||
readonly name = '@grafana/transport-mock'; | ||
readonly version = VERSION; | ||
|
||
items: TransportItem[] = []; | ||
|
||
constructor(private ignoreURLs: Patterns = []) { | ||
super(); | ||
} | ||
|
||
send(items: TransportItem[]): void | Promise<void> { | ||
this.items.push(...items); | ||
} | ||
|
||
override isBatched(): boolean { | ||
return true; | ||
} | ||
|
||
override getIgnoreUrls(): Patterns { | ||
return (this.ignoreURLs ?? ([] as Patterns[])).concat(this.config.ignoreUrls ?? []); | ||
} | ||
} | ||
|
||
describe('Urls', () => { | ||
it('should return the correct ignore urls for the given configuration', () => { | ||
const transport = new MockTransport(['http://foo.com']); | ||
|
||
initializeFaro( | ||
mockConfig({ | ||
transports: [transport], | ||
ignoreUrls: ['http://example.com', 'http://example2.com/test'], | ||
}) | ||
); | ||
|
||
const urls = getIgnoreUrls(); | ||
|
||
expect(urls).toEqual(['http://foo.com', 'http://example.com', 'http://example2.com/test']); | ||
}); | ||
}); |