Skip to content

Commit

Permalink
Merge branch 'develop' into feature-multidomain
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhenkes committed Mar 30, 2022
2 parents 9098744 + 085add5 commit 1fa78f5
Show file tree
Hide file tree
Showing 9 changed files with 516 additions and 2,324 deletions.
2 changes: 1 addition & 1 deletion browser-versions.json
@@ -1,4 +1,4 @@
{
"chrome:beta": "100.0.4896.60",
"chrome:stable": "99.0.4844.84"
"chrome:stable": "100.0.4896.60"
}
10 changes: 10 additions & 0 deletions packages/driver/cypress/integration/commands/querying/root_spec.js
Expand Up @@ -35,6 +35,16 @@ describe('src/cy/commands/querying', () => {
cy.root().should('have.class', 'foo').and('have.class', 'bar')
})

// https://github.com/cypress-io/cypress/issues/19985
it('respects timeout option', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.not.contain('4000ms')
done()
})

cy.root({ timeout: 50 }).should('contain', 'root world')
})

describe('.log', () => {
beforeEach(function () {
this.logs = []
Expand Down
5 changes: 4 additions & 1 deletion packages/driver/src/cy/commands/querying/root.ts
Expand Up @@ -29,7 +29,10 @@ export default (Commands, Cypress, cy, state) => {
return log(withinSubject)
}

return cy.now('get', 'html', { log: false }).then(log)
return cy.now('get', 'html', {
log: false,
timeout: options.timeout,
}).then(log)
},
})
}
19 changes: 11 additions & 8 deletions packages/server/lib/browsers/cdp_automation.ts
Expand Up @@ -163,7 +163,7 @@ const normalizeResourceType = (resourceType: string | undefined): ResourceType =
return ffToStandardResourceTypeMap[resourceType] || 'other'
}

type SendDebuggerCommand = (message: string, data?: any) => Bluebird<any>
type SendDebuggerCommand = (message: string, data?: any) => Promise<any>
type OnFn = (eventName: string, cb: Function) => void

// the intersection of what's valid in CDP and what's valid in FFCDP
Expand Down Expand Up @@ -250,7 +250,7 @@ export class CdpAutomation {
})
}

private getCookiesByUrl = (url): Bluebird<CyCookie[]> => {
private getCookiesByUrl = (url): Promise<CyCookie[]> => {
return this.sendDebuggerCommandFn('Network.getCookies', {
urls: [url],
})
Expand All @@ -277,7 +277,7 @@ export class CdpAutomation {
})
}

