Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Cypress object proxying related code for certain utils #7486

Merged
merged 8 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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