Skip to content

Commit

Permalink
feat: add new experimental retries configuration (#27412)
Browse files Browse the repository at this point in the history
* feat: implement the experimental retries configuration options to pair
with test burn in

* [run ci]
  • Loading branch information
AtofStryker authored Aug 1, 2023
1 parent c428443 commit ef84f03
Show file tree
Hide file tree
Showing 11 changed files with 817 additions and 26 deletions.
26 changes: 25 additions & 1 deletion cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2838,6 +2838,30 @@ declare namespace Cypress {
certs: PEMCert[] | PFXCert[]
}

type RetryStrategyWithModeSpecs = RetryStrategy & {
openMode: boolean; // defaults to false
runMode: boolean; // defaults to true
}

type RetryStrategy =
| RetryStrategyDetectFlakeAndPassOnThresholdType
| RetryStrategyDetectFlakeButAlwaysFailType

interface RetryStrategyDetectFlakeAndPassOnThresholdType {
experimentalStrategy: "detect-flake-and-pass-on-threshold"
experimentalOptions?: {
maxRetries: number; // defaults to 2 if experimentalOptions is not provided, must be a whole number > 0
passesRequired: number; // defaults to 2 if experimentalOptions is not provided, must be a whole number > 0 and <= maxRetries
}
}

interface RetryStrategyDetectFlakeButAlwaysFailType {
experimentalStrategy: "detect-flake-but-always-fail"
experimentalOptions?: {
maxRetries: number; // defaults to 2 if experimentalOptions is not provided, must be a whole number > 0
stopIfAnyPassed: boolean; // defaults to false if experimentalOptions is not provided
}
}
interface ResolvedConfigOptions<ComponentDevServerOpts = any> {
/**
* Url used as prefix for [cy.visit()](https://on.cypress.io/visit) or [cy.request()](https://on.cypress.io/request) command's url
Expand Down Expand Up @@ -3131,7 +3155,7 @@ declare namespace Cypress {
* To enable test retries only in runMode, set e.g. `{ openMode: null, runMode: 2 }`
* @default null
*/
retries: Nullable<number | { runMode?: Nullable<number>, openMode?: Nullable<number> }>
retries: Nullable<number | ({ runMode?: Nullable<number>, openMode?: Nullable<number> }) | RetryStrategyWithModeSpecs>
/**
* Enables including elements within the shadow DOM when using querying
* commands (e.g. cy.get(), cy.find()). Can be set globally in cypress.config.{js,ts,mjs,cjs},
Expand Down
33 changes: 33 additions & 0 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,39 @@ namespace CypressLocalStorageTests {
cy.clearAllSessionStorage({ log: 'true' }) // $ExpectError
}

namespace CypressRetriesSpec {
Cypress.config('retries', {
openMode: 0,
runMode: 1
})

Cypress.config('retries', {
openMode: false,
runMode: false,
experimentalStrategy: "detect-flake-and-pass-on-threshold",
experimentalOptions: {
maxRetries: 2,
passesRequired: 2
}
})

Cypress.config('retries', {
openMode: false,
runMode: false,
experimentalStrategy: "detect-flake-but-always-fail",
experimentalOptions: {
maxRetries: 2,
stopIfAnyPassed: true
}
})

Cypress.config('retries', { openMode: false, runMode: true, experimentalStrategy: "detect-flake-and-pass-on-threshold", experimentalOptions: { maxRetries: 2} }) // $ExpectError
Cypress.config('retries', { openMode: false, runMode: true, experimentalStrategy: "detect-flake-but-always-fail", experimentalOptions: { maxRetries: 2} }) // $ExpectError

Cypress.config('retries', { openMode: false, runMode: true, experimentalStrategy: "detect-flake-and-pass-on-threshold", experimentalOptions: { passesRequired: 2} }) // $ExpectError
Cypress.config('retries', { openMode: false, runMode: true, experimentalStrategy: "detect-flake-but-always-fail", experimentalOptions: { stopIfAnyPassed: true} }) // $ExpectError
}

namespace CypressTraversalTests {
cy.wrap({}).prevUntil('a') // $ExpectType Chainable<JQuery<HTMLAnchorElement>>
cy.wrap({}).prevUntil('#myItem') // $ExpectType Chainable<JQuery<HTMLElement>>
Expand Down
24 changes: 22 additions & 2 deletions packages/app/src/settings/project/Experiments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,33 @@ const props = defineProps<{
}>()
const localExperiments = computed(() => {
return props.gql?.config ? (props.gql.config as CypressResolvedConfig).filter((item) => item.field.startsWith('experimental')).map((configItem) => {
// get experiments out of the config
const experimentalConfigurations = props.gql?.config ? (props.gql.config as CypressResolvedConfig).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')
experimentalConfigurations.push({
field: 'retries.experimentalStrategy',
from,
value: experimentalStrategy,
})
experimentalConfigurations.push({
field: 'retries.experimentalOptions',
from,
value: experimentalOptions,
})
// end TODO removal
return experimentalConfigurations.map((configItem) => {
return {
key: configItem.field,
name: t(`settingsPage.experiments.${configItem.field}.name`),
enabled: !!configItem.value,
description: t(`settingsPage.experiments.${configItem.field}.description`),
}
}) : []
})
})
</script>
Loading

4 comments on commit ef84f03

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ef84f03 Aug 1, 2023

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.17.2/linux-arm64/feature/test-burn-in-ef84f03585a870d68e7ed2a9222f0468cfed03a9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ef84f03 Aug 1, 2023

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.17.2/linux-x64/feature/test-burn-in-ef84f03585a870d68e7ed2a9222f0468cfed03a9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ef84f03 Aug 1, 2023

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.17.2/darwin-x64/feature/test-burn-in-ef84f03585a870d68e7ed2a9222f0468cfed03a9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ef84f03 Aug 1, 2023

Choose a reason for hiding this comment

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

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.17.2/darwin-arm64/feature/test-burn-in-ef84f03585a870d68e7ed2a9222f0468cfed03a9/cypress.tgz

Please sign in to comment.