Skip to content

Commit

Permalink
fix(driver): cy.pause() should not be ignored with `cypress run --h…
Browse files Browse the repository at this point in the history
…eaded --no-exit` (#18358)
  • Loading branch information
davidmunechika committed Oct 8, 2021
1 parent 32464f3 commit 1d08280
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 4 deletions.
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 ?? true

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
16 changes: 16 additions & 0 deletions packages/server/test/integration/http_requests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe('Routes', () => {
specsStore: new SpecsStore({}, 'e2e'),
createRoutes,
testingType: 'e2e',
exit: false,
})
.spread(async (port) => {
const automationStub = {
Expand Down Expand Up @@ -377,6 +378,21 @@ describe('Routes', () => {
})
})
})

it('sends exit config', function () {
return this.setup({ baseUrl: 'http://localhost:9999/app' })
.then(() => {
return this.rp('http://localhost:9999/__')
.then((res) => {
expect(res.statusCode).to.eq(200)

const base64Config = /Runner\.start\(.*, "(.*)"\)/.exec(res.body)[1]
const configStr = Buffer.from(base64Config, 'base64').toString()

expect(configStr).to.include('"exit":false')
})
})
})
})

context('GET /__cypress/runner/*', () => {
Expand Down

4 comments on commit 1d08280

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1d08280 Oct 8, 2021

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/8.6.0/circle-develop-1d08280f4a85fc9eaf9326c88c2ea0e6d9d099d7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1d08280 Oct 8, 2021

Choose a reason for hiding this comment

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

AppVeyor has built the win32 ia32 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/8.6.0/appveyor-develop-1d08280f4a85fc9eaf9326c88c2ea0e6d9d099d7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1d08280 Oct 8, 2021

Choose a reason for hiding this comment

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

AppVeyor 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/8.6.0/appveyor-develop-1d08280f4a85fc9eaf9326c88c2ea0e6d9d099d7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1d08280 Oct 8, 2021

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/8.6.0/circle-develop-1d08280f4a85fc9eaf9326c88c2ea0e6d9d099d7/cypress.tgz

Please sign in to comment.