Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Breadcrumb } from '../src/api/Breadcrumb';
import ErrorCollector from '../src/collectors/error';
import parse, { defaultOptions } from '../src/options';

Expand All @@ -15,14 +16,15 @@ it('handles an empty configuration', () => {
});

it('can set all options at once', () => {
const filter = (breadcrumb: Breadcrumb) => breadcrumb;
const outOptions = parse({
maxPendingEvents: 1,
breadcrumbs: {
maxBreadcrumbs: 1,
click: false,
evaluations: false,
flagChange: false,
filters: [(breadcrumb) => breadcrumb],
filters: [filter],
},
collectors: [new ErrorCollector(), new ErrorCollector()],
});
Expand All @@ -39,7 +41,7 @@ it('can set all options at once', () => {
instrumentFetch: true,
instrumentXhr: true,
},
filters: expect.any(Array),
filters: expect.arrayContaining([filter]),
},
stack: {
source: {
Expand All @@ -50,6 +52,7 @@ it('can set all options at once', () => {
},
collectors: [new ErrorCollector(), new ErrorCollector()],
});
expect(mockLogger.warn).not.toHaveBeenCalled();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure there are never any warnings for fully specified options. This would have prevented this initially.

});

it('warns when maxPendingEvents is not a number', () => {
Expand Down Expand Up @@ -435,6 +438,6 @@ it('warns when filters is not an array', () => {
);
expect(outOptions.breadcrumbs.filters).toEqual([]);
expect(mockLogger.warn).toHaveBeenCalledWith(
'LaunchDarkly - Browser Telemetry: Config option "breadcrumbs.filters" should be of type array, got string, using default value',
'LaunchDarkly - Browser Telemetry: Config option "breadcrumbs.filters" should be of type BreadcrumbFilter[], got string, using default value',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly improved error message.

);
});
12 changes: 7 additions & 5 deletions packages/telemetry/browser-telemetry/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,13 @@ export default function parse(options: Options, logger?: MinLogger): ParsedOptio
checkBasic('boolean', 'breadcrumbs.keyboardInput', logger),
),
http: parseHttp(options.breadcrumbs?.http, defaults.breadcrumbs.http, logger),
filters: itemOrDefault(
options.breadcrumbs?.filters,
defaults.breadcrumbs.filters,
checkBasic('array', 'breadcrumbs.filters', logger),
),
filters: itemOrDefault(options.breadcrumbs?.filters, defaults.breadcrumbs.filters, (item) => {
if (Array.isArray(item)) {
return true;
}
logger?.warn(wrongOptionType('breadcrumbs.filters', 'BreadcrumbFilter[]', typeof item));
return false;
}),
},
stack: parseStack(options.stack, defaults.stack),
maxPendingEvents: itemOrDefault(
Expand Down
Loading