remove Cypress object proxying related code for certain utils (#7486)

This commit is contained in:
Ben Kucera
2020-05-27 15:39:29 -04:00
committed by GitHub
parent c392ac82fd
commit 50cdd67a76
8 changed files with 32 additions and 58 deletions

View File

@@ -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')

View File

@@ -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')
@@ -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.$ = $

View File

@@ -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)
@@ -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 = []

View File

@@ -1,9 +1,3 @@
declare namespace Cypress {
interface cy {
state(key: 'document'): Document
}
}
describe('src/dom/coordinates', () => {
const $ = Cypress.$.bind(Cypress)
let doc: Document

View File

@@ -1,9 +1,3 @@
declare namespace Cypress {
interface cy {
state(key: 'window'): Window
}
}
describe('src/dom/elements', () => {
const $ = Cypress.$.bind(Cypress)

View File

@@ -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
/**
* Access and set Cypress's internal state.
*/
state: State
state: Cypress.state
}
interface State {
(k: '$autIframe', v?: JQuery<HTMLIFrameElement>): JQuery<HTMLIFrameElement> | undefined
// Cypress.state is also accessible on cy.state
interface cy {
state: Cypress.State
}
// Extend Cypress.state properties here
interface ResolvedConfigOptions {
$autIframe: JQuery<HTMLIFrameElement>
document: Document
}
}

View File

@@ -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')

View File

@@ -74,7 +74,7 @@ const eventManager = {
})
const logCommand = (logId) => {
const consoleProps = Cypress.getConsolePropsForLogById(logId)
const consoleProps = Cypress.runner.getConsolePropsForLogById(logId)
logger.logFormatted(consoleProps)
}
@@ -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)
@@ -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')
@@ -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) {
@@ -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)
})
@@ -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,