Repository: cypress-io/cypress
File: packages/launchpad/cypress/e2e/integration/choose-a-browser.spec.ts (TypeScript)

Code before:
import type Sinon from '@packages/../cli/types/sinon'
import type { FoundBrowser } from '@packages/types/src'

describe('Choose a Browser Page', () => {
  // Walks through setup pages to get to browser selection
  const stepThroughConfigPages = () => {
    cy.get('h1').should('contain', 'Configuration Files')
    cy.contains('Continue').click()
    cy.get('h1').should('contain', 'Initializing Config...')
    cy.contains('Next Step').click()
  }

  // Mocks server's browser detection with known list
  const setupMockBrowsers = function () {
    cy.withCtx(async (ctx, o) => {
      let mockedGetBrowsers = ctx._apis.appApi.getBrowsers as Sinon.SinonStub

      if (mockedGetBrowsers.restore) {
        mockedGetBrowsers.restore()
      }

      const mockBrowsers = [{
        'channel': 'stable',
        'displayName': 'Chrome',
        'family': 'chromium',
        'name': 'chrome',
        'version': '1.2.333.445',
        'path': '/test/chrome/path',
        'majorVersion': '1',
      }, {
        'channel': 'stable',
        'displayName': 'Firefox',
        'family': 'firefox',
        'name': 'firefox',
        'path': '/test/firefox/path',
        'version': '2.3.444',
        'majorVersion': '2',
      }, {
        'channel': 'stable',
        'displayName': 'Electron',
        'family': 'chromium',
        'name': 'electron',
        'path': '/test/electron/path',
        'version': '3.4.555.66',

Review comment (suggestion):
I thought our framework reset signons automatically. Wondering if this should be sinon.restore() rather than sinon.reset():

https://github.com/cypress-io/cypress/blob/10.0-release/packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts#L128

Code after:
describe('Choose a Browser Page', () => {
  // Walks through setup pages to get to browser selection
  const stepThroughConfigPages = () => {
    cy.get('h1').should('contain', 'Configuration Files')
    cy.contains('button', 'Continue').click()
    cy.get('h1').should('contain', 'Initializing Config...')
    cy.contains('button', 'Next Step').click()
  }

  beforeEach(() => {
    cy.scaffoldProject('launchpad')
  })

  describe('System Browsers Detected', () => {
    beforeEach(() => {
      cy.findBrowsers({
        filter: (browser) => {
          return Cypress._.includes(['chrome', 'firefox', 'electron', 'edge'], browser.name) && browser.channel === 'stable'
        },
      })
    })

    it('preselects browser that is provided through the command line', () => {
      cy.openProject('launchpad', ['--e2e', '--browser', 'edge'])

      cy.visitLaunchpad()
      stepThroughConfigPages()

      cy.get('h1').should('contain', 'Choose a Browser')

      cy.findByRole('radio', { name: 'Edge v8', checked: true })
    })

    it('shows warning when launched with --browser name that cannot be matched to found browsers', () => {
      cy.openProject('launchpad', ['--e2e', '--browser', 'doesNotExist'])
      cy.visitLaunchpad()

      stepThroughConfigPages()

      cy.get('h1').should('contain', 'Choose a Browser')
      cy.get('[data-cy="alert-header"]').should('contain', 'Warning: Browser Not Found')
      cy.get('[data-cy="alert-body"]')
      .should('contain', 'The specified browser was not found on your system or is not supported by Cypress: doesNotExist')