Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow disabling throttling in project monitors #690

Merged
merged 1 commit into from
Jan 10, 2023
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
2 changes: 1 addition & 1 deletion __tests__/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('options', () => {

it('normalize monitor configs', () => {
expect(normalizeOptions({ throttling: false })).toMatchObject({
throttling: {},
throttling: false,
});

expect(
Expand Down
3 changes: 1 addition & 2 deletions src/common_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ type BaseArgs = {
ignoreHttpsErrors?: boolean;
playwrightOptions?: PlaywrightOptions;
quietExitCode?: boolean;
throttling?: ThrottlingOptions;
throttling?: MonitorConfig['throttling'];
schedule?: MonitorConfig['schedule'];
locations?: MonitorConfig['locations'];
privateLocations?: MonitorConfig['privateLocations'];
Expand All @@ -226,7 +226,6 @@ export type CliArgs = BaseArgs & {
richEvents?: boolean;
capability?: Array<string>;
ignoreHttpsErrors?: boolean;
throttling?: boolean | ThrottlingOptions;
};

export type RunOptions = BaseArgs & {
Expand Down
2 changes: 1 addition & 1 deletion src/dsl/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type MonitorConfig = {
enabled?: boolean;
locations?: SyntheticsLocationsType[];
privateLocations?: string[];
throttling?: ThrottlingOptions;
throttling?: boolean | ThrottlingOptions;
screenshot?: ScreenshotOptions;
params?: Params;
playwrightOptions?: PlaywrightOptions;
Expand Down
26 changes: 21 additions & 5 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,24 @@ export function normalizeOptions(cliArgs: CliArgs): RunOptions {
if (cliArgs.throttling) {
const throttleConfig = merge.all([
DEFAULT_THROTTLING_OPTIONS,
monitor?.throttling || {},
cliArgs.throttling as ThrottlingOptions,
toObject(monitor?.throttling),
toObject(cliArgs.throttling),
]);
options.throttling = throttleConfig;
options.networkConditions = getNetworkConditions(throttleConfig);
if (monitor?.throttling !== false) {
options.throttling = throttleConfig;
options.networkConditions = getNetworkConditions(throttleConfig);
} else {
/**
* If the throttling is disabled via Project monitor config, use it a source
* of truth and disable it for pushing those monitors.
*/
options.throttling = false;
}
} else {
/**
* Do not apply throttling when `--no-throttling` flag is passed
*/
options.throttling = {};
options.throttling = false;
}

options.schedule = cliArgs.schedule ?? monitor?.schedule;
Expand All @@ -143,6 +151,14 @@ export function normalizeOptions(cliArgs: CliArgs): RunOptions {
return options;
}

function toObject(value: boolean | Record<string, any>): Record<string, any> {
const defaulVal = {};
if (typeof value === 'boolean') {
return defaulVal;
}
return value || defaulVal;
}

/**
* Parses the throttling CLI settings and also
* adapts to the format to keep the backwards compatability
Expand Down