Skip to content

Commit

Permalink
remove Cypress object proxying related code for certain utils (#7486)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuceb authored May 27, 2020
1 parent c392ac8 commit 50cdd67
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 57 deletions.
12 changes: 6 additions & 6 deletions packages/driver/src/cy/commands/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,14 +917,14 @@ module.exports = (Commands, Cypress, cy, state, config) => {
// state for like scrollTop
let s = {
currentId: id,
tests: Cypress.getTestsState(),
startTime: Cypress.getStartTime(),
emissions: Cypress.getEmissions(),
tests: Cypress.runner.getTestsState(),
startTime: Cypress.runner.getStartTime(),
emissions: Cypress.runner.getEmissions(),
}

s.passed = Cypress.countByTestState(s.tests, 'passed')
s.failed = Cypress.countByTestState(s.tests, 'failed')
s.pending = Cypress.countByTestState(s.tests, 'pending')
s.passed = Cypress.runner.countByTestState(s.tests, 'passed')
s.failed = Cypress.runner.countByTestState(s.tests, 'failed')
s.pending = Cypress.runner.countByTestState(s.tests, 'pending')
s.numLogs = $Log.countLogsByTests(s.tests)

return Cypress.action('cy:collect:run:state')
Expand Down
17 changes: 0 additions & 17 deletions packages/driver/src/cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ const browserInfo = require('./cypress/browser')
const resolvers = require('./cypress/resolvers')
const debug = require('debug')('cypress:driver:cypress')

const proxies = {
runner: 'getStartTime getTestsState getEmissions setNumLogs countByTestState getDisplayPropsForLog getConsolePropsForLogById getSnapshotPropsForLogById getErrorByTestId setStartTime resumeAtTest normalizeAll'.split(' '),
cy: 'detachDom getStyles'.split(' '),
}

const jqueryProxyFn = function (...args) {
if (!this.cy) {
$errUtils.throwErrByPath('miscellaneous.no_cy')
Expand Down Expand Up @@ -624,18 +619,6 @@ $Cypress.prototype.minimatch = minimatch
$Cypress.prototype.sinon = sinon
$Cypress.prototype.lolex = lolex

// proxy all of the methods in proxies
// to their corresponding objects
_.each(proxies, (methods, key) => {
return _.each(methods, (method) => {
return $Cypress.prototype[method] = function (...args) {
const prop = this[key]

return prop && prop[method].apply(prop, args)
}
})
})

// attaching these so they are accessible
// via the runner + integration spec helper
$Cypress.$ = $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,11 @@ describe('src/cy/commands/navigation', () => {
beforeEach(() => {
Cypress.emit('test:before:run', { id: 888 })

cy.stub(Cypress, 'getEmissions').returns([])
cy.stub(Cypress, 'getTestsState').returns([])
cy.stub(Cypress, 'getStartTime').returns('12345')
cy.stub(Cypress.runner, 'getEmissions').returns([])
cy.stub(Cypress.runner, 'getTestsState').returns([])
cy.stub(Cypress.runner, 'getStartTime').returns('12345')
cy.stub(Cypress.Log, 'countLogsByTests').withArgs([]).returns(1)
cy.stub(Cypress, 'countByTestState')
cy.stub(Cypress.runner, 'countByTestState')
.withArgs([], 'passed').returns(2)
.withArgs([], 'failed').returns(3)
.withArgs([], 'pending').returns(4)
Expand Down Expand Up @@ -952,7 +952,7 @@ describe('src/cy/commands/navigation', () => {

describe('.log', () => {
beforeEach(function () {
cy.stub(Cypress, 'getEmissions').returns([])
cy.stub(Cypress.runner, 'getEmissions').returns([])

this.logs = []

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
declare namespace Cypress {
interface cy {
state(key: 'document'): Document
}
}

describe('src/dom/coordinates', () => {
const $ = Cypress.$.bind(Cypress)
let doc: Document
Expand Down
6 changes: 0 additions & 6 deletions packages/driver/test/cypress/integration/dom/elements_spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
declare namespace Cypress {
interface cy {
state(key: 'window'): Window
}
}

describe('src/dom/elements', () => {
const $ = Cypress.$.bind(Cypress)

Expand Down
15 changes: 9 additions & 6 deletions packages/driver/ts/internal-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ declare namespace Cypress {
// TODO: how to pull these from resolvers.ts? can't import in a d.ts file...
resolveWindowReference: any
resolveLocationReference: any
state: Cypress.state
}

/**
* Access and set Cypress's internal state.
*/
state: State
// Cypress.state is also accessible on cy.state
interface cy {
state: Cypress.State
}

interface State {
(k: '$autIframe', v?: JQuery<HTMLIFrameElement>): JQuery<HTMLIFrameElement> | undefined
// Extend Cypress.state properties here
interface ResolvedConfigOptions {
$autIframe: JQuery<HTMLIFrameElement>
document: Document
}
}
4 changes: 2 additions & 2 deletions packages/runner/src/iframe/aut-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export default class AutIframe {

if (!Cypress) return

return Cypress.detachDom(this._contents())
return Cypress.cy.detachDom(this._contents())
}

restoreDom = (snapshot) => {
const Cypress = eventManager.getCypress()
const { headStyles, bodyStyles } = Cypress ? Cypress.getStyles(snapshot) : {}
const { headStyles, bodyStyles } = Cypress ? Cypress.cy.getStyles(snapshot) : {}
const { body, htmlAttrs } = snapshot
const contents = this._contents()
const $html = contents.find('html')
Expand Down
18 changes: 9 additions & 9 deletions packages/runner/src/lib/event-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const eventManager = {
})

const logCommand = (logId) => {
const consoleProps = Cypress.getConsolePropsForLogById(logId)
const consoleProps = Cypress.runner.getConsolePropsForLogById(logId)

logger.logFormatted(consoleProps)
}
Expand Down Expand Up @@ -111,7 +111,7 @@ const eventManager = {
function sendEventIfSnapshotProps (logId, event) {
if (!Cypress) return

const snapshotProps = Cypress.getSnapshotPropsForLogById(logId)
const snapshotProps = Cypress.runner.getSnapshotPropsForLogById(logId)

if (snapshotProps) {
localBus.emit(event, snapshotProps)
Expand Down Expand Up @@ -217,7 +217,7 @@ const eventManager = {
// get the current runnable in case we reran mid-test due to a visit
// to a new domain
ws.emit('get:existing:run:state', (state = {}) => {
const runnables = Cypress.normalizeAll(state.tests)
const runnables = Cypress.runner.normalizeAll(state.tests)
const run = () => {
performance.mark('initialize-end')
performance.measure('initialize', 'initialize-start', 'initialize-end')
Expand All @@ -228,18 +228,18 @@ const eventManager = {
reporterBus.emit('runnables:ready', runnables)

if (state.numLogs) {
Cypress.setNumLogs(state.numLogs)
Cypress.runner.setNumLogs(state.numLogs)
}

if (state.startTime) {
Cypress.setStartTime(state.startTime)
Cypress.runner.setStartTime(state.startTime)
}

if (state.currentId) {
// if we have a currentId it means
// we need to tell the Cypress to skip
// ahead to that test
Cypress.resumeAtTest(state.currentId, state.emissions)
Cypress.runner.resumeAtTest(state.currentId, state.emissions)
}

if (config.isTextTerminal && !state.currentId) {
Expand Down Expand Up @@ -270,13 +270,13 @@ const eventManager = {
})

Cypress.on('log:added', (log) => {
const displayProps = Cypress.getDisplayPropsForLog(log)
const displayProps = Cypress.runner.getDisplayPropsForLog(log)

reporterBus.emit('reporter:log:add', displayProps)
})

Cypress.on('log:changed', (log) => {
const displayProps = Cypress.getDisplayPropsForLog(log)
const displayProps = Cypress.runner.getDisplayPropsForLog(log)

reporterBus.emit('reporter:log:state:changed', displayProps)
})
Expand Down Expand Up @@ -340,7 +340,7 @@ const eventManager = {

reporterBus.emit('reporter:start', {
firefoxGcInterval: Cypress.getFirefoxGcInterval(),
startTime: Cypress.getStartTime(),
startTime: Cypress.runner.getStartTime(),
numPassed: state.passed,
numFailed: state.failed,
numPending: state.pending,
Expand Down

4 comments on commit 50cdd67

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 50cdd67 May 27, 2020

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/linux-x64/circle-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-339284/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/circle-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-339180/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 50cdd67 May 27, 2020

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-ia32/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.7.1/win32-ia32/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-ia32/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-ia32/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 50cdd67 May 27, 2020

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-x64/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.7.1/win32-x64/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-x64/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/win32-x64/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.7.1/appveyor-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-33156777/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 50cdd67 May 27, 2020

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.7.1/darwin-x64/circle-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-339317/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.7.1/circle-develop-50cdd67a76628b77c4883425c132e7a0a5133fd1-339306/cypress.tgz

Please sign in to comment.