From f12cce3811df126342d19d34801c6648e79e5d24 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 11 Apr 2022 22:02:23 -0500 Subject: [PATCH 1/4] Add failing test --- .../cypress/e2e/cypress-in-cypress-e2e.cy.ts | 11 ++++++++++ .../cypress/e2e/withFailure.spec.js | 19 +++++++++++++++++ .../cypress/e2e/withWait.spec.js | 21 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 system-tests/projects/cypress-in-cypress/cypress/e2e/withFailure.spec.js create mode 100644 system-tests/projects/cypress-in-cypress/cypress/e2e/withWait.spec.js diff --git a/packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts b/packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts index 4f0b68efacf3..e5b58ebcf38b 100644 --- a/packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts +++ b/packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts @@ -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('fails if spec with failed test is running 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) + }) }) diff --git a/system-tests/projects/cypress-in-cypress/cypress/e2e/withFailure.spec.js b/system-tests/projects/cypress-in-cypress/cypress/e2e/withFailure.spec.js new file mode 100644 index 000000000000..ab2a6a5ba12d --- /dev/null +++ b/system-tests/projects/cypress-in-cypress/cypress/e2e/withFailure.spec.js @@ -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) + }) +}) diff --git a/system-tests/projects/cypress-in-cypress/cypress/e2e/withWait.spec.js b/system-tests/projects/cypress-in-cypress/cypress/e2e/withWait.spec.js new file mode 100644 index 000000000000..aa5e8c5088c3 --- /dev/null +++ b/system-tests/projects/cypress-in-cypress/cypress/e2e/withWait.spec.js @@ -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) + }) +}) From df709742ca5ca10609f7088856761ab49b601fdc Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 12 Apr 2022 11:51:03 -0500 Subject: [PATCH 2/4] Update mocha patch --- packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts | 2 +- packages/driver/src/cypress/mocha.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts b/packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts index e5b58ebcf38b..9e2758b64661 100644 --- a/packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts +++ b/packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts @@ -168,7 +168,7 @@ describe('Cypress In Cypress E2E', { viewportWidth: 1500, defaultCommandTimeout: cy.get('#unified-runner').should('have.css', 'height', '333px') }) - it('fails if spec with failed test is running while switching specs', () => { + it('stops correctly running spec while switching specs', () => { cy.visitApp() cy.contains('withFailure.spec').click() cy.contains('switch spec') diff --git a/packages/driver/src/cypress/mocha.ts b/packages/driver/src/cypress/mocha.ts index 26fa88859142..5bfb9ee072b2 100644 --- a/packages/driver/src/cypress/mocha.ts +++ b/packages/driver/src/cypress/mocha.ts @@ -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 @@ -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' } this.timer = setTimeout(() => { - if (runnable.state === 'passed') { + // @ts-ignore Cypress.runner is not defined + if (runnable.state === 'passed' || Cypress.runner !== currentRunner || Cypress.state('canceled')) { // 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 From facc9ffc119814a1407550ec775896961710421a Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 12 Apr 2022 12:51:09 -0500 Subject: [PATCH 3/4] Update tests --- .../specChange-subscription.cy.ts | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/packages/app/cypress/e2e/subscriptions/specChange-subscription.cy.ts b/packages/app/cypress/e2e/subscriptions/specChange-subscription.cy.ts index eecd9313b0d9..27d95a913c15 100644 --- a/packages/app/cypress/e2e/subscriptions/specChange-subscription.cy.ts +++ b/packages/app/cypress/e2e/subscriptions/specChange-subscription.cy.ts @@ -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') @@ -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') @@ -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') @@ -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') @@ -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'), ], }) @@ -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'), ], }) @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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'), ], }) @@ -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') @@ -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', () => { @@ -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', () => { @@ -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'), ], }) @@ -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', From 0849d7b13f17f54e62b9c13f744a7b0fed6d7cd1 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 12 Apr 2022 14:18:56 -0500 Subject: [PATCH 4/4] Update error message/fix tests --- packages/app/cypress/e2e/reporter_header.cy.ts | 2 +- packages/app/cypress/e2e/runner/runner.ui.cy.ts | 1 + packages/app/cypress/e2e/specs_list_e2e.cy.ts | 6 +++--- packages/driver/src/cypress/error_messages.ts | 1 + packages/driver/src/cypress/mocha.ts | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/app/cypress/e2e/reporter_header.cy.ts b/packages/app/cypress/e2e/reporter_header.cy.ts index f847b6c0425e..67e04e5138dc 100644 --- a/packages/app/cypress/e2e/reporter_header.cy.ts +++ b/packages/app/cypress/e2e/reporter_header.cy.ts @@ -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', () => { diff --git a/packages/app/cypress/e2e/runner/runner.ui.cy.ts b/packages/app/cypress/e2e/runner/runner.ui.cy.ts index cf201004e4cc..eb328524c8fa 100644 --- a/packages/app/cypress/e2e/runner/runner.ui.cy.ts +++ b/packages/app/cypress/e2e/runner/runner.ui.cy.ts @@ -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 diff --git a/packages/app/cypress/e2e/specs_list_e2e.cy.ts b/packages/app/cypress/e2e/specs_list_e2e.cy.ts index 3c6622c01516..7b8c4641155d 100644 --- a/packages/app/cypress/e2e/specs_list_e2e.cy.ts +++ b/packages/app/cypress/e2e/specs_list_e2e.cy.ts @@ -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', () => { diff --git a/packages/driver/src/cypress/error_messages.ts b/packages/driver/src/cypress/error_messages.ts index 17b971203f8c..12f59c634349 100644 --- a/packages/driver/src/cypress/error_messages.ts +++ b/packages/driver/src/cypress/error_messages.ts @@ -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: { diff --git a/packages/driver/src/cypress/mocha.ts b/packages/driver/src/cypress/mocha.ts index 5bfb9ee072b2..dc911519d429 100644 --- a/packages/driver/src/cypress/mocha.ts +++ b/packages/driver/src/cypress/mocha.ts @@ -412,12 +412,12 @@ const patchRunnableResetTimeout = () => { return 'mocha.async_timed_out' } - return 'mocha.timed_out' + return 'miscellaneous.test_stopped' } this.timer = setTimeout(() => { // @ts-ignore Cypress.runner is not defined - if (runnable.state === 'passed' || Cypress.runner !== currentRunner || Cypress.state('canceled')) { + 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