From b459aba882a16e64caf2b6d4f9326c875106cdd2 Mon Sep 17 00:00:00 2001 From: Cacie Prins Date: Mon, 23 Oct 2023 13:26:31 -0400 Subject: [PATCH] improve typescript usage when appending experimental retry options to experiments in Experimenets.vue --- .../app/src/settings/project/Experiments.vue | 33 +++++++++++-------- .../src/settings/project/projectSettings.ts | 6 ++-- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/packages/app/src/settings/project/Experiments.vue b/packages/app/src/settings/project/Experiments.vue index b86489197e18..426a78e68375 100644 --- a/packages/app/src/settings/project/Experiments.vue +++ b/packages/app/src/settings/project/Experiments.vue @@ -39,7 +39,7 @@ import SettingsSection from '../SettingsSection.vue' import ExternalLink from '@cy/gql-components/ExternalLink.vue' import type { ExperimentsFragment } from '../../generated/graphql' import { useI18n } from '@cy/i18n' -import type { CypressResolvedConfig } from './projectSettings' +import type { CypressResolvedConfig, CypressConfigEntry } from './projectSettings' const { t } = useI18n() gql` @@ -55,24 +55,31 @@ const props = defineProps<{ const localExperiments = computed(() => { // get experiments out of the config - const experimentalConfigurations = props.gql?.config ? (props.gql.config as CypressResolvedConfig).filter((item) => item.field.startsWith('experimental')) : [] + const cfg = (props.gql?.config || []) as CypressResolvedConfig + + const experimentalConfigurations = cfg.filter((item) => item.field.startsWith('experimental')) // get experimental retry properties on the 'retries' config object. Mutate the experimentalConfigurations array as to not have side effects with props.gql.config // TODO: remove this once experimentalRetries becomes GA. This is to be treated as a one off as supported nested experiments inside config is rare. - const { value: { experimentalStrategy, experimentalOptions, from } } = props.gql?.config.find((item) => item.field === 'retries') + // const { value: { experimentalStrategy, experimentalOptions, from } } + const retryConfig = cfg.find((item) => item.field === 'retries') - experimentalConfigurations.push({ - field: 'retries.experimentalStrategy', - from, - value: experimentalStrategy, - }) + if (retryConfig) { + const { value: { experimentalStrategy, experimentalOptions, from } } = retryConfig as CypressConfigEntry & { value: Record } - experimentalConfigurations.push({ - field: 'retries.experimentalOptions', - from, - value: experimentalOptions, - }) + experimentalConfigurations.push({ + field: 'retries.experimentalStrategy', + from, + value: experimentalStrategy, + }) + + experimentalConfigurations.push({ + field: 'retries.experimentalOptions', + from, + value: experimentalOptions, + }) // end TODO removal + } return experimentalConfigurations.map((configItem) => { return { diff --git a/packages/app/src/settings/project/projectSettings.ts b/packages/app/src/settings/project/projectSettings.ts index 317d5cc33bc7..18cd7e4935c5 100644 --- a/packages/app/src/settings/project/projectSettings.ts +++ b/packages/app/src/settings/project/projectSettings.ts @@ -15,8 +15,10 @@ export interface Experiment { key: string } -export type CypressResolvedConfig = Array<{ +export type CypressConfigEntry = { field: string from: 'default'| 'config' | 'plugin' | 'env' value: string | number | boolean | Record | Array -}> +} + +export type CypressResolvedConfig = Array