Skip to content

Commit

Permalink
Merge branch 'develop' into error-improvements-approved
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding committed Mar 13, 2020
2 parents 88673c8 + 910ac6f commit 689bef0
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 116 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ executors:
# the Docker image with Cypress dependencies and Chrome browser
cy-doc:
docker:
- image: cypress/browsers:node12.8.1-chrome80-ff72
- image: cypress/browsers:node12.13.0-chrome80-ff74
environment:
PLATFORM: linux

Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"mocha": "6.2.2",
"mock-fs": "4.9.0",
"mocked-env": "1.2.4",
"nock": "9.6.1",
"nock": "12.0.2",
"postinstall-postinstall": "2.0.0",
"proxyquire": "2.1.0",
"resolve-pkg": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"minimist": "1.2.0"
},
"devDependencies": {
"electron": "7.1.13",
"electron": "8.1.1",
"mocha": "3.5.3"
},
"files": [
Expand Down
20 changes: 10 additions & 10 deletions packages/launcher/lib/browsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const browsers: Browser[] = [
family: 'chromium',
channel: 'stable',
displayName: 'Chrome',
versionRegex: /Google Chrome (\S+)/,
versionRegex: /Google Chrome (\S+)/m,
profile: true,
binary: ['google-chrome', 'chrome', 'google-chrome-stable'],
},
Expand All @@ -21,7 +21,7 @@ export const browsers: Browser[] = [
// technically Chromium is always in development
channel: 'stable',
displayName: 'Chromium',
versionRegex: /Chromium (\S+)/,
versionRegex: /Chromium (\S+)/m,
profile: true,
binary: ['chromium-browser', 'chromium'],
},
Expand All @@ -30,7 +30,7 @@ export const browsers: Browser[] = [
family: 'chromium',
channel: 'canary',
displayName: 'Canary',
versionRegex: /Google Chrome Canary (\S+)/,
versionRegex: /Google Chrome Canary (\S+)/m,
profile: true,
binary: 'google-chrome-canary',
},
Expand All @@ -41,7 +41,7 @@ export const browsers: Browser[] = [
displayName: 'Firefox',
info: firefoxInfo,
// Mozilla Firefox 70.0.1
versionRegex: /^Mozilla Firefox ([^\sab]+)$/,
versionRegex: /^Mozilla Firefox ([^\sab]+)$/m,
profile: true,
binary: 'firefox',
},
Expand All @@ -52,7 +52,7 @@ export const browsers: Browser[] = [
displayName: 'Firefox Developer Edition',
info: firefoxInfo,
// Mozilla Firefox 73.0b12
versionRegex: /^Mozilla Firefox (\S+b\S*)$/,
versionRegex: /^Mozilla Firefox (\S+b\S*)$/m,
profile: true,
// ubuntu PPAs install it as firefox
binary: ['firefox-developer-edition', 'firefox'],
Expand All @@ -64,7 +64,7 @@ export const browsers: Browser[] = [
displayName: 'Firefox Nightly',
info: firefoxInfo,
// Mozilla Firefox 74.0a1
versionRegex: /^Mozilla Firefox (\S+a\S*)$/,
versionRegex: /^Mozilla Firefox (\S+a\S*)$/m,
profile: true,
// ubuntu PPAs install it as firefox-trunk
binary: ['firefox-nightly', 'firefox-trunk'],
Expand All @@ -74,7 +74,7 @@ export const browsers: Browser[] = [
family: 'chromium',
channel: 'stable',
displayName: 'Edge',
versionRegex: /Microsoft Edge (\S+)/,
versionRegex: /Microsoft Edge (\S+)/m,
profile: true,
binary: 'edge',
},
Expand All @@ -83,7 +83,7 @@ export const browsers: Browser[] = [
family: 'chromium',
channel: 'canary',
displayName: 'Edge Canary',
versionRegex: /Microsoft Edge Canary (\S+)/,
versionRegex: /Microsoft Edge Canary (\S+)/m,
profile: true,
binary: 'edge-canary',
},
Expand All @@ -92,7 +92,7 @@ export const browsers: Browser[] = [
family: 'chromium',
channel: 'beta',
displayName: 'Edge Beta',
versionRegex: /Microsoft Edge Beta (\S+)/,
versionRegex: /Microsoft Edge Beta (\S+)/m,
profile: true,
binary: 'edge-beta',
},
Expand All @@ -101,7 +101,7 @@ export const browsers: Browser[] = [
family: 'chromium',
channel: 'dev',
displayName: 'Edge Dev',
versionRegex: /Microsoft Edge Dev (\S+)/,
versionRegex: /Microsoft Edge Dev (\S+)/m,
profile: true,
binary: 'edge-dev',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/launcher/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ export const goalBrowsers = [
{
displayName: 'Test Browser',
name: 'test-browser-name',
versionRegex: /test-browser v(\S+)$/,
versionRegex: /test-browser v(\S+)$/m,
profile: true,
binary: 'test-browser',
},
{
displayName: 'Foo Browser',
name: 'foo-browser',
versionRegex: /foo-browser v(\S+)$/,
versionRegex: /foo-browser v(\S+)$/m,
profile: true,
binary: ['foo-browser', 'foo-bar-browser'],
},
Expand Down
9 changes: 9 additions & 0 deletions packages/launcher/test/unit/browsers_spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import _ from 'lodash'
import { browsers } from '../../lib/browsers'
import { expect } from 'chai'
const snapshot = require('snap-shot-it')

describe('browsers', () => {
it('returns the expected list of browsers', () => {
snapshot(browsers)
})

// https://github.com/cypress-io/cypress/issues/6669
it('exports multiline versionRegexes', () => {
expect(_.every(browsers.map(({ versionRegex }) => {
return versionRegex.multiline
}))).to.be.true
})
})
19 changes: 19 additions & 0 deletions packages/launcher/test/unit/linux_spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require('../spec_helper')

import _ from 'lodash'
import * as linuxHelper from '../../lib/linux'
import 'chai-as-promised'
import { log } from '../log'
Expand Down Expand Up @@ -42,6 +43,24 @@ describe('linux browser detection', () => {
return linuxHelper.detect(goal).then(checkBrowser)
})

// https://github.com/cypress-io/cypress/issues/6669
it('detects browser if the --version stdout is multiline', () => {
stdout.withArgs('multiline-foo', ['--version'])
.resolves('Running without a11y support!\nfoo-browser v9001.1.2.3')

const goal = _.defaults({ binary: 'multiline-foo' }, _.find(goalBrowsers, { name: 'foo-browser' }))
const checkBrowser = (browser) => {
expect(browser).to.deep.equal({
name: 'foo-browser',
path: 'multiline-foo',
version: '9001.1.2.3',
})
}

// @ts-ignore
return linuxHelper.detect(goal).then(checkBrowser)
})

// despite using detect(), this test is in linux/spec instead of detect_spec because it is
// testing side effects that occur within the Linux-specific detect function
// https://github.com/cypress-io/cypress/issues/1400
Expand Down
20 changes: 15 additions & 5 deletions packages/server/__snapshots__/request_spec.coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ exports['lib/request #sendPromise followRedirect gets + attaches the cookies at
"setCalls": [
{
"currentUrl": "http://localhost:1234/",
"setCookie": "one=1"
"setCookie": [
"one=1"
]
},
{
"currentUrl": "http://localhost:1234/second",
"setCookie": "two=2"
"setCookie": [
"two=2"
]
},
{
"currentUrl": "http://localhost:1234/third",
"setCookie": "three=3"
"setCookie": [
"three=3"
]
}
],
"getCalls": [
Expand All @@ -30,11 +36,15 @@ exports['lib/request #sendStream gets + attaches the cookies at each redirect 1'
"setCalls": [
{
"currentUrl": "http://localhost:1234/",
"setCookie": "one=1"
"setCookie": [
"one=1"
]
},
{
"currentUrl": "http://localhost:1234/second",
"setCookie": "two=2"
"setCookie": [
"two=2"
]
}
],
"getCalls": [
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/browsers/cdp_automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const CdpAutomation = (sendDebuggerCommandFn: SendDebuggerCommand) => {
case 'remote:debugger:protocol':
return sendDebuggerCommandFn(data.command, data.params)
case 'take:screenshot':
return sendDebuggerCommandFn('Page.captureScreenshot')
return sendDebuggerCommandFn('Page.captureScreenshot', { format: 'png' })
.catch((err) => {
throw new Error(`The browser responded with an error when Cypress attempted to take a screenshot.\n\nDetails:\n${err.message}`)
})
Expand Down
46 changes: 30 additions & 16 deletions packages/server/lib/browsers/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,36 @@ const tryToCall = function (win, method) {
}
}

const getAutomation = function (win) {
const _getAutomation = function (win, options) {
const sendCommand = Bluebird.method((...args) => {
return tryToCall(win, () => {
return win.webContents.debugger.sendCommand
.apply(win.webContents.debugger, args)
})
})

return CdpAutomation(sendCommand)
const automation = CdpAutomation(sendCommand)

if (!options.onScreencastFrame) {
// after upgrading to Electron 8, CDP screenshots can hang if a screencast is not also running
// workaround: start and stop screencasts between screenshots
// @see https://github.com/cypress-io/cypress/pull/6555#issuecomment-596747134
automation.onRequest = _.wrap(automation.onRequest, async (fn, message, data) => {
if (message !== 'take:screenshot') {
return fn(message, data)
}

await sendCommand('Page.startScreencast')

const ret = await fn(message, data)

await sendCommand('Page.stopScreencast')

return ret
})
}

return automation
}

const _installExtensions = function (extensionPaths = [], options) {
Expand All @@ -61,14 +82,12 @@ const _maybeRecordVideo = function (webContents, options) {
return async () => {
const { onScreencastFrame } = options

if (!onScreencastFrame) {
debug('options.onScreencastFrame is falsy')
debug('maybe recording video %o', { onScreencastFrame })

if (!onScreencastFrame) {
return
}

debug('starting screencast')

webContents.debugger.on('message', (event, method, params) => {
if (method === 'Page.screencastFrame') {
onScreencastFrame(params)
Expand Down Expand Up @@ -132,12 +151,12 @@ module.exports = {
return _.defaultsDeep({}, options, defaults)
},

_getAutomation: getAutomation,
_getAutomation,

_render (url, projectRoot, automation, options = {}) {
const win = Windows.create(projectRoot, options)

automation.use(getAutomation(win))
automation.use(_getAutomation(win, options))

return this._launch(win, url, options)
.tap(_maybeRecordVideo(win.webContents, options))
Expand Down Expand Up @@ -215,11 +234,9 @@ module.exports = {

_attachDebugger (webContents) {
try {
webContents.debugger.attach()
webContents.debugger.attach('1.3')
debug('debugger attached')
} catch (error) {
const err = error

} catch (err) {
debug('debugger attached failed %o', { err })
throw err
}
Expand Down Expand Up @@ -263,10 +280,7 @@ module.exports = {
_enableDebugger (webContents) {
debug('debugger: enable Console and Network')

return Bluebird.join(
webContents.debugger.sendCommand('Console.enable'),
webContents.debugger.sendCommand('Network.enable'),
)
return webContents.debugger.sendCommand('Console.enable')
},

_getPartition (options) {
Expand Down
41 changes: 0 additions & 41 deletions packages/server/lib/screenshots.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -166,47 +166,6 @@ pixelConditionFn = (data, image) ->

multipartImages = []

# compareUntilPixelsDiffer = (img1, img2) ->
## NOTE: this is for comparing pixel by pixel which is useful
## if you're trying to dig into the specific pixel differences
##
## we're making this as efficient as possible because
## there are significant performance problems
## getting a hash or buffer of all the image data.
##
## instead we will walk through two images comparing
## them pixel by pixel until they don't match.
#
# iterations = 0
#
# { width, height } = img2.bitmap
#
# data1 = img1.bitmap.data
# data2 = img2.bitmap.data
#
# ret = (differences) ->
# return {
# iterations
# differences
# }
#
# for y in [0...height]
# for x in [0...width]
# iterations += 1
#
# idx = (width * y + x) << 2
#
# pix1 = data1.readUInt32BE(idx)
# pix2 = data2.readUInt32BE(idx)
#
# if pix1 isnt pix2
# return ret([
# intToRGBA(pix1),
# intToRGBA(pix2)
# ])
#
# return ret(null)

clearMultipartState = ->
debug("clearing %d cached multipart images", multipartImages.length)
multipartImages = []
Expand Down
3 changes: 3 additions & 0 deletions packages/server/lib/util/electron-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const waitForReady = () => {
const Promise = require('bluebird')
const { app } = require('electron')

// @see https://github.com/electron/electron/issues/18397
app.allowRendererProcessReuse = true

// electron >= 5.0.0 will exit the app if all browserwindows are closed,
// this is obviously undesirable in run mode
// https://github.com/cypress-io/cypress/pull/4720#issuecomment-514316695
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"mocked-env": "1.2.4",
"mockery": "2.1.0",
"multiparty": "4.2.1",
"nock": "9.6.1",
"nock": "12.0.2",
"npm-install-version": "6.0.2",
"proxyquire": "2.1.0",
"react": "15.6.2",
Expand Down
Loading

0 comments on commit 689bef0

Please sign in to comment.