From dbd0ff2fc84e0e167cef562a280e3e20c1e9522a Mon Sep 17 00:00:00 2001 From: Ben Kucera - CI <14625260+Bkucera@users.noreply.github.com> Date: Thu, 6 Sep 2018 14:04:51 -0400 Subject: [PATCH 001/207] update zunder --- packages/desktop-gui/package.json | 2 +- packages/driver/package.json | 4 +++- packages/reporter/package.json | 2 +- packages/runner/package.json | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/desktop-gui/package.json b/packages/desktop-gui/package.json index aac4d4edcce5..9989d495b7e7 100644 --- a/packages/desktop-gui/package.json +++ b/packages/desktop-gui/package.json @@ -44,6 +44,6 @@ "react-bootstrap-modal": "3.0.1", "react-dom": "^15.6.1", "react-loader": "^2.4.0", - "zunder": "5.6.5" + "zunder": "5.8.2" } } diff --git a/packages/driver/package.json b/packages/driver/package.json index a59c80afb945..51c6fc2720e2 100644 --- a/packages/driver/package.json +++ b/packages/driver/package.json @@ -59,6 +59,8 @@ "url-parse": "^1.1.7", "vanilla-text-mask": "^5.1.1", "wait-on": "^2.0.2", - "zone.js": "^0.8.18" + "zone.js": "^0.8.18", + "zunder": "^5.8.0" } + } diff --git a/packages/reporter/package.json b/packages/reporter/package.json index a4c2d02d675f..58e13194554d 100644 --- a/packages/reporter/package.json +++ b/packages/reporter/package.json @@ -64,6 +64,6 @@ "rebuild-node-sass": "^1.1.0", "sinon": "^1.17.4", "sinon-chai": "^2.8.0", - "zunder": "5.6.5" + "zunder": "5.8.0" } } diff --git a/packages/runner/package.json b/packages/runner/package.json index 785333b2d684..9c96e29694b9 100644 --- a/packages/runner/package.json +++ b/packages/runner/package.json @@ -41,6 +41,6 @@ "rebuild-node-sass": "^1.1.0", "sinon": "^1.17.5", "sinon-chai": "^2.8.0", - "zunder": "5.6.5" + "zunder": "^5.8.2" } } From a31fc99a182e59bae8a872d20874aff0b42c2fa7 Mon Sep 17 00:00:00 2001 From: Ben Kucera - CI <14625260+Bkucera@users.noreply.github.com> Date: Thu, 6 Sep 2018 21:07:27 -0400 Subject: [PATCH 002/207] [skip ci] CDP in browser --- packages/driver/package.json | 1 + .../src/cy/commands/actions/click.coffee | 88 +++++++++++-------- packages/driver/src/cypress/native_events.js | 86 ++++++++++++++++++ packages/launcher/lib/browsers.ts | 2 +- packages/runner/package.json | 1 + packages/server/lib/browsers/chrome.coffee | 12 ++- packages/server/lib/browsers/protocol.js | 53 +++++++++++ packages/server/lib/controllers/runner.coffee | 1 + packages/server/package.json | 2 + 9 files changed, 206 insertions(+), 40 deletions(-) create mode 100644 packages/driver/src/cypress/native_events.js create mode 100644 packages/server/lib/browsers/protocol.js diff --git a/packages/driver/package.json b/packages/driver/package.json index 51c6fc2720e2..a29077efc337 100644 --- a/packages/driver/package.json +++ b/packages/driver/package.json @@ -30,6 +30,7 @@ "chai": "3.5.0", "chai-as-promised": "6.0.0", "chokidar-cli": "^1.2.0", + "chrome-remote-interface": "^0.26.1", "clone": "^2.1.1", "compression": "^1.1.0", "cors": "^2.7.1", diff --git a/packages/driver/src/cy/commands/actions/click.coffee b/packages/driver/src/cy/commands/actions/click.coffee index 42196b900f1d..38514be4238c 100644 --- a/packages/driver/src/cy/commands/actions/click.coffee +++ b/packages/driver/src/cy/commands/actions/click.coffee @@ -9,6 +9,7 @@ $utils = require("../../../cypress/utils") $elements = require("../../../dom/elements") $selection = require("../../../dom/selection") $actionability = require("../../actionability") +$native = require("../../../cypress/native_events") module.exports = (Commands, Cypress, cy, state, config) -> Commands.addAll({ prevSubject: "element" }, { @@ -68,14 +69,21 @@ module.exports = (Commands, Cypress, cy, state, config) -> ## handle mouse events removing DOM elements ## https://www.w3.org/TR/uievents/#event-type-click (scroll up slightly) - if $dom.isAttached($elToClick) - domEvents.mouseUp = $Mouse.mouseUp($elToClick, fromViewport) + # if $dom.isAttached($elToClick) + return $native.mouseup(coords) + # .then -> + # if options._log and options.log + # options._log.snapshot().end() + .return(null) + + # if $dom.isAttached($elToClick) + # domEvents.mouseUp = $Mouse.mouseUp($elToClick, fromViewport) - if $dom.isAttached($elToClick) - domEvents.click = $Mouse.click($elToClick, fromViewport) + # if $dom.isAttached($elToClick) + # domEvents.click = $Mouse.click($elToClick, fromViewport) - if options._log - consoleObj = options._log.invoke("consoleProps") + # if options._log + # consoleObj = options._log.invoke("consoleProps") consoleProps = -> consoleObj = _.defaults consoleObj ? {}, { @@ -155,40 +163,44 @@ module.exports = (Commands, Cypress, cy, state, config) -> el = $elToClick.get(0) - domEvents.mouseDown = $Mouse.mouseDown($elToClick, coords.fromViewport) - - ## if mousedown was cancelled then or caused - ## our element to be removed from the DOM - ## just resolve after mouse down and dont - ## send a focus event - if domEvents.mouseDown.preventedDefault or not $dom.isAttached($elToClick) - afterMouseDown($elToClick, coords) - else - if $elements.isInput(el) or $elements.isTextarea(el) or $elements.isContentEditable(el) - if !$elements.isNeedSingleValueChangeInputElement(el) - $selection.moveSelectionToEnd(el) - - ## retrieve the first focusable $el in our parent chain - $elToFocus = $elements.getFirstFocusableEl($elToClick) - - if cy.needsFocus($elToFocus, $previouslyFocused) - cy.fireFocus($elToFocus.get(0)) - - ## if we are currently trying to focus - ## the body then calling body.focus() - ## is a noop, and it will not blur the - ## current element, which is all so wrong - if $elToFocus.is("body") - $focused = cy.getFocused() - - ## if the current focused element hasn't changed - ## then blur manually - if $elements.isSame($focused, $previouslyFocused) - cy.fireBlur($focused.get(0)) - - afterMouseDown($elToClick, coords) + return $native.mousedown(coords.fromViewport) + .then(()=>afterMouseDown($elToClick, coords)) + + # domEvents.mouseDown = $Mouse.mouseDown($elToClick, coords.fromViewport) + + # ## if mousedown was cancelled then or caused + # ## our element to be removed from the DOM + # ## just resolve after mouse down and dont + # ## send a focus event + # if domEvents.mouseDown.preventedDefault or not $dom.isAttached($elToClick) + # afterMouseDown($elToClick, coords) + # else + # if $elements.isInput(el) or $elements.isTextarea(el) or $elements.isContentEditable(el) + # if !$elements.isNeedSingleValueChangeInputElement(el) + # $selection.moveSelectionToEnd(el) + + # ## retrieve the first focusable $el in our parent chain + # $elToFocus = $elements.getFirstFocusableEl($elToClick) + + # if cy.needsFocus($elToFocus, $previouslyFocused) + # cy.fireFocus($elToFocus.get(0)) + + # ## if we are currently trying to focus + # ## the body then calling body.focus() + # ## is a noop, and it will not blur the + # ## current element, which is all so wrong + # if $elToFocus.is("body") + # $focused = cy.getFocused() + + # ## if the current focused element hasn't changed + # ## then blur manually + # if $elements.isSame($focused, $previouslyFocused) + # cy.fireBlur($focused.get(0)) + + # afterMouseDown($elToClick, coords) }) .catch (err) -> + debugger ## snapshot only on click failure err.onFail = -> if options._log diff --git a/packages/driver/src/cypress/native_events.js b/packages/driver/src/cypress/native_events.js new file mode 100644 index 000000000000..2992716eef5e --- /dev/null +++ b/packages/driver/src/cypress/native_events.js @@ -0,0 +1,86 @@ +console.log('native events ') +const _ = require('lodash') +// const $Cypress = require('../cypress') + +window.criRequest = (options, callback) => { + +} + +require('@babel/polyfill') +const CRI = require('chrome-remote-interface') + +console.log('loaded CRI') +const Promise = require('bluebird') +const debug = require('debug')('cypress:driver') + +let client + +const init = () => { + return Promise.try(() => { + + if (client) { + return client + } + console.log('cy config', Cypress.config()) + const wsUrl = Cypress.config('wsUrl')//'sdf'//window.config.wsUrl + return CRI(wsUrl) + .then((cri_client) => { + + client = cri_client + }) + .catch((e) => { + + }) + }) +} + +const mousedown = (coords) => { + + const x = coords.x + (coords.right - coords.left) / 2 + const y = coords.y + (coords.bottom - coords.top) / 2 + + + return init() + .then(() => { + return client.send('Input.dispatchMouseEvent', { + x, + y, + type: 'mouseMoved', + }) + }) + + .then(() => { + return client.send('Input.dispatchMouseEvent', { + x, + y, + type: 'mousePressed', + button: 'left', + clickCount: 1, + }) + }) +} + +const mouseup = (coords) => { + + const x = coords.x + (coords.right - coords.left) / 2 + const y = coords.y + (coords.bottom - coords.top) / 2 + + return init() + .then(() => { + + return client.send('Input.dispatchMouseEvent', { + x, + y, + type: 'mouseReleased', + button: 'left', + clickCount: 1, + }) + }) + + +} +console.log('export') +module.exports = { + mousedown, + mouseup, +} diff --git a/packages/launcher/lib/browsers.ts b/packages/launcher/lib/browsers.ts index a87254005e72..25e4e9091693 100644 --- a/packages/launcher/lib/browsers.ts +++ b/packages/launcher/lib/browsers.ts @@ -23,7 +23,7 @@ export const browsers: Browser[] = [ displayName: 'Chrome', versionRegex: /Google Chrome (\S+)/, profile: true, - binary: 'google-chrome' + binary: 'google-chrome-beta' }, { name: 'chromium', diff --git a/packages/runner/package.json b/packages/runner/package.json index 9c96e29694b9..a8517c318dc0 100644 --- a/packages/runner/package.json +++ b/packages/runner/package.json @@ -25,6 +25,7 @@ "bluebird": "3.5.0", "chai": "^3.5.0", "chai-enzyme": "^0.7.1", + "chrome-remote-interface": "^0.26.1", "classnames": "^2.2.5", "enzyme": "^2.8.2", "font-awesome": "^4.6.3", diff --git a/packages/server/lib/browsers/chrome.coffee b/packages/server/lib/browsers/chrome.coffee index 5e41ce0e1aaa..13883825a904 100644 --- a/packages/server/lib/browsers/chrome.coffee +++ b/packages/server/lib/browsers/chrome.coffee @@ -8,6 +8,7 @@ plugins = require("../plugins") fs = require("../util/fs") appData = require("../util/app_data") utils = require("./utils") +protocol = require("./protocol") LOAD_EXTENSION = "--load-extension=" CHROME_VERSIONS_WITH_BUGGY_ROOT_LAYER_SCROLLING = "66 67".split(" ") @@ -185,8 +186,17 @@ module.exports = { ## by being the last one args.push("--user-data-dir=#{userDir}") args.push("--disk-cache-dir=#{cacheDir}") + ## TODO: make this a dynamic port + args.push("--remote-debugging-port=9222") debug("launch in chrome: %s, %s", url, args) - + utils.launch(browserName, url, args) + .tap -> + ## TODO: pass in the port + protocol.getWsTargetFor() + .then (wsUrl) -> + console.log 'wsUrl', wsUrl + global.wsUrl = wsUrl + } diff --git a/packages/server/lib/browsers/protocol.js b/packages/server/lib/browsers/protocol.js new file mode 100644 index 000000000000..0754e68f5c59 --- /dev/null +++ b/packages/server/lib/browsers/protocol.js @@ -0,0 +1,53 @@ +const _ = require('lodash') +const CRI = require('chrome-remote-interface') +const promiseRetry = require('promise-retry') +const Promise = require('bluebird') +const net = require('net') + +function connectAsync (opts) { + return new Promise(function (resolve, reject) { + let socket = net.connect(opts) + socket.once('connect', function () { + socket.removeListener('error', reject) + resolve(socket) + }) + socket.once('error', function (err) { + socket.removeListener('connection', resolve) + reject(err) + }) + }) +} + +// TODO: accept port as arg +const getWsTargetFor = () => { + + return promiseRetry((retry, number) => { + console.log('attempt number:', number) + return connectAsync({ port: '9222' }).catch(retry) + }, { retries: 10 }) + .catch((e) => { + console.log('asdfasfsfsdfasfasdfasdf', e) + }) + .then(() => CRI.List()) + .then((targets) => { + // activate the first available id + console.log('targets are', targets) + + // find the first target page that's a real tab + // and not the dev tools + const target = _.find(targets, (t) => { + return t.type === 'page' && t.url.startsWith('http') + }) + + console.log('target is', target) + + return target + }) + .catch((err) => { + console.log(err) + }) +} + +module.exports = { + getWsTargetFor, +} diff --git a/packages/server/lib/controllers/runner.coffee b/packages/server/lib/controllers/runner.coffee index ecb0ce771919..4ed12b9e9b44 100644 --- a/packages/server/lib/controllers/runner.coffee +++ b/packages/server/lib/controllers/runner.coffee @@ -18,6 +18,7 @@ module.exports = { config.arch = os.arch() config.spec = spec config.browser = browser + config.wsUrl = global.wsUrl debug("serving runner index.html with config %o", _.pick(config, "version", "platform", "arch", "projectName") diff --git a/packages/server/package.json b/packages/server/package.json index 1eed841a88da..e45d4dd60187 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -45,6 +45,7 @@ "body-parser": "1.12.4", "chai-uuid": "^1.0.6", "chokidar-cli": "^1.2.0", + "chrome-remote-interface": "^0.26.1", "codecov": "^1.0.1", "coffee-coverage": "^1.0.1", "cors": "^2.8.3", @@ -149,6 +150,7 @@ "parse-domain": "2.0.0", "pluralize": "^3.0.0", "progress": "^1.1.8", + "promise-retry": "^1.1.1", "pumpify": "1.5.1", "ramda": "^0.24.0", "randomstring": "^1.1.5", From 48563a8394ef1f148b6775dd4fceba6a8d5768a5 Mon Sep 17 00:00:00 2001 From: Ben Kucera - CI <14625260+Bkucera@users.noreply.github.com> Date: Fri, 7 Sep 2018 14:14:55 -0400 Subject: [PATCH 003/207] [skip ci] coords --- packages/driver/src/cy/actionability.coffee | 1 + .../src/cy/commands/actions/click.coffee | 4 +- packages/driver/src/cypress/native_events.js | 99 ++++++++++--------- packages/driver/src/dom/coordinates.coffee | 18 +++- packages/server/lib/browsers/protocol.js | 4 +- 5 files changed, 72 insertions(+), 54 deletions(-) diff --git a/packages/driver/src/cy/actionability.coffee b/packages/driver/src/cy/actionability.coffee index c217e929352a..2c938b2bebe2 100644 --- a/packages/driver/src/cy/actionability.coffee +++ b/packages/driver/src/cy/actionability.coffee @@ -186,6 +186,7 @@ ensureElIsNotCovered = (cy, win, $el, fromViewport, options, log, onScroll) -> return $elAtCoords getCoordinatesForEl = (cy, $el, options) -> + debugger ## determine if this element is animating if options.x and options.y $dom.getElementCoordinatesByPositionRelativeToXY($el, options.x, options.y) diff --git a/packages/driver/src/cy/commands/actions/click.coffee b/packages/driver/src/cy/commands/actions/click.coffee index 38514be4238c..cd1c2bb7a788 100644 --- a/packages/driver/src/cy/commands/actions/click.coffee +++ b/packages/driver/src/cy/commands/actions/click.coffee @@ -70,7 +70,7 @@ module.exports = (Commands, Cypress, cy, state, config) -> ## https://www.w3.org/TR/uievents/#event-type-click (scroll up slightly) # if $dom.isAttached($elToClick) - return $native.mouseup(coords) + return $native.mouseup(coords.fromViewport) # .then -> # if options._log and options.log # options._log.snapshot().end() @@ -163,7 +163,7 @@ module.exports = (Commands, Cypress, cy, state, config) -> el = $elToClick.get(0) - return $native.mousedown(coords.fromViewport) + return $native.mousedown($elToClick, coords.fromViewport) .then(()=>afterMouseDown($elToClick, coords)) # domEvents.mouseDown = $Mouse.mouseDown($elToClick, coords.fromViewport) diff --git a/packages/driver/src/cypress/native_events.js b/packages/driver/src/cypress/native_events.js index 2992716eef5e..bcaaffa2f388 100644 --- a/packages/driver/src/cypress/native_events.js +++ b/packages/driver/src/cypress/native_events.js @@ -1,15 +1,8 @@ -console.log('native events ') -const _ = require('lodash') -// const $Cypress = require('../cypress') - -window.criRequest = (options, callback) => { - -} - require('@babel/polyfill') + +window.criRequest = function () {} const CRI = require('chrome-remote-interface') -console.log('loaded CRI') const Promise = require('bluebird') const debug = require('debug')('cypress:driver') @@ -17,42 +10,38 @@ let client const init = () => { return Promise.try(() => { - if (client) { return client } - console.log('cy config', Cypress.config()) - const wsUrl = Cypress.config('wsUrl')//'sdf'//window.config.wsUrl - return CRI(wsUrl) - .then((cri_client) => { + // console.log('cy config', Cypress.config()) + const wsUrl = Cypress.config('wsUrl') //'sdf'//window.config.wsUrl - client = cri_client + return CRI({ + target: wsUrl, + local: true, }) - .catch((e) => { + .then((cri_client) => { + client = cri_client }) + .catch((e) => { }) }) } -const mousedown = (coords) => { - - const x = coords.x + (coords.right - coords.left) / 2 - const y = coords.y + (coords.bottom - coords.top) / 2 - - - return init() - .then(() => { - return client.send('Input.dispatchMouseEvent', { - x, - y, - type: 'mouseMoved', - }) +const mousedown = ($elToClick, coords) => { + // const x = coords.x + (coords.right - coords.left) / 2 + // const y = coords.y + (coords.bottom - coords.top) / 2 + const { x, y } = calculateTrueCoords(coords, $elToClick) + return client.send('Input.dispatchMouseEvent', { + x, + y, + type: 'mouseMoved', }) .then(() => { return client.send('Input.dispatchMouseEvent', { - x, - y, + x: coords.x, + y: coords.y, type: 'mousePressed', button: 'left', clickCount: 1, @@ -60,27 +49,39 @@ const mousedown = (coords) => { }) } -const mouseup = (coords) => { - - const x = coords.x + (coords.right - coords.left) / 2 - const y = coords.y + (coords.bottom - coords.top) / 2 - - return init() - .then(() => { - - return client.send('Input.dispatchMouseEvent', { - x, - y, - type: 'mouseReleased', - button: 'left', - clickCount: 1, - }) +const mouseup = ($elToClick, coords) => { + const { x, y } = calculateTrueCoords(coords, $elToClick) + return client.send('Input.dispatchMouseEvent', { + x, + y, + type: 'mouseReleased', + button: 'left', + clickCount: 1, }) - - } -console.log('export') + module.exports = { mousedown, mouseup, } + + +const calculateTrueCoords = (coords, $elToClick) => { + let x = coords.x + let y = coords.y + let curWindow = $elToClick.ownerDocument.defaultView + while (curWindow.parent) { + const iframes = curWindow.parent.document.getElementsByTagName('IFRAME') + for (let i = 0; i < iframes.length; i++) { + if (curWindow.parent.frames[i] === curWindow) { + const frame = iframes[i] + const rect = frame.getBoundingClientRect() + x += rect.x + y += rect.y + break + } + } + curWindow = curWindow.parent + } + return { x, y } +} diff --git a/packages/driver/src/dom/coordinates.coffee b/packages/driver/src/dom/coordinates.coffee index 17445b7fde47..9d1ecf14d84c 100644 --- a/packages/driver/src/dom/coordinates.coffee +++ b/packages/driver/src/dom/coordinates.coffee @@ -19,11 +19,22 @@ getElementPositioning = ($el) -> topCenter = center.y leftCenter = center.x + ## factor in elements within iframes + iframe = cy.state("$autIframe").get(0).getBoundingClientRect() + return { scrollTop: el.scrollTop scrollLeft: el.scrollLeft width: rect.width height: rect.height + fromTopViewport: { + top: rect.top + iframe.top + left: rect.left + iframe.left + right: rect.right + iframe.right + bottom: rect.bottom + iframe.bottom + topCenter: topCenter + iframe.top + leftCenter: leftCenter + iframe.left + } fromViewport: { top: rect.top left: rect.left @@ -134,7 +145,7 @@ getElementCoordinatesByPosition = ($el, position = "center") -> ## but also from the viewport so ## whoever is calling us can use it ## however they'd like - { width, height, fromViewport, fromWindow } = positionProps + { width, height, fromViewport, fromWindow, fromTopViewport } = positionProps ## dynamically call the function by transforming the name ## bottom -> getBottomCoordinates @@ -163,6 +174,10 @@ getElementCoordinatesByPosition = ($el, position = "center") -> left: fromWindow.left }) + ## HACK: fix this plz + fromTopViewport.x = viewportTargetCoords.x + fromTopViewport.left + fromTopViewport.y = viewportTargetCoords.y + fromTopViewport.top + fromViewport.x = viewportTargetCoords.x fromViewport.y = viewportTargetCoords.y @@ -175,6 +190,7 @@ getElementCoordinatesByPosition = ($el, position = "center") -> return { width height + fromTopViewport fromViewport fromWindow } diff --git a/packages/server/lib/browsers/protocol.js b/packages/server/lib/browsers/protocol.js index 0754e68f5c59..9ae60dabaa87 100644 --- a/packages/server/lib/browsers/protocol.js +++ b/packages/server/lib/browsers/protocol.js @@ -26,7 +26,7 @@ const getWsTargetFor = () => { return connectAsync({ port: '9222' }).catch(retry) }, { retries: 10 }) .catch((e) => { - console.log('asdfasfsfsdfasfasdfasdf', e) + console.log('err', e) }) .then(() => CRI.List()) .then((targets) => { @@ -41,7 +41,7 @@ const getWsTargetFor = () => { console.log('target is', target) - return target + return target.webSocketDebuggerUrl }) .catch((err) => { console.log(err) From 933fba905a02f4f601756cdc6a42a0b4c1db8f87 Mon Sep 17 00:00:00 2001 From: Ben Kucera <14625260+Bkucera@users.noreply.github.com> Date: Thu, 18 Oct 2018 12:39:23 -0400 Subject: [PATCH 004/207] browserify config, use frameElement --- packages/driver/package.json | 4 ++-- packages/driver/src/cypress/native_events.js | 16 +++++---------- packages/launcher/lib/browsers.ts | 2 +- packages/reporter/package.json | 21 +++++++++++--------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/packages/driver/package.json b/packages/driver/package.json index a29077efc337..08e45b4bf4ce 100644 --- a/packages/driver/package.json +++ b/packages/driver/package.json @@ -14,6 +14,7 @@ "lib" ], "devDependencies": { + "@babel/polyfill": "^7.0.0", "@cypress/bower-kendo-ui": "0.0.2", "@cypress/sinon-chai": "1.1.0", "@cypress/underscore.inflection": "^1.0.0", @@ -61,7 +62,6 @@ "vanilla-text-mask": "^5.1.1", "wait-on": "^2.0.2", "zone.js": "^0.8.18", - "zunder": "^5.8.0" + "zunder": "^5.8.2" } - } diff --git a/packages/driver/src/cypress/native_events.js b/packages/driver/src/cypress/native_events.js index bcaaffa2f388..06d24bb73597 100644 --- a/packages/driver/src/cypress/native_events.js +++ b/packages/driver/src/cypress/native_events.js @@ -70,17 +70,11 @@ const calculateTrueCoords = (coords, $elToClick) => { let x = coords.x let y = coords.y let curWindow = $elToClick.ownerDocument.defaultView - while (curWindow.parent) { - const iframes = curWindow.parent.document.getElementsByTagName('IFRAME') - for (let i = 0; i < iframes.length; i++) { - if (curWindow.parent.frames[i] === curWindow) { - const frame = iframes[i] - const rect = frame.getBoundingClientRect() - x += rect.x - y += rect.y - break - } - } + while (curWindow.frameElement) { + const frame = curWindow.frameElement + const rect = frame.getBoundingClientRect() + x += rect.x + y += rect.y curWindow = curWindow.parent } return { x, y } diff --git a/packages/launcher/lib/browsers.ts b/packages/launcher/lib/browsers.ts index 25e4e9091693..a87254005e72 100644 --- a/packages/launcher/lib/browsers.ts +++ b/packages/launcher/lib/browsers.ts @@ -23,7 +23,7 @@ export const browsers: Browser[] = [ displayName: 'Chrome', versionRegex: /Google Chrome (\S+)/, profile: true, - binary: 'google-chrome-beta' + binary: 'google-chrome' }, { name: 'chromium', diff --git a/packages/reporter/package.json b/packages/reporter/package.json index 58e13194554d..ad9bd3d5e287 100644 --- a/packages/reporter/package.json +++ b/packages/reporter/package.json @@ -24,26 +24,29 @@ "babelify", { "presets": [ - "env", - "react", - "stage-1" + "@babel/env", + "@babel/react" ], "plugins": [ "add-module-exports", - "transform-decorators-legacy" + [ + "@babel/plugin-proposal-class-properties", + { + "loose": true + } + ] ] } ] ] }, "devDependencies": { + "@babel/plugin-proposal-decorators": "^7.0.0", + "@babel/preset-env": "^7.0.0", + "@babel/preset-react": "^7.0.0", "@cypress/react-tooltip": "0.3.1", "@cypress/releaser": "0.1.12", "babel-plugin-add-module-exports": "^0.2.1", - "babel-plugin-transform-decorators-legacy": "^1.3.4", - "babel-preset-env": "^1.6.1", - "babel-preset-react": "^6.24.1", - "babel-preset-stage-1": "^6.24.1", "bin-up": "^1.1.0", "chai": "^3.5.0", "chai-enzyme": "^0.8.0", @@ -64,6 +67,6 @@ "rebuild-node-sass": "^1.1.0", "sinon": "^1.17.4", "sinon-chai": "^2.8.0", - "zunder": "5.8.0" + "zunder": "5.8.2" } } From 15674727b4d06704b1d45d57f2bf41ec582e0876 Mon Sep 17 00:00:00 2001 From: Ben Kucera <14625260+Bkucera@users.noreply.github.com> Date: Wed, 24 Oct 2018 11:28:53 -0400 Subject: [PATCH 005/207] merge develop --- CONTRIBUTING.md | 6 +- DEPLOY.md | 11 +- circle.yml | 19 + cli/package.json | 12 +- cli/test/lib/exec/spawn_spec.js | 12 +- cli/types/tests/cypress-tests.ts | 2 +- package.json | 10 +- packages/coffee/package.json | 5 +- .../desktop-gui/cypress/fixtures/specs.json | 4 +- .../integration/specs_list_spec.coffee | 11 +- packages/desktop-gui/package.json | 7 +- packages/desktop-gui/src/app/nav.jsx | 1 - packages/desktop-gui/src/footer/footer.jsx | 2 +- .../desktop-gui/src/projects/projects-api.js | 3 +- packages/desktop-gui/src/specs/specs-list.jsx | 6 +- packages/desktop-gui/src/specs/specs-store.js | 21 +- packages/driver/package.json | 10 +- packages/driver/src/cy/actionability.coffee | 1 - .../src/cy/commands/actions/click.coffee | 88 ++--- packages/driver/src/cy/commands/clock.coffee | 2 + packages/driver/src/cy/commands/files.coffee | 3 +- .../driver/src/cy/commands/screenshot.coffee | 2 +- packages/driver/src/cy/timers.js | 133 +++++++ packages/driver/src/cypress/clock.coffee | 6 +- packages/driver/src/cypress/cy.coffee | 55 +-- packages/driver/src/cypress/native_events.js | 81 ----- packages/driver/src/cypress/runner.coffee | 6 +- packages/driver/src/cypress/server.coffee | 38 +- packages/driver/src/dom/coordinates.coffee | 18 +- .../test/cypress/fixtures/issue-599.html | 19 + .../integration/commands/clock_spec.coffee | 82 +++-- .../integration/commands/files_spec.coffee | 47 ++- .../integration/commands/task_spec.coffee | 2 +- .../integration/commands/xhr_spec.coffee | 21 ++ .../integration/cy/snapshot_spec.coffee | 2 +- .../cypress/integration/cy/timers_spec.js | 335 ++++++++++++++++++ .../cypress/integration/issues/599_spec.js | 7 + packages/driver/test/cypress/plugins/index.js | 12 + packages/electron/package.json | 5 + packages/example/package.json | 7 +- packages/extension/package.json | 7 + packages/https-proxy/package.json | 5 + .../https-proxy/test/helpers/proxy.coffee | 2 +- packages/launcher/package.json | 8 +- packages/reporter/cypress.json | 3 +- packages/reporter/lib/test-setup.js | 11 +- packages/reporter/package.json | 75 ++-- packages/reporter/scripts/build-dev.js | 1 + packages/reporter/scripts/build-prod.js | 4 +- .../reporter/scripts/set-zunder-config.js | 9 - .../reporter/src/commands/command.spec.jsx | 2 +- packages/reporter/src/errors/an-error.jsx | 2 +- .../reporter/src/errors/an-error.spec.jsx | 2 +- .../reporter/src/runnables/runnables.spec.jsx | 2 +- packages/reporter/src/test/test.spec.jsx | 4 +- packages/runner/lib/test-setup.js | 6 + packages/runner/package.json | 47 +-- packages/runner/scripts/set-zunder-config.js | 26 +- packages/runner/src/app/app.jsx | 2 +- packages/runner/src/app/app.spec.jsx | 51 ++- packages/runner/src/app/resizer.spec.jsx | 4 +- packages/runner/src/header/header.spec.jsx | 10 +- packages/runner/src/lib/dom.js | 70 ++-- .../4_return_value_spec.coffee.js | 6 - .../5_screenshots_spec.coffee.js | 10 +- .../__snapshots__/6_task_spec.coffee.js | 62 +++- .../__snapshots__/7_record_spec.coffee.js | 69 ++++ .../__snapshots__/cypress_spec.coffee.js | 15 +- packages/server/lib/browsers/chrome.coffee | 12 +- packages/server/lib/browsers/protocol.js | 53 --- packages/server/lib/controllers/proxy.coffee | 2 +- packages/server/lib/controllers/runner.coffee | 1 - packages/server/lib/controllers/xhrs.coffee | 2 +- packages/server/lib/errors.coffee | 4 + packages/server/lib/files.coffee | 6 +- packages/server/lib/modes/record.coffee | 6 +- packages/server/lib/modes/run.coffee | 8 +- .../server/lib/plugins/child/run_plugins.js | 11 + packages/server/lib/plugins/child/task.js | 15 +- packages/server/lib/saved_state.coffee | 3 +- packages/server/lib/socket.coffee | 2 +- packages/server/lib/task.coffee | 3 +- packages/server/lib/util/ci_provider.coffee | 121 +++++-- packages/server/lib/util/specs.coffee | 1 + packages/server/lib/util/trash.coffee | 11 +- packages/server/package.json | 42 ++- .../4_screenshot_fullpage_capture_spec.coffee | 3 +- .../5_screenshot_viewport_capture_spec.coffee | 3 +- packages/server/test/e2e/6_task_spec.coffee | 12 +- packages/server/test/e2e/7_record_spec.coffee | 18 + .../integration/http_requests_spec.coffee | 4 +- .../test/integration/server_spec.coffee | 48 +-- .../integration/screenshots_spec.coffee | 3 + .../projects/e2e/cypress/plugins/index.js | 13 +- .../multiple-task-registrations/cypress.json | 1 + .../multiple_task_registrations_spec.coffee | 4 + .../cypress/plugins/index.js | 11 + .../cypress/integration/.gitkeep | 0 .../cypress/integration/1.0/sample_spec.js | 0 .../server/test/unit/ci_provider_spec.coffee | 167 +++++++-- packages/server/test/unit/files_spec.coffee | 10 +- .../test/unit/plugins/child/task_spec.coffee | 6 + .../server/test/unit/screenshots_spec.coffee | 8 +- packages/server/test/unit/socket_spec.coffee | 12 +- packages/server/test/unit/specs_spec.coffee | 8 + packages/server/test/unit/task_spec.coffee | 6 + packages/server/test/unit/trash_spec.coffee | 35 ++ packages/socket/package.json | 6 +- packages/static/package.json | 4 + scripts/check-deps.js | 140 ++++++++ scripts/run-all.js | 2 + 111 files changed, 1808 insertions(+), 648 deletions(-) create mode 100644 packages/driver/src/cy/timers.js delete mode 100644 packages/driver/src/cypress/native_events.js create mode 100644 packages/driver/test/cypress/fixtures/issue-599.html create mode 100644 packages/driver/test/cypress/integration/cy/timers_spec.js create mode 100644 packages/driver/test/cypress/integration/issues/599_spec.js delete mode 100644 packages/server/lib/browsers/protocol.js create mode 100644 packages/server/test/support/fixtures/projects/multiple-task-registrations/cypress.json create mode 100644 packages/server/test/support/fixtures/projects/multiple-task-registrations/cypress/integration/multiple_task_registrations_spec.coffee create mode 100644 packages/server/test/support/fixtures/projects/multiple-task-registrations/cypress/plugins/index.js create mode 100644 packages/server/test/support/fixtures/projects/odd-directory-name/cypress/integration/.gitkeep create mode 100644 packages/server/test/support/fixtures/projects/odd-directory-name/cypress/integration/1.0/sample_spec.js create mode 100644 packages/server/test/unit/trash_spec.coffee create mode 100644 scripts/check-deps.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 054b593f3498..4a5165c41cd6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -186,7 +186,11 @@ This outputs a lot of debugging lines. To focus on an individual module, run wit When running `npm start` this routes through the CLI and eventually calls `npm run dev` with the proper arguments. This enables Cypress day-to-day development to match the logic of the built binary + CLI integration. -If you want to bypass the CLI entirely, you can use the `npm run dev` task and pass arguments directly. +If you want to bypass the CLI entirely, you can use the `npm run dev` task and pass arguments directly. For example to headlessly run a project in a given folder, while trying to record to the Dashboard + +```text +npm run dev -- --run-project /project/folder --record --key +``` #### Tasks diff --git a/DEPLOY.md b/DEPLOY.md index 933a89db3fd4..6964bc6b70e4 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -106,15 +106,14 @@ npm i https://cdn.../npm//hash/cypress.tgz $ npm publish https://cdn.../npm/1.0.5//cypress.tgz --tag dev + cypress@1.0.5 + - Check that the new version has the right tag using [available-versions](https://github.com/bahmutov/available-versions) -``` -$ vers cypress -0.20.1 16 days -0.20.2 3 days latest -1.0.5 a few seconds ago dev -``` + $ vers cypress + 0.20.1 16 days + 0.20.2 3 days latest + 1.0.5 a few seconds ago dev - Test `cypress@1.0.5` again to make sure everything is working. You can trigger test projects from command line (if you have the appropriate permissions) diff --git a/circle.yml b/circle.yml index 7d120c58bd72..c3014219fe84 100644 --- a/circle.yml +++ b/circle.yml @@ -367,6 +367,25 @@ jobs: - store_artifacts: path: /tmp/artifacts + "reporter-integration-tests": + <<: *defaults + steps: + - attach_workspace: + at: ~/ + - run: + command: npm run build-prod + working_directory: packages/reporter + - run: + command: | + CYPRESS_KONFIG_ENV=production \ + CYPRESS_RECORD_KEY=$PACKAGES_RECORD_KEY \ + npm run cypress:run -- --record --parallel --group reporter + working_directory: packages/reporter + - store_test_results: + path: /tmp/cypress + - store_artifacts: + path: /tmp/artifacts + "run-launcher": <<: *defaults steps: diff --git a/cli/package.json b/cli/package.json index 23b1e1e3bf3d..a9d5013e3c90 100644 --- a/cli/package.json +++ b/cli/package.json @@ -10,10 +10,15 @@ "node": ">=4.0.0" }, "scripts": { + "pretest": "npm run check-deps-pre", "test": "npm run test-unit", + "pretest-unit": "npm run check-deps-pre", "test-unit": "npm run dtslint && npm run unit", + "pretest-watch": "npm run check-deps-pre", "test-watch": "npm run unit -- --watch", - "test-dependencies": "bin-up deps-ok && dependency-check . --no-dev", + "check-deps": "node ../scripts/check-deps.js --verbose", + "check-deps-pre": "npm run check-deps -- --prescript", + "test-dependencies": "npm run check-deps && dependency-check . --no-dev", "test-debug": "node --inspect --debug-brk $(bin-up _mocha)", "test-cov": "nyc npm run unit", "unit": "BLUEBIRD_DEBUG=1 NODE_ENV=test bin-up mocha --reporter mocha-multi-reporters --reporter-options configFile=../mocha-reporter-config.json", @@ -39,7 +44,7 @@ "@types/bluebird": "3.5.18", "@types/chai": "4.0.8", "@types/chai-jquery": "1.1.35", - "@types/jquery": "3.2.16", + "@types/jquery": "3.3.6", "@types/lodash": "4.14.87", "@types/minimatch": "3.0.3", "@types/mocha": "2.2.44", @@ -92,8 +97,7 @@ "proxyquire": "2.0.1", "shelljs": "0.7.8", "sinon": "5.0.7", - "snap-shot-it": "^5.0.0", - "strip-ansi": "4.0.0" + "snap-shot-it": "^5.0.0" }, "files": [ "bin", diff --git a/cli/test/lib/exec/spawn_spec.js b/cli/test/lib/exec/spawn_spec.js index b4e85382c7a6..a74493ad8f6c 100644 --- a/cli/test/lib/exec/spawn_spec.js +++ b/cli/test/lib/exec/spawn_spec.js @@ -250,7 +250,7 @@ describe('lib/exec/spawn', function () { }) it('writes everything on win32', function () { - const buf1 = new Buffer('asdf') + const buf1 = Buffer.from('asdf') this.spawnedProcess.stdin.pipe.withArgs(process.stdin) this.spawnedProcess.stdout.pipe.withArgs(process.stdout) @@ -268,9 +268,9 @@ describe('lib/exec/spawn', function () { }) it('does not write to process.stderr when from xlib or libudev', function () { - const buf1 = new Buffer('Xlib: something foo') - const buf2 = new Buffer('libudev something bar') - const buf3 = new Buffer('asdf') + const buf1 = Buffer.from('Xlib: something foo') + const buf2 = Buffer.from('libudev something bar') + const buf3 = Buffer.from('asdf') this.spawnedProcess.stderr.on .withArgs('data') @@ -295,8 +295,8 @@ describe('lib/exec/spawn', function () { }) it('does not write to process.stderr when from high sierra warnings', function () { - const buf1 = new Buffer('2018-05-19 15:30:30.287 Cypress[7850:32145] *** WARNING: Textured Window') - const buf2 = new Buffer('asdf') + const buf1 = Buffer.from('2018-05-19 15:30:30.287 Cypress[7850:32145] *** WARNING: Textured Window') + const buf2 = Buffer.from('asdf') this.spawnedProcess.stderr.on .withArgs('data') diff --git a/cli/types/tests/cypress-tests.ts b/cli/types/tests/cypress-tests.ts index 90a3594df763..5ab955f9e78f 100644 --- a/cli/types/tests/cypress-tests.ts +++ b/cli/types/tests/cypress-tests.ts @@ -6,7 +6,7 @@ namespace CypressLodashTests { } namespace CypressJqueryTests { - Cypress.$ // $ExpectType JQueryStatic + Cypress.$ // $ExpectType JQueryStatic Cypress.$('selector') // $ExpectType JQuery Cypress.$('selector').click() // $ExpectType JQuery } diff --git a/package.json b/package.json index 9a07a26c5668..9baa11ac987c 100644 --- a/package.json +++ b/package.json @@ -8,17 +8,20 @@ "node": ">=8.2.1" }, "scripts": { + "prestart": "npm run check-deps-pre", "start": "node ./cli/bin/cypress open --dev --global", "cypress:open": "node ./cli/bin/cypress open --dev --global", "cypress:run": "node ./cli/bin/cypress run --dev", "dev": "node ./scripts/start.js", "watch": "npm run all watch", - "deps": "deps-ok", - "prebuild": "npm run deps", + "check-deps": "node ./scripts/check-deps.js --verbose", + "check-deps-pre": "node ./scripts/check-deps.js --verbose --prescript", + "prebuild": "npm run check-deps-pre", "build": "npm run all build", "all": "node ./scripts/run.js", "test": "echo '⚠️ This root monorepo is only for local development and new contributions. There are no tests.'", "link": "node ./scripts/link-packages.js", + "install-filtered": "npm run all install -- --package $(node ./scripts/check-deps.js --list)", "postinstall": "echo 'root postinstall' && npm run link && npm run all install && npm run build", "clean-deps": "npm run all clean-deps", "docker": "./scripts/run-docker-local.sh", @@ -61,6 +64,7 @@ "bluebird-retry": "^0.11.0", "chai": "^4.0.2", "chalk": "^2.0.1", + "check-dependencies": "1.1.0", "check-more-types": "^2.24.0", "cloudflare-cli": "^2.1.0", "coffeelint": "^1.16.0", @@ -69,7 +73,6 @@ "console.table": "^0.9.1", "debug": "3.1.0", "del": "^3.0.0", - "deps-ok": "^1.4.1", "electron-osx-sign": "^0.4.6", "eslint": "4.13.1", "eslint-plugin-cypress": "^2.0.1", @@ -109,6 +112,7 @@ "shelljs": "^0.7.8", "snap-shot-it": "^5.0.1", "stop-only": "2.1.0", + "strip-ansi": "4.0.0", "terminal-banner": "^1.0.0", "typescript": "^2.3.4", "vagrant": "0.0.1", diff --git a/packages/coffee/package.json b/packages/coffee/package.json index 229af8d324b3..9dec5d10c1f8 100644 --- a/packages/coffee/package.json +++ b/packages/coffee/package.json @@ -8,6 +8,7 @@ "files": [ "register.js" ], - "scripts": {}, - "devDependencies": {} + "scripts": { + "check-deps": "node ../../scripts/check-deps.js --verbose" + } } diff --git a/packages/desktop-gui/cypress/fixtures/specs.json b/packages/desktop-gui/cypress/fixtures/specs.json index d31b9cb0ff8e..5c0e5905ca0e 100644 --- a/packages/desktop-gui/cypress/fixtures/specs.json +++ b/packages/desktop-gui/cypress/fixtures/specs.json @@ -17,8 +17,8 @@ "relative": "cypress/integration/admin_users/admin_users_list_spec.coffee" }, { - "name": "admin_users/admin/foo_list_spec.coffee", - "relative": "cypress/integration/admin_users/admin/foo_list_spec.coffee" + "name": "admin_users/admin.user/foo_list_spec.coffee", + "relative": "cypress/integration/admin_users/admin.user/foo_list_spec.coffee" } ], "unit": [ diff --git a/packages/desktop-gui/cypress/integration/specs_list_spec.coffee b/packages/desktop-gui/cypress/integration/specs_list_spec.coffee index 340688daa679..f84fc4abd963 100644 --- a/packages/desktop-gui/cypress/integration/specs_list_spec.coffee +++ b/packages/desktop-gui/cypress/integration/specs_list_spec.coffee @@ -150,6 +150,10 @@ describe "Specs List", -> it "lists test specs", -> cy.get(".file a").contains("app_spec.coffee") + it "lists folder with '.'", -> + cy.get(".file").should("have.length", 7) + cy.get(".folder").should("have.length", 10) + context "collapsing specs", -> it "sets folder collapsed when clicked", -> cy.get(".folder:first").should("have.class", "folder-expanded") @@ -238,14 +242,14 @@ describe "Specs List", -> it "saves the filter to local storage for the project", -> cy.window().then (win) => - expect(win.localStorage["specsFilter-#{@config.projectId}"]).to.be.a("string") - expect(JSON.parse(win.localStorage["specsFilter-#{@config.projectId}"])).to.equal("new") + expect(win.localStorage["specsFilter-#{@config.projectId}-/foo/bar"]).to.be.a("string") + expect(JSON.parse(win.localStorage["specsFilter-#{@config.projectId}-/foo/bar"])).to.equal("new") describe "when there's a saved filter", -> beforeEach -> @ipc.getSpecs.yields(null, @specs) cy.window().then (win) -> - win.localStorage["specsFilter-#{@config.projectId}"] = JSON.stringify("app") + win.localStorage["specsFilter-#{@config.projectId}-/foo/bar"] = JSON.stringify("app") it "applies it for the appropriate project", -> @openProject.resolve(@config) @@ -256,7 +260,6 @@ describe "Specs List", -> @openProject.resolve(@config) cy.get(".filter").should("have.value", "") - context "click on spec", -> beforeEach -> @ipc.getSpecs.yields(null, @specs) diff --git a/packages/desktop-gui/package.json b/packages/desktop-gui/package.json index 9989d495b7e7..3eb5ef39334b 100644 --- a/packages/desktop-gui/package.json +++ b/packages/desktop-gui/package.json @@ -5,9 +5,14 @@ "private": true, "scripts": { "postinstall": "echo '@packages/desktop-gui needs: npm run build'", + "prebuild": "npm run check-deps-pre", "build": "node ./scripts/build-dev.js", + "prebuild-prod": "npm run check-deps-pre", "build-prod": "node ./scripts/build-prod.js", + "prewatch": "npm run check-deps-pre", "watch": "node ./scripts/watch.js", + "check-deps": "node ../../scripts/check-deps.js --verbose", + "check-deps-pre": "npm run check-deps -- --prescript", "clean": "zunder clean", "clean-deps": "rm -rf node_modules", "lint": "$(bin-up eslint) --fix lib/*.js src/*.js* src/**/*.js*", @@ -44,6 +49,6 @@ "react-bootstrap-modal": "3.0.1", "react-dom": "^15.6.1", "react-loader": "^2.4.0", - "zunder": "5.8.2" + "zunder": "6.1.1" } } diff --git a/packages/desktop-gui/src/app/nav.jsx b/packages/desktop-gui/src/app/nav.jsx index 63371a3b89c5..918e688143ec 100644 --- a/packages/desktop-gui/src/app/nav.jsx +++ b/packages/desktop-gui/src/app/nav.jsx @@ -72,7 +72,6 @@ export default class Nav extends Component { return (
- Beta
) } diff --git a/packages/desktop-gui/src/footer/footer.jsx b/packages/desktop-gui/src/footer/footer.jsx index ce76e9ac9089..90751e7a6ed8 100644 --- a/packages/desktop-gui/src/footer/footer.jsx +++ b/packages/desktop-gui/src/footer/footer.jsx @@ -9,7 +9,7 @@ export default class Footer extends Component {