Skip to content

Commit

Permalink
feat: add testIsolation option and support describe-only overrides (#…
Browse files Browse the repository at this point in the history
…23040)

Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>
Co-authored-by: Bill Glesias <bglesias@gmail.com>
Co-authored-by: Matt Henkes <mjhenkes@gmail.com>
  • Loading branch information
4 people committed Aug 12, 2022
1 parent 6afbfc5 commit 0729a68
Show file tree
Hide file tree
Showing 29 changed files with 1,126 additions and 495 deletions.
7 changes: 7 additions & 0 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2784,6 +2784,13 @@ declare namespace Cypress {
* @default "cypress/support/{e2e|component}.js"
*/
supportFile: string | false
/**
* The test isolation level applied to ensure a clean slate between tests.
* - legacy - resets/clears aliases, intercepts, clock, viewport, cookies, and local storage before each test.
* - strict - applies all resets/clears from legacy, plus clears the page by visiting 'about:blank' to ensure clean app state before each test.
* @default "legacy", however, when experimentalSessionAndOrigin=true, the default is "strict"
*/
testIsolation: 'legacy' | 'strict'
/**
* Path to folder where videos will be saved after a headless or CI run
* @default "cypress/videos"
Expand Down
11 changes: 7 additions & 4 deletions packages/config/__snapshots__/index.spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ exports['config/src/index .getDefaultValues returns list of public config keys 1
"supportFile": "cypress/support/e2e.{js,jsx,ts,tsx}",
"supportFolder": false,
"taskTimeout": 60000,
"testIsolation": "legacy",
"trashAssetsBeforeRuns": true,
"userAgent": null,
"video": true,
Expand All @@ -77,6 +78,7 @@ exports['config/src/index .getDefaultValues returns list of public config keys 1
"viewportWidth": 1000,
"waitForAnimations": true,
"watchForFileChanges": true,
"specPattern": "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}",
"additionalIgnorePattern": [],
"autoOpen": false,
"browsers": [],
Expand Down Expand Up @@ -146,6 +148,7 @@ exports['config/src/index .getDefaultValues returns list of public config keys f
"supportFile": "cypress/support/e2e.{js,jsx,ts,tsx}",
"supportFolder": false,
"taskTimeout": 60000,
"testIsolation": "legacy",
"trashAssetsBeforeRuns": true,
"userAgent": null,
"video": true,
Expand All @@ -156,6 +159,7 @@ exports['config/src/index .getDefaultValues returns list of public config keys f
"viewportWidth": 1000,
"waitForAnimations": true,
"watchForFileChanges": true,
"specPattern": "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}",
"additionalIgnorePattern": [],
"autoOpen": false,
"browsers": [],
Expand All @@ -172,8 +176,7 @@ exports['config/src/index .getDefaultValues returns list of public config keys f
"socketId": null,
"socketIoCookie": "__socket",
"socketIoRoute": "/__socket",
"xhrRoute": "/xhrs/",
"specPattern": "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}"
"xhrRoute": "/xhrs/"
}

exports['config/src/index .getPublicConfigKeys returns list of public config keys 1'] = [
Expand Down Expand Up @@ -221,6 +224,7 @@ exports['config/src/index .getPublicConfigKeys returns list of public config key
"supportFile",
"supportFolder",
"taskTimeout",
"testIsolation",
"trashAssetsBeforeRuns",
"userAgent",
"video",
Expand All @@ -235,6 +239,5 @@ exports['config/src/index .getPublicConfigKeys returns list of public config key
"browsers",
"hosts",
"isInteractive",
"modifyObstructiveCode",
"specPattern"
"modifyObstructiveCode"
]
56 changes: 40 additions & 16 deletions packages/config/src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
import _ from 'lodash'
import Debug from 'debug'
import { defaultSpecPattern, options, breakingOptions, breakingRootOptions, testingTypeBreakingOptions, additionalOptionsToResolveConfig } from './options'
import type { BreakingOption, BreakingOptionErrorKey } from './options'
import {
defaultSpecPattern,
options,
breakingOptions,
breakingRootOptions,
testingTypeBreakingOptions,
} from './options'

import type { TestingType } from '@packages/types'
import type { BreakingOption, BreakingOptionErrorKey, OverrideLevel } from './options'
import type { ErrResult } from './validation'

// this export has to be done in 2 lines because of a bug in babel typescript
import * as validation from './validation'

export {
defaultSpecPattern,
validation,
options,
breakingOptions,
BreakingOption,
BreakingOptionErrorKey,
ErrResult,
validation,
}

const debug = Debug('cypress:config:browser')

const dashesOrUnderscoresRe = /^(_-)+/

// takes an array and creates an index object of [keyKey]: [valueKey]
function createIndex<T extends Record<string, any>> (arr: Array<T>, keyKey: keyof T, valueKey: keyof T) {
function createIndex<T extends Record<string, any>> (arr: Array<T>, keyKey: keyof T, valueKey: keyof T, defaultValueFallback?: any) {
return _.reduce(arr, (memo: Record<string, any>, item) => {
if (item[valueKey] !== undefined) {
memo[item[keyKey] as string] = item[valueKey]
memo[item[keyKey]] = item[valueKey]
} else {
memo[item[keyKey]] = defaultValueFallback
}

return memo
Expand All @@ -33,13 +44,20 @@ function createIndex<T extends Record<string, any>> (arr: Array<T>, keyKey: keyo

const breakingKeys = _.map(breakingOptions, 'name')
const defaultValues = createIndex(options, 'name', 'defaultValue')
const publicConfigKeys = _([...options, ...additionalOptionsToResolveConfig]).reject({ isInternal: true }).map('name').value()
const publicConfigKeys = _(options).reject({ isInternal: true }).map('name').value()
const validationRules = createIndex(options, 'name', 'validation')
const testConfigOverrideOptions = createIndex(options, 'name', 'canUpdateDuringTestTime')

export const testOverrideLevels = createIndex(options, 'name', 'overrideLevel', 'never')

const restartOnChangeOptionsKeys = _.filter(options, 'requireRestartOnChange')

const issuedWarnings = new Set()

export type InvalidTestOverrideResult = {
invalidConfigKey: string
supportedOverrideLevel: string
}

export type BreakingErrResult = {
name: string
newName?: string
Expand Down Expand Up @@ -137,7 +155,7 @@ export const matchesConfigKey = (key: string) => {
return
}

export const validate = (cfg: any, onErr: (property: string) => void) => {
export const validate = (cfg: any, onErr: (property: ErrResult | string) => void) => {
debug('validating configuration')

return _.each(cfg, (value, key) => {
Expand Down Expand Up @@ -172,16 +190,22 @@ export const validateNoBreakingTestingTypeConfig = (cfg: any, testingType: keyof
return validateNoBreakingOptions(options, cfg, onWarning, onErr, testingType)
}

export const validateNoReadOnlyConfig = (config: any, onErr: (property: string) => void) => {
let errProperty
export const validateOverridableAtRunTime = (config: any, isSuiteLevelOverride: boolean, onErr: (result: InvalidTestOverrideResult) => void) => {
Object.keys(config).some((configKey) => {
const overrideLevel: OverrideLevel = testOverrideLevels[configKey]

Object.keys(config).some((option) => {
return errProperty = testConfigOverrideOptions[option] === false ? option : undefined
})
if (!overrideLevel) {
// non-cypress configuration option. skip validation
return
}

if (errProperty) {
return onErr(errProperty)
}
if (overrideLevel === 'never' || (overrideLevel === 'suite' && !isSuiteLevelOverride)) {
onErr({
invalidConfigKey: configKey,
supportedOverrideLevel: overrideLevel,
})
}
})
}

export const validateNeedToRestartOnChange = (cachedConfig: any, updatedConfig: any) => {
Expand Down
Loading

5 comments on commit 0729a68

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0729a68 Aug 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.5.0/linux-x64/develop-0729a6833b100f3fe0b38b2f5bd4a978b61a7e5f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0729a68 Aug 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.5.0/linux-arm64/develop-0729a6833b100f3fe0b38b2f5bd4a978b61a7e5f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0729a68 Aug 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.5.0/darwin-arm64/develop-0729a6833b100f3fe0b38b2f5bd4a978b61a7e5f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0729a68 Aug 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.5.0/darwin-x64/develop-0729a6833b100f3fe0b38b2f5bd4a978b61a7e5f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0729a68 Aug 12, 2022

Choose a reason for hiding this comment

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

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

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.5.0/win32-x64/develop-0729a6833b100f3fe0b38b2f5bd4a978b61a7e5f/cypress.tgz

Please sign in to comment.