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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runner): Cannot set property 'err' of undefined on spec rerun due to file changes #8193

Merged
merged 3 commits into from Aug 6, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/driver/src/cypress/runner.js
Expand Up @@ -832,7 +832,6 @@ const create = (specWindow, mocha, Cypress, cy) => {
}

// hold onto the _runnables for faster lookup later
let _stopped = false
let _test = null
let _tests = []
let _testsById = {}
Expand Down Expand Up @@ -932,8 +931,13 @@ const create = (specWindow, mocha, Cypress, cy) => {

return _runner.run((failures) => {
// if we happen to make it all the way through
// the run, then just set _stopped to true here
_stopped = true
// the run, then just set _runner.stopped to true here
_runner.stopped = true

// remove all the listeners
// so no more events fire
// since a test failure may 'leak' after a run completes
_runner.removeAllListeners()

// TODO this functions is not correctly
// synchronized with the 'end' event that
Expand Down Expand Up @@ -1183,11 +1187,11 @@ const create = (specWindow, mocha, Cypress, cy) => {
},

stop () {
if (_stopped) {
if (_runner.stopped) {
return
}

_stopped = true
_runner.stopped = true

// abort the run
_runner.abort()
Expand All @@ -1200,7 +1204,7 @@ const create = (specWindow, mocha, Cypress, cy) => {

// remove all the listeners
// so no more events fire
return _runner.removeAllListeners()
_runner.removeAllListeners()
},

getDisplayPropsForLog: $Log.getDisplayProps,
Expand Down
31 changes: 31 additions & 0 deletions packages/runner/cypress/integration/reporter.hooks.spec.js
Expand Up @@ -119,4 +119,35 @@ describe('hooks', function () {
})
})
})

// https://github.com/cypress-io/cypress/issues/8189
it('can rerun without timeout error leaking into next run (due to run restart)', () => {
runIsolatedCypress(() => {
const top = window.parent

top.count = top.count || 0

Cypress.config('defaultCommandTimeout', 50)
afterEach(function () {
assert(true, `run ${top.count}`)
})

describe('s1', () => {
it('foo', () => {
cy.once('test:after:run', () => {
if (!top.count) {
requestAnimationFrame(() => {
window.parent.eventManager.reporterBus.emit('runner:restart')
})
}

top.count++
})
})
})
})

// wait until spec has run twice (due to one reload)
cy.window().its('count').should('eq', 2)
})
})
11 changes: 8 additions & 3 deletions packages/runner/cypress/support/helpers.js
Expand Up @@ -188,9 +188,14 @@ function createCypress () {
})
})

cy.spy(cy.state('window').console, 'log').as('console_log')
cy.spy(cy.state('window').console, 'error').as('console_error')

// TODO: clean this up, sinon doesn't like wrapping things multiple times
// and this catches that error
try {
cy.spy(cy.state('window').console, 'log').as('console_log')
cy.spy(cy.state('window').console, 'error').as('console_error')
} catch (_e) {
// console was already wrapped, noop
}
onInitializedListeners.forEach((fn) => fn(autCypress))
onInitializedListeners = []

Expand Down