private getCookie = (filter: CyCookieFilter): Bluebird<CyCookie | null> => {
private getCookie = (filter: CyCookieFilter): Promise<CyCookie | null> => {
return this.getAllCookies(filter)
.then((cookies) => {
return _.get(cookies, 0, null)
Expand Down Expand Up @@ -320,15 +320,18 @@ export class CdpAutomation {

case 'clear:cookie':
return this.getCookie(data)
// tap, so we can resolve with the value of the removed cookie
// also, getting the cookie via CDP first will ensure that we send a cookie `domain` to CDP
// that matches the cookie domain that is really stored
.tap((cookieToBeCleared) => {
// always resolve with the value of the removed cookie. also, getting
// the cookie via CDP first will ensure that we send a cookie `domain`
// to CDP that matches the cookie domain that is really stored
.then((cookieToBeCleared) => {
if (!cookieToBeCleared) {
return
return cookieToBeCleared
}

return this.sendDebuggerCommandFn('Network.deleteCookies', _.pick(cookieToBeCleared, 'name', 'domain'))
.then(() => {
return cookieToBeCleared
})
})

case 'clear:cookies':
Expand Down
145 changes: 71 additions & 74 deletions packages/server/lib/browsers/cri-client.ts
@@ -1,4 +1,3 @@
import Bluebird from 'bluebird'
import debugModule from 'debug'
import _ from 'lodash'

Expand Down Expand Up @@ -48,17 +47,17 @@ interface CRIWrapper {
/**
* Get the `protocolVersion` supported by the browser.
*/
getProtocolVersion (): Bluebird<Version>
getProtocolVersion (): Promise<Version>
/**
* Rejects if `protocolVersion` is less than the current version.
* @param protocolVersion CDP version string (ex: 1.3)
*/
ensureMinimumProtocolVersion(protocolVersion: string): Bluebird<void>
ensureMinimumProtocolVersion(protocolVersion: string): Promise<void>
/**
* Sends a command to the Chrome remote interface.
* @example client.send('Page.navigate', { url })
*/
send (command: CRI.Command, params?: object): Bluebird<any>
send (command: CRI.Command, params?: object): Promise<any>
/**
* Registers callback for particular event.
* @see https://github.com/cyrus-and/chrome-remote-interface#class-cdp
Expand All @@ -67,7 +66,7 @@ interface CRIWrapper {
/**
* Calls underlying remote interface client close
*/
close (): Bluebird<void>
close (): Promise<void>
}

interface Version {
Expand Down Expand Up @@ -137,7 +136,7 @@ export { chromeRemoteInterface }

type DeferredPromise = { resolve: Function, reject: Function }

export const create = Bluebird.method((target: websocketUrl, onAsynchronousError: Function): Bluebird<CRIWrapper> => {
export const create = async (target: websocketUrl, onAsynchronousError: Function): Promise<CRIWrapper> => {
const subscriptions: {eventName: CRI.EventName, cb: Function}[] = []
let enqueuedCommands: {command: CRI.Command, params: any, p: DeferredPromise }[] = []

Expand All @@ -147,7 +146,7 @@ export const create = Bluebird.method((target: websocketUrl, onAsynchronousError
let cri
let client: CRIWrapper

const reconnect = () => {
const reconnect = async () => {
debug('disconnected, attempting to reconnect... %o', { closed })

connected = false
Expand All @@ -156,8 +155,9 @@ export const create = Bluebird.method((target: websocketUrl, onAsynchronousError
return
}

return connect()
.then(() => {
try {
await connect()

debug('restoring subscriptions + running queued commands... %o', { subscriptions, enqueuedCommands })
subscriptions.forEach((sub) => {
cri.on(sub.eventName, sub.cb)
Expand All @@ -169,98 +169,95 @@ export const create = Bluebird.method((target: websocketUrl, onAsynchronousError
})

enqueuedCommands = []
})
.catch((err) => {
} catch (err) {
onAsynchronousError(errors.get('CDP_COULD_NOT_RECONNECT', err))
})
}
}

const connect = () => {
const connect = async () => {
cri?.close()

debug('connecting %o', { target })

return chromeRemoteInterface({
cri = await chromeRemoteInterface({
target,
local: true,
})
.then((newCri) => {
cri = newCri
connected = true

maybeDebugCdpMessages(cri)
connected = true

cri.send = Bluebird.promisify(cri.send, { context: cri })
maybeDebugCdpMessages(cri)

// @see https://github.com/cyrus-and/chrome-remote-interface/issues/72
cri._notifier.on('disconnect', reconnect)
})
// @see https://github.com/cyrus-and/chrome-remote-interface/issues/72
cri._notifier.on('disconnect', reconnect)
}

return connect()
.then(() => {
const ensureMinimumProtocolVersion = (protocolVersion: string) => {
return getProtocolVersion()
.then((actual) => {
const minimum = getMajorMinorVersion(protocolVersion)
await connect()

if (!isVersionGte(actual, minimum)) {
errors.throw('CDP_VERSION_TOO_OLD', protocolVersion, actual)
}
})
const ensureMinimumProtocolVersion = async (protocolVersion: string) => {
const actual = await getProtocolVersion()
const minimum = getMajorMinorVersion(protocolVersion)

if (!isVersionGte(actual, minimum)) {
errors.throw('CDP_VERSION_TOO_OLD', protocolVersion, actual)
}
}

const getProtocolVersion = _.memoize(() => {
return client.send('Browser.getVersion')
const getProtocolVersion = _.memoize(async () => {
let version

try {
version = await client.send('Browser.getVersion')
} catch (_) {
// could be any version <= 1.2
.catchReturn({ protocolVersion: '0.0' })
.then(({ protocolVersion }) => {
return getMajorMinorVersion(protocolVersion)
})
})
version = { protocolVersion: '0.0' }
}

client = {
ensureMinimumProtocolVersion,
getProtocolVersion,
send: Bluebird.method((command: CRI.Command, params?: object) => {
const enqueue = () => {
return new Bluebird((resolve, reject) => {
enqueuedCommands.push({ command, params, p: { resolve, reject } })
})
}
return getMajorMinorVersion(version.protocolVersion)
})

if (connected) {
return cri.send(command, params)
.catch((err) => {
if (!WEBSOCKET_NOT_OPEN_RE.test(err.message)) {
throw err
}
client = {
ensureMinimumProtocolVersion,
getProtocolVersion,
async send (command: CRI.Command, params?: object) {
const enqueue = () => {
return new Promise((resolve, reject) => {
enqueuedCommands.push({ command, params, p: { resolve, reject } })
})
}

if (connected) {
try {
return await cri.send(command, params)
} catch (err) {
if (!WEBSOCKET_NOT_OPEN_RE.test(err.message)) {
throw err
}

debug('encountered closed websocket on send %o', { command, params, err })
debug('encountered closed websocket on send %o', { command, params, err })

const p = enqueue()
const p = enqueue()

reconnect()
reconnect()

return p
})
return p
}
}

return enqueue()
}),
on (eventName: CRI.EventName, cb: Function) {
subscriptions.push({ eventName, cb })
debug('registering CDP on event %o', { eventName })
return enqueue()
},
on (eventName: CRI.EventName, cb: Function) {
subscriptions.push({ eventName, cb })
debug('registering CDP on event %o', { eventName })

return cri.on(eventName, cb)
},
close () {
closed = true
return cri.on(eventName, cb)
},
close () {
closed = true

return cri.close()
},
}
return cri.close()
},
}

return client
})
})
return client
}
3 changes: 0 additions & 3 deletions packages/server/test/unit/browsers/cri-client_spec.ts
@@ -1,4 +1,3 @@
import Bluebird from 'bluebird'
import chalk from 'chalk'
import EventEmitter from 'events'
import { create } from '../../../lib/browsers/cri-client'
Expand All @@ -17,8 +16,6 @@ describe('lib/browsers/cri-client', function () {
let getClient: () => ReturnType<typeof create>

beforeEach(function () {
sinon.stub(Bluebird, 'promisify').returnsArg(0)

send = sinon.stub()
onError = sinon.stub()

Expand Down

3 comments on commit 1fa78f5

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1fa78f5 Mar 30, 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/9.6.0/linux-x64/feature-multidomain-1fa78f5021baedc4ebcfe3f0e28d9035e4185e6c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1fa78f5 Mar 30, 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/9.6.0/darwin-x64/feature-multidomain-1fa78f5021baedc4ebcfe3f0e28d9035e4185e6c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1fa78f5 Mar 30, 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/9.6.0/win32-x64/feature-multidomain-1fa78f5021baedc4ebcfe3f0e28d9035e4185e6c/cypress.tgz

Please sign in to comment.