Repository: cypress-io/cypress
File: packages/server/test/unit/socket_spec.js (JavaScript)

Code before:
const { SocketE2E } = require('../../lib/socket-e2e')
const { ServerBase } = require('../../lib/server-base')
const { Automation } = require('../../lib/automation')
const preprocessor = require('../../lib/plugins/preprocessor').default
const { fs } = require('../../lib/util/fs')
const session = require('../../lib/session')
const devServer = require('../../lib/plugins/dev-server').default
const { createRoutes } = require('../../lib/routes')
const { getCtx } = require('../../lib/makeDataContext')
const { sinon } = require('../spec_helper')
const { SocketCt } = require('../../lib/socket-ct')

let ctx

describe('lib/socket', () => {
  beforeEach(async function () {
    ctx = getCtx()
    ctx.coreData.activeBrowser = {
      path: 'path-to-browser-one',
    }

    // Don't bother initializing the child process, etc for this
    sinon.stub(ctx.actions.project, 'initializeActiveProject')
    sinon.stub(preprocessor.emitter, 'on')
    sinon.stub(preprocessor.emitter, 'off')

    Fixtures.scaffold()
    session.clearSessions(true)

    this.todosPath = Fixtures.projectPath('todos')

    await ctx.actions.project.setCurrentProjectAndTestingTypeForTestSetup(this.todosPath)

    return ctx.lifecycleManager.getFullInitialConfig()
    .then((cfg) => {
      this.cfg = cfg
      this.server = new ServerBase(cfg)
    })
  })

  afterEach(function () {
    Fixtures.remove()

    return this.server.close()
  })

  context('integration', () => {
    let mockCyPrompt

    beforeEach(function (done) {
      // create a for realz socket.io connection

Review comment (bug):
I did not test what other impact this has on the test, but frankly I am tired of trying to run these and they fail locally because the electron resolved browser has an empty version string and therefore fails config validation. I would also say this is mostly an integration test, as it integrates heavily with the `data-context` package and the `errors` package

Code after:
const Fixtures = require('@tooling/system-tests')

const errors = require('../../lib/errors')
const { SocketE2E } = require('../../lib/socket-e2e')
const { ServerBase } = require('../../lib/server-base')
const { Automation } = require('../../lib/automation')
const preprocessor = require('../../lib/plugins/preprocessor').default
const { fs } = require('../../lib/util/fs')
const session = require('../../lib/session')
const devServer = require('../../lib/plugins/dev-server').default
const { createRoutes } = require('../../lib/routes')
const { getCtx } = require('../../lib/makeDataContext')
const { sinon } = require('../spec_helper')
const { SocketCt } = require('../../lib/socket-ct')

let ctx

describe('lib/socket', () => {
  beforeEach(async function () {
    ctx = getCtx()
    ctx.coreData.activeBrowser = {
      path: 'path-to-browser-one',
    }

    // needed to run these tests locally
    // sinon.stub(ctx.browser, 'machineBrowsers').resolves([
    //   {
    //     channel: 'stable',
    //     displayName: 'Electron',
    //     family: 'chromium',
    //     majorVersion: '123',
    //     name: 'electron',
    //     path: 'path-to-browser-one',
    //     version: '123.45.67',
    //   },
    // ])

    // Don't bother initializing the child process, etc for this
    sinon.stub(ctx.actions.project, 'initializeActiveProject')
    sinon.stub(preprocessor.emitter, 'on')
    sinon.stub(preprocessor.emitter, 'off')

    Fixtures.scaffold()
    session.clearSessions(true)

    this.todosPath = Fixtures.projectPath('todos')

    await ctx.actions.project.setCurrentProjectAndTestingTypeForTestSetup(this.todosPath)

    return ctx.lifecycleManager.getFullInitialConfig()
    .then((cfg) => {