Skip to content

Commit

Permalink
Merge branch 'develop' into 10.0-release
Browse files Browse the repository at this point in the history
* develop:
  chore(deps): update dependency ssri to 6.0.2 [security] (#19351)
  chore: Fix server unit tests running on mac by using actual tmp dir (#19350)
  fix: Add more precise types to Cypress.Commands (#19003)
  fix: Do not screenshot or trigger the failed event when tests are skipped (#19331)
  fix (#19262)
  fix: throw when writing to 'read only' properties of `config` (#18896)
  fix: close chrome when closing electron (#19322)
  fix: disable automatic request retries (#19161)
  chore: refactor cy funcs (#19080)
  chore(deps): update dependency @ffmpeg-installer/ffmpeg to v1.1.0 🌟 (#19300)
  • Loading branch information
tgriesser committed Dec 15, 2021
2 parents dc88b28 + 52dfe1e commit 223d5fa
Show file tree
Hide file tree
Showing 48 changed files with 1,723 additions and 1,387 deletions.
52 changes: 45 additions & 7 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,38 @@ declare namespace Cypress {
type HttpMethod = string
type RequestBody = string | object
type ViewportOrientation = 'portrait' | 'landscape'
type PrevSubject = 'optional' | 'element' | 'document' | 'window'
type PrevSubject = keyof PrevSubjectMap
type TestingType = 'e2e' | 'component'
type PluginConfig = (on: PluginEvents, config: PluginConfigOptions) => void | ConfigOptions | Promise<ConfigOptions>

interface PrevSubjectMap<O = unknown> {
optional: O
element: JQuery
document: Document
window: Window
}

interface CommandOptions {
prevSubject: boolean | PrevSubject | PrevSubject[]
}
interface CommandFn<T extends keyof ChainableMethods> {
(this: Mocha.Context, ...args: Parameters<ChainableMethods[T]>): ReturnType<ChainableMethods[T]> | void
}
interface CommandFnWithSubject<T extends keyof ChainableMethods, S> {
(this: Mocha.Context, prevSubject: S, ...args: Parameters<ChainableMethods[T]>): ReturnType<ChainableMethods[T]> | void
}
interface CommandOriginalFn<T extends keyof ChainableMethods> extends CallableFunction {
(...args: Parameters<ChainableMethods[T]>): ReturnType<ChainableMethods[T]>
}
interface CommandOriginalFnWithSubject<T extends keyof ChainableMethods, S> extends CallableFunction {
(prevSubject: S, ...args: Parameters<ChainableMethods[T]>): ReturnType<ChainableMethods[T]>
}
interface CommandFnWithOriginalFn<T extends keyof Chainable> {
(this: Mocha.Context, originalFn: CommandOriginalFn<T>, ...args: Parameters<ChainableMethods[T]>): ReturnType<ChainableMethods[T]> | void
}
interface CommandFnWithOriginalFnAndSubject<T extends keyof Chainable, S> {
(this: Mocha.Context, originalFn: CommandOriginalFnWithSubject<T, S>, prevSubject: S, ...args: Parameters<ChainableMethods[T]>): ReturnType<ChainableMethods[T]> | void
}
interface ObjectLike {
[key: string]: any
}
Expand Down Expand Up @@ -328,7 +353,7 @@ declare namespace Cypress {
// 60000
```
*/
config<K extends keyof ConfigOptions>(key: K): ResolvedConfigOptions[K]
config<K extends keyof Config>(key: K): Config[K]
/**
* Sets one configuration value.
* @see https://on.cypress.io/config
Expand All @@ -337,7 +362,7 @@ declare namespace Cypress {
Cypress.config('viewportWidth', 800)
```
*/
config<K extends keyof ConfigOptions>(key: K, value: ResolvedConfigOptions[K]): void
config<K extends keyof TestConfigOverrides>(key: K, value: TestConfigOverrides[K]): void
/**
* Sets multiple configuration values at once.
* @see https://on.cypress.io/config
Expand Down Expand Up @@ -420,9 +445,16 @@ declare namespace Cypress {
* @see https://on.cypress.io/api/commands
*/
Commands: {
add<T extends keyof Chainable>(name: T, fn: Chainable[T]): void
add<T extends keyof Chainable>(name: T, options: CommandOptions, fn: Chainable[T]): void
overwrite<T extends keyof Chainable>(name: T, fn: Chainable[T]): void
add<T extends keyof Chainable>(name: T, fn: CommandFn<T>): void
add<T extends keyof Chainable>(name: T, options: CommandOptions & {prevSubject: false}, fn: CommandFn<T>): void
add<T extends keyof Chainable, S extends PrevSubject>(
name: T, options: CommandOptions & { prevSubject: true | S | ['optional'] }, fn: CommandFnWithSubject<T, PrevSubjectMap[S]>,
): void
add<T extends keyof Chainable, S extends PrevSubject>(
name: T, options: CommandOptions & { prevSubject: S[] }, fn: CommandFnWithSubject<T, PrevSubjectMap<void>[S]>,
): void
overwrite<T extends keyof Chainable>(name: T, fn: CommandFnWithOriginalFn<T>): void
overwrite<T extends keyof Chainable, S extends PrevSubject>(name: T, fn: CommandFnWithOriginalFnAndSubject<T, PrevSubjectMap[S]>): void
}

/**
Expand Down Expand Up @@ -2248,6 +2280,12 @@ declare namespace Cypress {
$$<TElement extends Element = HTMLElement>(selector: JQuery.Selector, context?: Element | Document | JQuery): JQuery<TElement>
}

type ChainableMethods<Subject = any> = {
[P in keyof Chainable<Subject>]: Chainable<Subject>[P] extends ((...args: any[]) => any)
? Chainable<Subject>[P]
: never
}

interface SinonSpyAgent<A extends sinon.SinonSpy> {
log(shouldOutput?: boolean): Omit<A, 'withArgs'> & Agent<A>

Expand Down Expand Up @@ -2884,7 +2922,7 @@ declare namespace Cypress {
xhrUrl: string
}

interface TestConfigOverrides extends Partial<Pick<ConfigOptions, 'animationDistanceThreshold' | 'baseUrl' | 'defaultCommandTimeout' | 'env' | 'execTimeout' | 'includeShadowDom' | 'requestTimeout' | 'responseTimeout' | 'retries' | 'scrollBehavior' | 'taskTimeout' | 'viewportHeight' | 'viewportWidth' | 'waitForAnimations'>> {
interface TestConfigOverrides extends Partial<Pick<ConfigOptions, 'animationDistanceThreshold' | 'baseUrl' | 'blockHosts' | 'defaultCommandTimeout' | 'env' | 'execTimeout' | 'includeShadowDom' | 'numTestsKeptInMemory' | 'pageLoadTimeout' | 'redirectionLimit' | 'requestTimeout' | 'responseTimeout' | 'retries' | 'screenshotOnRunFailure' | 'slowTestThreshold' | 'scrollBehavior' | 'taskTimeout' | 'viewportHeight' | 'viewportWidth' | 'waitForAnimations'>> {
browser?: IsBrowserMatcher | IsBrowserMatcher[]
keystrokeDelay?: number
}
Expand Down
102 changes: 94 additions & 8 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace CypressIsCyTests {

declare namespace Cypress {
interface Chainable {
newCommand: (arg: string) => void
newCommand: (arg: string) => Chainable<number>
}
}

Expand All @@ -74,20 +74,106 @@ namespace CypressCommandsTests {
arg
return
})
Cypress.Commands.add('newCommand', { prevSubject: true }, (arg) => {
Cypress.Commands.add('newCommand', (arg) => {
// $ExpectType string
arg
})
Cypress.Commands.add('newCommand', function(arg) {
this // $ExpectType Context
arg // $ExpectType string
})
Cypress.Commands.add('newCommand', { prevSubject: true }, (subject, arg) => {
subject // $ExpectType unknown
arg // $ExpectType string
return
})
Cypress.Commands.add('newCommand', (arg) => {
// $ExpectType string
arg
return new Promise((resolve) => {})
Cypress.Commands.add('newCommand', { prevSubject: false }, (arg) => {
arg // $ExpectType string
return
})
Cypress.Commands.add('newCommand', { prevSubject: 'optional' }, (subject, arg) => {
subject // $ExpectType unknown
arg // $ExpectType string
return
})
Cypress.Commands.overwrite('newCommand', (arg) => {
Cypress.Commands.add('newCommand', { prevSubject: 'optional' }, (subject, arg) => {
subject // $ExpectType unknown
arg // $ExpectType string
})
Cypress.Commands.add('newCommand', { prevSubject: ['optional'] }, (subject, arg) => {
subject // $ExpectType unknown
arg // $ExpectType string
})
Cypress.Commands.add('newCommand', { prevSubject: 'document' }, (subject, arg) => {
subject // $ExpectType Document
arg // $ExpectType string
})
Cypress.Commands.add('newCommand', { prevSubject: 'window' }, (subject, arg) => {
subject // $ExpectType Window
arg // $ExpectType string
})
Cypress.Commands.add('newCommand', { prevSubject: 'element' }, (subject, arg) => {
subject // $ExpectType JQuery<HTMLElement>
arg // $ExpectType string
})
Cypress.Commands.add('newCommand', { prevSubject: ['element'] }, (subject, arg) => {
subject // $ExpectType JQuery<HTMLElement>
arg // $ExpectType string
})
Cypress.Commands.add('newCommand', { prevSubject: ['element', 'document', 'window'] }, (subject, arg) => {
if (subject instanceof Window) {
subject // $ExpectType Window
} else if (subject instanceof Document) {
subject // $ExpectType Document
} else {
subject // $ExpectType JQuery<HTMLElement>
}
arg // $ExpectType string
})
Cypress.Commands.add('newCommand', { prevSubject: ['window', 'document', 'optional', 'element'] }, (subject, arg) => {
if (subject instanceof Window) {
subject // $ExpectType Window
} else if (subject instanceof Document) {
subject // $ExpectType Document
} else if (subject) {
subject // $ExpectType JQuery<HTMLElement>
} else {
subject // $ExpectType void
}
arg // $ExpectType string
})
Cypress.Commands.add('newCommand', (arg) => {
// $ExpectType string
arg
return
return cy.wrap(new Promise<number>((resolve) => { resolve(5) }))
})
Cypress.Commands.overwrite('newCommand', (originalFn, arg) => {
arg // $ExpectType string
originalFn // $ExpectedType Chainable['newCommand']
originalFn(arg) // $ExpectType Chainable<number>
})
Cypress.Commands.overwrite('newCommand', function(originalFn, arg) {
this // $ExpectType Context
arg // $ExpectType string
originalFn // $ExpectedType Chainable['newCommand']
originalFn.apply(this, [arg]) // $ExpectType Chainable<number>
})
Cypress.Commands.overwrite<'type', 'element'>('type', (originalFn, element, text, options?: Partial<Cypress.TypeOptions & {sensitive: boolean}>) => {
element // $ExpectType JQuery<HTMLElement>
text // $ExpectType string

if (options && options.sensitive) {
// turn off original log
options.log = false
// create our own log with masked message
Cypress.log({
$el: element,
name: 'type',
message: '*'.repeat(text.length),
})
}

return originalFn(element, text, options)
})
}

Expand Down
6 changes: 6 additions & 0 deletions packages/config/__snapshots__/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports['src/index .getDefaultValues returns list of public config keys 1'] = {
"e2e": {},
"env": {},
"execTimeout": 60000,
"exit": true,
"experimentalFetchPolyfill": false,
"experimentalInteractiveRunEvents": false,
"experimentalSessionSupport": false,
Expand All @@ -33,6 +34,8 @@ exports['src/index .getDefaultValues returns list of public config keys 1'] = {
"ignoreTestFiles": "*.hot-update.js",
"includeShadowDom": false,
"integrationFolder": "cypress/integration",
"isInteractive": true,
"keystrokeDelay": 0,
"modifyObstructiveCode": true,
"numTestsKeptInMemory": 50,
"pageLoadTimeout": 60000,
Expand Down Expand Up @@ -97,6 +100,7 @@ exports['src/index .getPublicConfigKeys returns list of public config keys 1'] =
"e2e",
"env",
"execTimeout",
"exit",
"experimentalFetchPolyfill",
"experimentalInteractiveRunEvents",
"experimentalSessionSupport",
Expand All @@ -107,6 +111,7 @@ exports['src/index .getPublicConfigKeys returns list of public config keys 1'] =
"ignoreTestFiles",
"includeShadowDom",
"integrationFolder",
"keystrokeDelay",
"modifyObstructiveCode",
"nodeVersion",
"numTestsKeptInMemory",
Expand Down Expand Up @@ -142,5 +147,6 @@ exports['src/index .getPublicConfigKeys returns list of public config keys 1'] =
"watchForFileChanges",
"browsers",
"hosts",
"isInteractive",
"modifyObstructiveCode"
]
2 changes: 1 addition & 1 deletion packages/config/__snapshots__/validation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ Expected \`mockConfigKey\` to be a fully qualified URL (starting with \`http://\

exports['empty string'] = `
Expected \`mockConfigKey\` to be a fully qualified URL (starting with \`http://\` or \`https://\`). Instead the value was: \`""\`
`
`
13 changes: 13 additions & 0 deletions packages/config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const breakingKeys = _.map(breakingOptions, 'name')
const defaultValues = createIndex(options, 'name', 'defaultValue')
const publicConfigKeys = _(options).reject({ isInternal: true }).map('name').value()
const validationRules = createIndex(options, 'name', 'validation')
const testConfigOverrideOptions = createIndex(options, 'name', 'canUpdateDuringTestTime')

module.exports = {
allowed: (obj = {}) => {
Expand Down Expand Up @@ -101,4 +102,16 @@ module.exports = {
}
})
},

validateNoReadOnlyConfig: (config, onErr) => {
let errProperty

Object.keys(config).some((option) => {
return errProperty = testConfigOverrideOptions[option] === false ? option : undefined
})

if (errProperty) {
return onErr(errProperty)
}
},
}
Loading

0 comments on commit 223d5fa

Please sign in to comment.