Skip to content

Commit

Permalink
clear server session state between spec launches, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kuceb committed Jul 30, 2021
1 parent 3bac762 commit 461e15c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
44 changes: 37 additions & 7 deletions packages/server/__snapshots__/7_session_spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = `
====================================================================================================
Expand All @@ -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
Expand All @@ -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 │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
Expand All @@ -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 - - -
`
4 changes: 4 additions & 0 deletions packages/server/lib/open_project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/e2e/7_session_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)')
Expand Down
Original file line number Diff line number Diff line change
@@ -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)')
})
})
})

0 comments on commit 461e15c

Please sign in to comment.