Repository: cypress-io/cypress
File: packages/data-context/src/data/ProjectConfigIpc.ts (TypeScript)

Code before:
  once(evt: 'setupTestingType:reply', listener: (payload: SetupNodeEventsReply) => void): this
  once(evt: 'setupTestingType:error', listener: (error: CypressError) => void): this
  once(evt: 'file:preprocessor:overridden', listener: (payload: { handlerText: string }) => void): this
  once (evt: string, listener: (...args: any[]) => void) {
    return super.once(evt, listener)
  }

  emit (evt: string, ...args: any[]) {
    return super.emit(evt, ...args)
  }

  loadConfig (): Promise<LoadConfigReply> {
    return new Promise((resolve, reject) => {
      if (this._childProcess.stdout && this._childProcess.stderr) {
        // manually pipe plugin stdout and stderr for Cypress Cloud capture
        // @see https://github.com/cypress-io/cypress/issues/7434
        this._childProcess.stdout.pipe(process.stdout)
        this._childProcess.stderr.pipe(new TagStream()).pipe(process.stderr)
      }

      let resolved = false

      this._childProcess.on('error', (err: NodeJS.ErrnoException) => {
        if (err.code === 'EPIPE') {
          debug('EPIPE error in loadConfig() of child process %s', err)

          return
        }

        debug('unhandled error in child process %s', err)
        this.handleChildProcessError(err, this, resolved, reject)
        reject(err)
      })

      /**
       * This reject cannot be caught anywhere??
       *
       * It's supposed to be caught on lib/modes/run.js:1689,
       * but it's not.
       */
      this.on('childProcess:unhandledError', (err) => {
        debug('unhandled error in child process %s', err)
        this.handleChildProcessError(err, this, resolved, reject)
        reject(err)
      })

      this.once('loadConfig:reply', (val) => {
        debug('loadConfig:reply')
        resolve({ ...val, initialConfig: JSON.parse(val.initialConfig) })
        resolved = true
      })

Review comment (performance):
@alexsch01 I wonder if we just want to `resolve()` this before returning just to prevent a possible memory leak (even though the process _should_ be killed)
```suggestion
resolve()
```

Code after:
  once(evt: 'setupTestingType:reply', listener: (payload: SetupNodeEventsReply) => void): this
  once(evt: 'setupTestingType:error', listener: (error: CypressError) => void): this
  once(evt: 'file:preprocessor:overridden', listener: (payload: { handlerText: string }) => void): this
  once (evt: string, listener: (...args: any[]) => void) {
    return super.once(evt, listener)
  }

  emit (evt: string, ...args: any[]) {
    return super.emit(evt, ...args)
  }

  loadConfig (): Promise<LoadConfigReply> {
    return new Promise((resolve, reject) => {
      if (this._childProcess.stdout && this._childProcess.stderr) {
        // manually pipe plugin stdout and stderr for Cypress Cloud capture
        // @see https://github.com/cypress-io/cypress/issues/7434
        this._childProcess.stdout.pipe(process.stdout)
        this._childProcess.stderr.pipe(new TagStream()).pipe(process.stderr)
      }

      let resolved = false

      this._childProcess.on('error', (err: NodeJS.ErrnoException) => {
        if (err.code === 'EPIPE') {
          debug('EPIPE error in loadConfig() of child process %s', err)

          // @ts-ignore
          resolve()

          return
        }

        debug('unhandled error in child process %s', err)
        this.handleChildProcessError(err, this, resolved, reject)
        reject(err)
      })

      /**
       * This reject cannot be caught anywhere??
       *
       * It's supposed to be caught on lib/modes/run.js:1689,
       * but it's not.
       */
      this.on('childProcess:unhandledError', (err) => {
        debug('unhandled error in child process %s', err)
        this.handleChildProcessError(err, this, resolved, reject)
        reject(err)
      })

      this.once('loadConfig:reply', (val) => {
        debug('loadConfig:reply')