mirror of
https://github.com/cypress-io/cypress.git
synced 2026-03-09 01:19:20 -05:00
fix tests
This commit is contained in:
18
cli/types/cypress.d.ts
vendored
18
cli/types/cypress.d.ts
vendored
@@ -655,8 +655,22 @@ declare namespace Cypress {
|
||||
}
|
||||
|
||||
interface SessionOptions {
|
||||
/**
|
||||
* Whether or not to persist the session across all specs in the run.
|
||||
* @default {false}
|
||||
*/
|
||||
cacheAcrossSpecs?: boolean,
|
||||
validate?: () => false | void
|
||||
/**
|
||||
* Function to run immediately after the session is created and `setup` function runs or
|
||||
* after a session is restored and the page is cleared. If this returns `false`, throws an
|
||||
* exception, returns a Promise which resolves to `false` or rejects or contains any failing
|
||||
* Cypress command, the session is considered invalid.
|
||||
*
|
||||
* If validation fails immediately after `setup`, the test will fail.
|
||||
* If validation fails after restoring a session, `setup` will re-run.
|
||||
* @default {false}
|
||||
*/
|
||||
validate?: () => Promise<false | void> | false | void
|
||||
}
|
||||
|
||||
type CanReturnChainable = void | Chainable | Promise<unknown>
|
||||
@@ -1075,7 +1089,7 @@ declare namespace Cypress {
|
||||
*
|
||||
* @see https://on.cypress.io/session
|
||||
*/
|
||||
session(id: string | object, setup?: SessionOptions['validate'], options?: SessionOptions): Chainable<null>
|
||||
session(id: string | object, setup?: () => void, options?: SessionOptions): Chainable<null>
|
||||
|
||||
/**
|
||||
* Get the window.document of the page that is currently active.
|
||||
|
||||
@@ -176,17 +176,11 @@ function getSpecUrl (namespace: string, specSrc: string) {
|
||||
* or re-running the current spec.
|
||||
*/
|
||||
function teardownSpec (isRerun: boolean = false) {
|
||||
useAutStore().$reset()
|
||||
|
||||
useStudioStore().cancel()
|
||||
|
||||
useSnapshotStore().$reset()
|
||||
|
||||
_eventManager?.stop()
|
||||
|
||||
getEventManager().teardown(getMobxRunnerStore(), isRerun)
|
||||
|
||||
return
|
||||
return getEventManager().teardown(getMobxRunnerStore(), isRerun)
|
||||
}
|
||||
|
||||
let isTorndown = false
|
||||
@@ -197,8 +191,9 @@ let isTorndown = false
|
||||
* any associated events.
|
||||
*/
|
||||
export async function teardown () {
|
||||
teardownSpec(false)
|
||||
UnifiedReporterAPI.setInitializedReporter(false)
|
||||
_eventManager?.stop()
|
||||
_eventManager?.teardown(getMobxRunnerStore())
|
||||
await _eventManager?.resetReporter()
|
||||
_eventManager = undefined
|
||||
isTorndown = true
|
||||
@@ -355,8 +350,15 @@ async function initialize () {
|
||||
return
|
||||
}
|
||||
|
||||
// Reset stores
|
||||
const autStore = useAutStore()
|
||||
|
||||
autStore.$reset()
|
||||
|
||||
const studioStore = useStudioStore()
|
||||
|
||||
studioStore.cancel()
|
||||
|
||||
// TODO(lachlan): UNIFY-1318 - use GraphQL to get the viewport dimensions
|
||||
// once it is more practical to do so
|
||||
// find out if we need to continue managing viewportWidth/viewportHeight in MobX at all.
|
||||
@@ -395,9 +397,11 @@ async function initialize () {
|
||||
* description for more information.
|
||||
*/
|
||||
async function executeSpec (spec: SpecFile, isRerun: boolean = false) {
|
||||
await Promise.all([teardownSpec(isRerun), UnifiedReporterAPI.resetReporter()])
|
||||
await teardownSpec(isRerun)
|
||||
|
||||
getMobxRunnerStore().setSpec(spec)
|
||||
const mobxRunnerStore = getMobxRunnerStore()
|
||||
|
||||
mobxRunnerStore.setSpec(spec)
|
||||
|
||||
UnifiedReporterAPI.setupReporter()
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ describe('src/cy/commands/sessions/manager.ts', () => {
|
||||
'session_1': {
|
||||
id: 'session_1',
|
||||
setup: () => {},
|
||||
cacheAcrossSpecs: false,
|
||||
hydrated: true,
|
||||
},
|
||||
}
|
||||
@@ -47,11 +48,13 @@ describe('src/cy/commands/sessions/manager.ts', () => {
|
||||
'session_1': {
|
||||
id: 'session_1',
|
||||
setup: () => {},
|
||||
cacheAcrossSpecs: false,
|
||||
hydrated: false,
|
||||
},
|
||||
'session_2': {
|
||||
id: 'session_2',
|
||||
setup: () => {},
|
||||
cacheAcrossSpecs: false,
|
||||
hydrated: true,
|
||||
},
|
||||
}
|
||||
@@ -62,6 +65,7 @@ describe('src/cy/commands/sessions/manager.ts', () => {
|
||||
'session_3': {
|
||||
id: 'session_3',
|
||||
setup: () => {},
|
||||
cacheAcrossSpecs: false,
|
||||
hydrated: true,
|
||||
},
|
||||
}
|
||||
@@ -96,11 +100,13 @@ describe('src/cy/commands/sessions/manager.ts', () => {
|
||||
'session_1': {
|
||||
id: 'session_1',
|
||||
setup: () => {},
|
||||
cacheAcrossSpecs: false,
|
||||
hydrated: false,
|
||||
},
|
||||
'session_2': {
|
||||
id: 'session_2',
|
||||
setup: () => {},
|
||||
cacheAcrossSpecs: false,
|
||||
hydrated: true,
|
||||
},
|
||||
}
|
||||
@@ -135,11 +141,13 @@ describe('src/cy/commands/sessions/manager.ts', () => {
|
||||
'session_1': {
|
||||
id: 'session_1',
|
||||
setup: () => {},
|
||||
cacheAcrossSpecs: false,
|
||||
hydrated: false,
|
||||
},
|
||||
'session_2': {
|
||||
id: 'session_2',
|
||||
setup: () => {},
|
||||
cacheAcrossSpecs: false,
|
||||
hydrated: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
getConsoleProps,
|
||||
navigateAboutBlank,
|
||||
} from './utils'
|
||||
import type { ServerSessionData } from '@packages/types'
|
||||
|
||||
type SessionData = Cypress.Commands.Session.SessionData
|
||||
|
||||
@@ -21,7 +22,7 @@ type SessionData = Cypress.Commands.Session.SessionData
|
||||
*/
|
||||
|
||||
export default function (Commands, Cypress, cy) {
|
||||
Object.values(Cypress.state('activeSessions') || {}).forEach((sessionData) => {
|
||||
Object.values(Cypress.state('activeSessions') || {}).forEach((sessionData: ServerSessionData) => {
|
||||
if (sessionData.cacheAcrossSpecs) {
|
||||
sessionsManager.registeredSessions.set(sessionData.id, true)
|
||||
}
|
||||
@@ -61,7 +62,7 @@ export default function (Commands, Cypress, cy) {
|
||||
})
|
||||
|
||||
Commands.addAll({
|
||||
session (id, setup?: Function, options: Cypress.SessionOptions = { cacheAcrossSpecs: false }) {
|
||||
session (id: string | object, setup?: () => void, options: Cypress.SessionOptions = { cacheAcrossSpecs: false }) {
|
||||
throwIfNoSessionSupport()
|
||||
|
||||
if (!id || !_.isString(id) && !_.isObject(id)) {
|
||||
|
||||
@@ -145,7 +145,6 @@ describe('e2e sessions', () => {
|
||||
project: 'session-and-origin-e2e-specs',
|
||||
spec: 'session_persist_1.cy.js,session_persist_2.cy.js',
|
||||
browser: '!webkit', // TODO(webkit): fix+unskip (needs multidomain support)
|
||||
spec: 'session_persist_spec_1.cy.js,session_persist_spec_2.cy.js',
|
||||
snapshot: true,
|
||||
config: {
|
||||
experimentalSessionAndOrigin: true,
|
||||
|
||||
Reference in New Issue
Block a user