Repository: cypress-io/cypress
File: packages/driver/src/cy/commands/sessions/index.ts (TypeScript)

Code before:
          return restoreSession(existingSession)
        })
        .then({ timeout: INTERNAL_COMMAND_TIMEOUT }, () => validateSession(existingSession, SESSION_STEPS.restore))
        .then({ timeout: INTERNAL_COMMAND_TIMEOUT }, (isValidSession: boolean) => {
          if (!isValidSession) {
            return createSessionWorkflow(existingSession, SESSION_STEPS.recreate)
          }

          return statusMap.complete(SESSION_STEPS.restore)
        })
      }

      /**
       * Session command rules:
       *   If session does not exists or was no previously saved to the server, create session
       *      1. run create session flow
       *      2. clear page
       *
       *   If session exists or has been saved to the server, restore session
       *      1. run restore session flow
       *      2. clear page
       */
      let _log
      const groupDetails = {
        message: `${session.id.length > 50 ? `${session.id.substring(0, 47)}...` : session.id}`,
        defaultCollapsedState: 'closed' as 'closed' | 'open',
      }

      return logGroup(Cypress, groupDetails, (log) => {
        return cy.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, async () => {
          _log = log

          if (!session.hydrated) {
            const serverStoredSession = await sessions.getSession(session.id).catch(_.noop)

            // we have a saved session on the server and setup matches
            if (serverStoredSession && serverStoredSession.setup === session.setup.toString()) {
              _.extend(session, _.omit(serverStoredSession, 'setup', 'validate'))
              session.hydrated = true
            } else {
              return createSessionWorkflow(session, SESSION_STEPS.create)
            }
          }

          return restoreSessionWorkflow(session)
        }).then({ timeout: INTERNAL_COMMAND_TIMEOUT }, (status: 'created' | 'restored' | 'recreated' | 'failed') => {
          return navigateAboutBlank()
          .then(() => {
            setSessionLogStatus(status)
          })
        })

Review comment (suggestion):
Suggest defining the `closed | open` type somewhere so it can be reused.

Code after:
          return restoreSession(existingSession)
        })
        .then({ timeout: INTERNAL_COMMAND_TIMEOUT }, () => validateSession(existingSession, SESSION_STEPS.restore))
        .then({ timeout: INTERNAL_COMMAND_TIMEOUT }, (isValidSession: boolean) => {
          if (!isValidSession) {
            return createSessionWorkflow(existingSession, SESSION_STEPS.recreate)
          }

          return statusMap.complete(SESSION_STEPS.restore)
        })
      }

      /**
       * Session command rules:
       *   If session does not exists or was no previously saved to the server, create session
       *      1. run create session flow
       *      2. clear page
       *
       *   If session exists or has been saved to the server, restore session
       *      1. run restore session flow
       *      2. clear page
       */
      let _log
      const groupDetails = {
        message: `${session.id.length > 50 ? `${session.id.substring(0, 47)}...` : session.id}`,
        defaultCollapsedState: 'closed' as const,
      }

      return logGroup(Cypress, groupDetails, (log) => {
        return cy.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, async () => {
          _log = log

          if (!session.hydrated) {
            const serverStoredSession = await sessions.getSession(session.id).catch(_.noop)

            // we have a saved session on the server and setup matches
            if (serverStoredSession && serverStoredSession.setup === session.setup.toString()) {
              _.extend(session, _.omit(serverStoredSession, 'setup', 'validate'))
              session.hydrated = true
            } else {
              return createSessionWorkflow(session, SESSION_STEPS.create)
            }
          }

          return restoreSessionWorkflow(session)
        }).then({ timeout: INTERNAL_COMMAND_TIMEOUT }, (status: 'created' | 'restored' | 'recreated' | 'failed') => {
          return navigateAboutBlank()
          .then(() => {
            setSessionLogStatus(status)
          })
        })