diff --git a/packages/server/__snapshots__/7_session_spec.ts.js b/packages/server/__snapshots__/7_session_spec.ts.js index 71f10da3c847..0200e50cae1e 100644 --- a/packages/server/__snapshots__/7_session_spec.ts.js +++ b/packages/server/__snapshots__/7_session_spec.ts.js @@ -145,7 +145,7 @@ exports['e2e sessions / session tests'] = ` ` -exports['e2e sessions / sessions persist on reload'] = ` +exports['e2e sessions / sessions persist on reload, and clear between specs'] = ` ==================================================================================================== @@ -154,14 +154,15 @@ exports['e2e sessions / sessions persist on reload'] = ` ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Cypress: 1.2.3 │ │ Browser: FooBrowser 88 │ - │ Specs: 1 found (session_persist_spec.js) │ - │ Searched: cypress/integration/session_persist_spec.js │ + │ Specs: 2 found (session_persist_spec_1.js, session_persist_spec_2.js) │ + │ Searched: cypress/integration/session_persist_spec_1.js, cypress/integration/session_persist │ + │ _spec_2.js │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ ──────────────────────────────────────────────────────────────────────────────────────────────────── - Running: session_persist_spec.js (1 of 1) + Running: session_persist_spec_1.js (1 of 2) persist saved sessions between spec reruns @@ -185,7 +186,34 @@ exports['e2e sessions / sessions persist on reload'] = ` │ Screenshots: 0 │ │ Video: false │ │ Duration: X seconds │ - │ Spec Ran: session_persist_spec.js │ + │ Spec Ran: session_persist_spec_1.js │ + └────────────────────────────────────────────────────────────────────────────────────────────────┘ + + +──────────────────────────────────────────────────────────────────────────────────────────────────── + + Running: session_persist_spec_2.js (2 of 2) + + + after running spec with saved session + ✓ has an initially blank session on new spec + + + 1 passing + + + (Results) + + ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ Tests: 1 │ + │ Passing: 1 │ + │ Failing: 0 │ + │ Pending: 0 │ + │ Skipped: 0 │ + │ Screenshots: 0 │ + │ Video: false │ + │ Duration: X seconds │ + │ Spec Ran: session_persist_spec_2.js │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ @@ -196,9 +224,11 @@ exports['e2e sessions / sessions persist on reload'] = ` Spec Tests Passing Failing Pending Skipped ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ ✔ session_persist_spec.js XX:XX 1 1 - - - │ + │ ✔ session_persist_spec_1.js XX:XX 1 1 - - - │ + ├────────────────────────────────────────────────────────────────────────────────────────────────┤ + │ ✔ session_persist_spec_2.js XX:XX 1 1 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✔ All specs passed! XX:XX 1 1 - - - + ✔ All specs passed! XX:XX 2 2 - - - ` diff --git a/packages/server/lib/open_project.js b/packages/server/lib/open_project.js index 58a603717904..8fc8c5b5075a 100644 --- a/packages/server/lib/open_project.js +++ b/packages/server/lib/open_project.js @@ -9,6 +9,7 @@ const browsers = require('./browsers') const specsUtil = require('./util/specs') const preprocessor = require('./plugins/preprocessor') const runEvents = require('./plugins/run_events') +const session = require('./session') const { getSpecUrl } = require('./project_utils') const errors = require('./errors') @@ -171,6 +172,9 @@ const moduleFactory = () => { if (!cfg.isTextTerminal && cfg.experimentalInteractiveRunEvents) { return runEvents.execute('before:spec', cfg, spec) } + + // clear all session data before each spec + session.clearSessions() }) .then(() => { return browsers.open(browser, options, automation) diff --git a/packages/server/test/e2e/7_session_spec.ts b/packages/server/test/e2e/7_session_spec.ts index 2174e3fd7cac..2bdc5c8f1330 100644 --- a/packages/server/test/e2e/7_session_spec.ts +++ b/packages/server/test/e2e/7_session_spec.ts @@ -134,8 +134,8 @@ describe('e2e sessions', () => { }, }) - it('sessions persist on reload', { - spec: 'session_persist_spec.js', + it('sessions persist on reload, and clear between specs', { + spec: 'session_persist_spec_1.js,session_persist_spec_2.js', snapshot: true, config: { experimentalSessionSupport: true, diff --git a/packages/server/test/support/fixtures/projects/e2e/cypress/integration/session_persist_spec.js b/packages/server/test/support/fixtures/projects/e2e/cypress/integration/session_persist_spec_1.js similarity index 77% rename from packages/server/test/support/fixtures/projects/e2e/cypress/integration/session_persist_spec.js rename to packages/server/test/support/fixtures/projects/e2e/cypress/integration/session_persist_spec_1.js index 506340a0f8d0..c8bc119e7369 100644 --- a/packages/server/test/support/fixtures/projects/e2e/cypress/integration/session_persist_spec.js +++ b/packages/server/test/support/fixtures/projects/e2e/cypress/integration/session_persist_spec_1.js @@ -5,8 +5,10 @@ describe('persist saved sessions between spec reruns', () => { cy.session('persist_session', () => { cy.setCookie('cookieName', 'cookieValue') }) - .then(() => { - if (!top.count) { + + if (!top.count) { + return cy.wrap(null).should(() => { + expect(cy.$$('.commands-container li.command:first', top.document).text()).contain('(new)') top.count++ // this simulates interactive/open mode @@ -18,10 +20,10 @@ describe('persist saved sessions between spec reruns', () => { // in the browser reporter gui cy.$$('button.stop', top.document)[0].click() cy.$$('button.restart', top.document)[0].click() - } + }) + } - cy.$$('.runnable-active', top.document)[0].click() - }) + cy.$$('.runnable-active', top.document)[0].click() cy.wrap(null).should(() => { expect(cy.$$('.commands-container li.command:first', top.document).text()).contain('(saved)') diff --git a/packages/server/test/support/fixtures/projects/e2e/cypress/integration/session_persist_spec_2.js b/packages/server/test/support/fixtures/projects/e2e/cypress/integration/session_persist_spec_2.js new file mode 100644 index 000000000000..577a6a2b523a --- /dev/null +++ b/packages/server/test/support/fixtures/projects/e2e/cypress/integration/session_persist_spec_2.js @@ -0,0 +1,16 @@ +/** + * This is part 2 of the session persist spec + * This part makes sure session data is cleared inbetween specs in run mode + */ + +describe('after running spec with saved session', () => { + it('has an initially blank session on new spec', () => { + cy.session('persist_session', () => { + cy.setCookie('cookieName', 'cookieValue') + }) + + return cy.wrap(null).should(() => { + expect(cy.$$('.commands-container li.command:first', top.document).text()).contain('(new)') + }) + }) +})