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

fix(driver): cy.pause() should not be ignored with cypress run --headed --no-exit #18358

Merged
merged 17 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
27 changes: 27 additions & 0 deletions packages/driver/cypress/integration/commands/debugging_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,32 @@ describe('src/cy/commands/debugging', () => {
expect(cy.state('onPaused')).to.be.null
})
})

it('can pause in run mode with --headed and --no-exit', function () {
let didPause = false

Cypress.config('isInteractive', false)
Cypress.config('browser').isHeaded = true
Cypress.config('exit', false)

cy.once('paused', (name) => {
cy.once('paused', (name) => {
didPause = true

// resume the rest of the commands so this
// test ends
Cypress.emit('resume:all')
})

Cypress.emit('resume:next')
})

cy.pause().wrap({}).should('deep.eq', {}).then(function () {
expect(didPause).to.be.true

// should no longer have onPaused
expect(cy.state('onPaused')).to.be.null
})
})
})
})
4 changes: 2 additions & 2 deletions packages/driver/src/cy/commands/debugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default (Commands, Cypress, cy, state, config) => {
// pause should indefinitely pause until the user
// presses a key or clicks in the UI to continue
pause (subject, options = {}) {
// bail if we're headless
if (!config('isInteractive')) {
// bail if we're in run mode, unless --headed and --no-exit flags are passed
if (!config('isInteractive') && (!config('browser').isHeaded || config('exit'))) {
return subject
}

Expand Down
5 changes: 3 additions & 2 deletions packages/server/lib/controllers/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const _serveNonProxiedError = (res: Response) => {
})
}

export interface ServeOptions extends Pick<InitializeRoutes, 'getSpec' | 'config' | 'getCurrentBrowser' | 'getRemoteState' | 'specsStore'> {
export interface ServeOptions extends Pick<InitializeRoutes, 'getSpec' | 'config' | 'getCurrentBrowser' | 'getRemoteState' | 'specsStore' | 'exit'> {
testingType: Cypress.TestingType
}

Expand All @@ -47,7 +47,7 @@ export const runner = {
return _serveNonProxiedError(res)
}

let { config, getRemoteState, getCurrentBrowser, getSpec, specsStore } = options
let { config, getRemoteState, getCurrentBrowser, getSpec, specsStore, exit } = options

config = _.clone(config)
// at any given point, rather than just arbitrarily modifying it.
Expand All @@ -72,6 +72,7 @@ export const runner = {
config.spec = getSpec() ?? null
config.specs = specsStore.specFiles
config.browser = getCurrentBrowser()
config.exit = exit

debug('serving runner index.html with config %o',
_.pick(config, 'version', 'platform', 'arch', 'projectName'))
Expand Down
1 change: 1 addition & 0 deletions packages/server/lib/open_project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface LaunchArgs {
cwd: string
browser?: Browser['name']
configFile?: string
exit?: boolean
project: string // projectRoot
projectRoot: string // same as above
testingType: Cypress.TestingType
Expand Down
2 changes: 2 additions & 0 deletions packages/server/lib/project-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ReceivedCypressOptions =
export interface Cfg extends ReceivedCypressOptions {
projectRoot: string
proxyServer?: Cypress.RuntimeConfigOptions['proxyUrl']
exit?: boolean
state?: {
firstOpened?: number
lastOpened?: number
Expand Down Expand Up @@ -213,6 +214,7 @@ export class ProjectBase<TServer extends ServerE2E | ServerCt> extends EE {
const [port, warning] = await this._server.open(cfg, {
getCurrentBrowser: () => this.browser,
getSpec: () => this.spec,
exit: this.options.args?.exit,
onError: this.options.onError,
onWarning: this.options.onWarning,
shouldCorrelatePreRequests: this.shouldCorrelatePreRequests,
Expand Down
3 changes: 3 additions & 0 deletions packages/server/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface InitializeRoutes {
getRemoteState: () => Cypress.RemoteState
onError: (...args: unknown[]) => any
testingType: Cypress.TestingType
exit?: boolean
}

export const createCommonRoutes = ({
Expand All @@ -33,6 +34,7 @@ export const createCommonRoutes = ({
specsStore,
getRemoteState,
nodeProxy,
exit,
}: InitializeRoutes) => {
const router = Router()

Expand Down Expand Up @@ -70,6 +72,7 @@ export const createCommonRoutes = ({
getCurrentBrowser,
getRemoteState,
specsStore,
exit,
})
})

Expand Down
3 changes: 3 additions & 0 deletions packages/server/lib/server-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface OpenServerOptions {
testingType: Cypress.TestingType
onError: any
onWarning: any
exit?: boolean
getCurrentBrowser: () => Browser
getSpec: () => Cypress.Cypress['spec'] | null
shouldCorrelatePreRequests: () => boolean
Expand Down Expand Up @@ -177,6 +178,7 @@ export abstract class ServerBase<TSocket extends SocketE2E | SocketCt> {
specsStore,
testingType,
SocketCtor,
exit,
}: OpenServerOptions) {
debug('server open')

Expand Down Expand Up @@ -221,6 +223,7 @@ export abstract class ServerBase<TSocket extends SocketE2E | SocketCt> {
getSpec,
getCurrentBrowser,
testingType,
exit,
}

const runnerSpecificRouter = testingType === 'e2e'
Expand Down