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

fix: stop running spec when switching specs #21038

Merged
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
11 changes: 11 additions & 0 deletions packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,15 @@ describe('Cypress In Cypress E2E', { viewportWidth: 1500, defaultCommandTimeout:
cy.get('#unified-runner').should('have.css', 'width', '333px')
cy.get('#unified-runner').should('have.css', 'height', '333px')
})

it('stops correctly running spec while switching specs', () => {
cy.visitApp()
cy.contains('withFailure.spec').click()
cy.contains('switch spec')
cy.contains('withWait.spec').click()

cy.wait(5000)
cy.get('.passed > .num').should('contain', 4)
cy.get('.failed > .num').should('not.contain', 1)
})
})
2 changes: 1 addition & 1 deletion packages/app/cypress/e2e/reporter_header.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Reporter Header', () => {
})

cy.get('[data-selected-spec="true"]').should('contain', 'dom-content').should('have.length', '1')
cy.get('[data-selected-spec="false"]').should('have.length', '4')
cy.get('[data-selected-spec="false"]').should('have.length', '6')
})

it('filters the list of specs when searching for specs', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/app/cypress/e2e/runner/runner.ui.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ describe('src/cypress/runner', () => {
})

cy.get('.runnable-err-message').should('not.contain', 'ran afterEach even though specs were stopped')
cy.get('.runnable-err-message').should('contain', 'Cypress test was stopped while running this command.')
})

// TODO: blocked by UNIFY-1077
Expand Down
6 changes: 3 additions & 3 deletions packages/app/cypress/e2e/specs_list_e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ describe('App: Spec List (E2E)', () => {
})

it('allows you to search and filter the list of specs in the list', () => {
cy.get('button').contains('4 Matches')
cy.get('button').contains('6 Matches')

cy.get('input').type('content', { force: true })

cy.get('[data-cy="spec-item"]').should('have.length', 2)
.should('contain', 'dom-content.spec.js')

cy.get('button').contains('2 of 4 Matches')
cy.get('button').contains('2 of 6 Matches')

cy.get('input').clear().type('asdf', { force: true })

cy.get('[data-cy="spec-item"]').should('have.length', 0)

cy.get('button').contains('0 of 4 Matches')
cy.get('button').contains('0 of 6 Matches')
})

