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

feat: add testIsolation option and support describe-only overrides #23040

Merged
merged 46 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
28380a5
feat: add testIsolation config option and add support for varying con…
emilyrohrbough Jul 29, 2022
8677ec7
clean up based on tests
emilyrohrbough Jul 29, 2022
174b50c
fix unit tests & types
emilyrohrbough Jul 29, 2022
3ca878d
system tests
emilyrohrbough Jul 29, 2022
819f71f
and fix
emilyrohrbough Jul 29, 2022
41fb01b
fix tests & align runTime with runtime value passed to the dashboard
emilyrohrbough Jul 31, 2022
6226550
fix snapshots
emilyrohrbough Aug 1, 2022
7b62033
add types
emilyrohrbough Aug 1, 2022
68fd5b1
Merge branch 'develop' into test-isolation-config-opt-2
emilyrohrbough Aug 1, 2022
15ec8d8
fix
emilyrohrbough Aug 1, 2022
dec1da8
Update cli/types/cypress.d.ts
emilyrohrbough Aug 2, 2022
9de9028
Merge branch 'develop' into test-isolation-config-opt-2
emilyrohrbough Aug 3, 2022
191105b
typescript changes per lachlan's review
emilyrohrbough Aug 3, 2022
92d5bc8
change testIsolation's defaultValue from default to legacy
emilyrohrbough Aug 3, 2022
fd510a9
add issues in comments and update missed default->legacy changes
emilyrohrbough Aug 3, 2022
fe3bcca
Merge branch 'develop' into test-isolation-config-opt-2
emilyrohrbough Aug 8, 2022
d0c1a0d
add missing todo
emilyrohrbough Aug 8, 2022
9848dab
break out driver config validation
emilyrohrbough Aug 8, 2022
840d2bc
whoops. fix types
emilyrohrbough Aug 8, 2022
88aa9e5
reduce specificity of event override levels
emilyrohrbough Aug 8, 2022
2c47a14
legacy -> lax
emilyrohrbough Aug 8, 2022
16125cd
nit
emilyrohrbough Aug 8, 2022
c8cd668
fix
emilyrohrbough Aug 8, 2022
c036d64
Merge branch 'develop' into test-isolation-config-opt-2
emilyrohrbough Aug 8, 2022
66c5c16
Merge branch 'develop' into test-isolation-config-opt-2
emilyrohrbough Aug 9, 2022
86f4e62
Update packages/server/test/unit/config_spec.js
emilyrohrbough Aug 10, 2022
06766ab
Update packages/server/lib/config.ts
emilyrohrbough Aug 10, 2022
5c48123
Update packages/server/test/unit/config_spec.js
emilyrohrbough Aug 10, 2022
d823396
Merge branch 'develop' into test-isolation-config-opt-2
emilyrohrbough Aug 11, 2022
7005a0e
remove err workarounds that were fixed in https://github.com/cypress…
emilyrohrbough Aug 11, 2022
f60dd05
Merge branch 'test-isolation-config-opt-2' of https://github.com/cypr…
emilyrohrbough Aug 11, 2022
9bfc380
Update packages/driver/cypress/e2e/util/config.cy.js
emilyrohrbough Aug 11, 2022
e3e5dde
Update packages/config/src/options.ts
emilyrohrbough Aug 11, 2022
aa97c9a
Update packages/driver/cypress/e2e/commands/sessions/sessions.cy.js
emilyrohrbough Aug 11, 2022
8446984
fix failing test
emilyrohrbough Aug 11, 2022
3248797
fix snapshot
emilyrohrbough Aug 11, 2022
073de5a
overruled....changing lax back to legacy
emilyrohrbough Aug 11, 2022
623ef3b
Merge branch 'develop' into test-isolation-config-opt-2
emilyrohrbough Aug 11, 2022
28a7140
fix
emilyrohrbough Aug 11, 2022
fb14105
Merge branch 'test-isolation-config-opt-2' of https://github.com/cypr…
emilyrohrbough Aug 11, 2022
2b94621
change code -> fileLoad
emilyrohrbough Aug 11, 2022
586ca74
okayyyy another round of feedback applied
emilyrohrbough Aug 11, 2022
9449f40
Update cli/types/cypress.d.ts
emilyrohrbough Aug 12, 2022
368ff71
Merge branch 'develop' into test-isolation-config-opt-2
emilyrohrbough Aug 12, 2022
f34fdb3
Update packages/server/lib/util/spec_writer.ts
emilyrohrbough Aug 12, 2022
2291a29
Merge branch 'develop' into test-isolation-config-opt-2
emilyrohrbough Aug 12, 2022
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
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.
mjhenkes marked this conversation as resolved.
Show resolved Hide resolved
* - 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