it('shows a git status for each spec', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('specChange subscription', () => {
describe('specs list', () => {
it('responds to specChange event for an added file', () => {
cy.get('[data-cy="spec-item-link"]')
.should('have.length', 4)
.should('have.length', 6)
.should('contain', 'blank-contents.spec.js')
.should('contain', 'dom-container.spec.js')
.should('contain', 'dom-content.spec.js')
Expand All @@ -27,7 +27,7 @@ describe('specChange subscription', () => {
}, { path: getPathForPlatform('cypress/e2e/new-file.spec.js') })

cy.get('[data-cy="spec-item-link"]')
.should('have.length', 5)
.should('have.length', 7)
.should('contain', 'blank-contents.spec.js')
.should('contain', 'dom-container.spec.js')
.should('contain', 'dom-content.spec.js')
Expand All @@ -37,7 +37,7 @@ describe('specChange subscription', () => {

it('responds to specChange event for a removed file', () => {
cy.get('[data-cy="spec-item-link"]')
.should('have.length', 4)
.should('have.length', 6)
.should('contain', 'blank-contents.spec.js')
.should('contain', 'dom-container.spec.js')
.should('contain', 'dom-content.spec.js')
Expand All @@ -48,7 +48,7 @@ describe('specChange subscription', () => {
}, { path: getPathForPlatform('cypress/e2e/dom-list.spec.js') })

cy.get('[data-cy="spec-item-link"]')
.should('have.length', 3)
.should('have.length', 5)
.should('contain', 'blank-contents.spec.js')
.should('contain', 'dom-container.spec.js')
.should('contain', 'dom-content.spec.js')
Expand All @@ -63,6 +63,8 @@ describe('specChange subscription', () => {
getPathForPlatform('cypress/e2e/dom-container.spec.js'),
getPathForPlatform('cypress/e2e/dom-content.spec.js'),
getPathForPlatform('cypress/e2e/dom-list.spec.js'),
getPathForPlatform('cypress/e2e/withFailure.spec.js'),
getPathForPlatform('cypress/e2e/withWait.spec.js'),
],
})

Expand All @@ -86,6 +88,8 @@ describe('specChange subscription', () => {
getPathForPlatform('cypress/e2e/blank-contents.spec.js'),
getPathForPlatform('cypress/e2e/dom-container.spec.js'),
getPathForPlatform('cypress/e2e/dom-content.spec.js'),
getPathForPlatform('cypress/e2e/withFailure.spec.js'),
getPathForPlatform('cypress/e2e/withWait.spec.js'),
],
})

Expand All @@ -103,7 +107,7 @@ describe('specChange subscription', () => {

it('responds to a cypress.config.js file change', () => {
cy.get('[data-cy="spec-item-link"]')
.should('have.length', 4)
.should('have.length', 6)
.should('contain', 'blank-contents.spec.js')
.should('contain', 'dom-container.spec.js')
.should('contain', 'dom-content.spec.js')
Expand Down Expand Up @@ -144,7 +148,7 @@ module.exports = {
cy.get('[data-model-state="passed"]').should('contain', 'renders the test content')

cy.get('[data-testid="spec-file-item"]')
.should('have.length', 4)
.should('have.length', 6)
.should('contain', 'blank-contents.spec.js')
.should('contain', 'dom-container.spec.js')
.should('contain', 'dom-content.spec.js')
Expand All @@ -155,7 +159,7 @@ module.exports = {
}, { path: getPathForPlatform('cypress/e2e/new-file.spec.js') })

cy.get('[data-testid="spec-file-item"]')
.should('have.length', 5)
.should('have.length', 7)
.should('contain', 'blank-contents.spec.js')
.should('contain', 'dom-container.spec.js')
.should('contain', 'dom-content.spec.js')
Expand All @@ -168,7 +172,7 @@ module.exports = {
cy.get('[data-model-state="passed"]').should('contain', 'renders the test content')

cy.get('[data-testid="spec-file-item"]')
.should('have.length', 4)
.should('have.length', 6)
.should('contain', 'blank-contents.spec.js')
.should('contain', 'dom-container.spec.js')
.should('contain', 'dom-content.spec.js')
Expand All @@ -179,7 +183,7 @@ module.exports = {
}, { path: getPathForPlatform('cypress/e2e/dom-list.spec.js') })

cy.get('[data-testid="spec-file-item"]')
.should('have.length', 3)
.should('have.length', 5)
.should('contain', 'blank-contents.spec.js')
.should('contain', 'dom-container.spec.js')
.should('contain', 'dom-content.spec.js')
Expand All @@ -196,6 +200,8 @@ module.exports = {
getPathForPlatform('cypress/e2e/blank-contents.spec.js'),
getPathForPlatform('cypress/e2e/dom-container.spec.js'),
getPathForPlatform('cypress/e2e/dom-list.spec.js'),
getPathForPlatform('cypress/e2e/withFailure.spec.js'),
getPathForPlatform('cypress/e2e/withWait.spec.js'),
],
})

Expand All @@ -216,7 +222,7 @@ module.exports = {
cy.get('[data-model-state="passed"]').should('contain', 'renders the test content')

cy.get('[data-testid="spec-file-item"]')
.should('have.length', 4)
.should('have.length', 6)
.should('contain', 'blank-contents.spec.js')
.should('contain', 'dom-container.spec.js')
.should('contain', 'dom-content.spec.js')
Expand Down Expand Up @@ -259,14 +265,14 @@ module.exports = {
cy.get('[data-cy="spec-pattern"]').contains('cypress/e2e/**/*.spec.{js,ts}')

cy.get('[data-cy="file-match-indicator"]')
.should('contain', '4 Matches')
.should('contain', '6 Matches')

cy.withCtx(async (ctx, o) => {
await ctx.actions.file.writeFileInProject(o.path, '')
}, { path: getPathForPlatform('cypress/e2e/new-file.spec.js') })

cy.get('[data-cy="file-match-indicator"]')
.should('contain', '5 Matches')
.should('contain', '7 Matches')
})

it('responds to specChange event for a removed file', () => {
Expand All @@ -276,14 +282,14 @@ module.exports = {
cy.get('[data-cy="spec-pattern"]').contains('cypress/e2e/**/*.spec.{js,ts}')

cy.get('[data-cy="file-match-indicator"]')
.should('contain', '4 Matches')
.should('contain', '6 Matches')

cy.withCtx(async (ctx, o) => {
await ctx.actions.file.removeFileInProject(o.path)
}, { path: getPathForPlatform('cypress/e2e/dom-list.spec.js') })

cy.get('[data-cy="file-match-indicator"]')
.should('contain', '3 Matches')
.should('contain', '5 Matches')
})

it('handles removing the last file', () => {
Expand All @@ -299,6 +305,8 @@ module.exports = {
getPathForPlatform('cypress/e2e/blank-contents.spec.js'),
getPathForPlatform('cypress/e2e/dom-container.spec.js'),
getPathForPlatform('cypress/e2e/dom-content.spec.js'),
getPathForPlatform('cypress/e2e/withFailure.spec.js'),
getPathForPlatform('cypress/e2e/withWait.spec.js'),
],
})

Expand All @@ -320,7 +328,7 @@ module.exports = {
cy.get('[data-cy="spec-pattern"]').contains('cypress/e2e/**/*.spec.{js,ts}')

cy.get('[data-cy="file-match-indicator"]')
.should('contain', '4 Matches')
.should('contain', '6 Matches')

cy.withCtx(async (ctx) => {
await ctx.actions.file.writeFileInProject('cypress.config.js',
Expand Down
1 change: 1 addition & 0 deletions packages/driver/src/cypress/error_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ export default {
retry_timed_out ({ ms }) {
return `Timed out retrying after ${ms}ms: `
},
test_stopped: 'Cypress test was stopped while running this command.',
},

mocha: {
Expand Down
11 changes: 5 additions & 6 deletions packages/driver/src/cypress/mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ const patchSuiteAddSuite = (specWindow, config) => {
const patchRunnableResetTimeout = () => {
Runnable.prototype.resetTimeout = function () {
const runnable = this
// @ts-ignore Cypress.runner is not defined
const currentRunner = Cypress.runner

const ms = this.timeout() || 1e9

Expand All @@ -410,15 +412,12 @@ const patchRunnableResetTimeout = () => {
return 'mocha.async_timed_out'
}

// TODO: improve this error message. It's not that
// a command necessarily timed out - in fact this is
// a mocha timeout, and a command likely *didn't*
// time out correctly, so we received this message instead.
return 'mocha.timed_out'
return 'miscellaneous.test_stopped'
}

this.timer = setTimeout(() => {
if (runnable.state === 'passed') {
// @ts-ignore Cypress.runner is not defined
if (runnable.state === 'passed' || Cypress.runner !== currentRunner) {
// this timeout can be reached at the same time that a
// user does an asynchronous `done`, so double-check
// that the test has not already passed before timing out
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe('withFailure', () => {
it('fails', () => {
expect(true).to.eq(false)
})

it('passes', () => {
expect(true).to.eq(true)
})

it('passes with delay', () => {
cy.log('switch spec')
cy.wait(3000)
expect(true).to.eq(true)
})

it('passes again', () => {
expect(true).to.eq(true)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
describe('withWait', () => {
it('passes', () => {
cy.wait(2000)
expect(true).to.eq(true)
})

it('passes', () => {
cy.wait(2000)
expect(true).to.eq(true)
})

it('passes', () => {
cy.wait(2000)
expect(true).to.eq(true)
})

it('passes', () => {
cy.wait(2000)
expect(true).to.eq(true)
})
})