Repository: cypress-io/cypress
File: packages/app/src/store/studio-store.ts (TypeScript)

Code before:
      }

      if (studio.url) {
        this._initialUrl = studio.url
      }

      // if we have an existing test or are creating a new test, we need to start loading
      // otherwise if we have a suite, we can just set the studio active
      if (this.testId || studio.newTestLineNumber) {
        this.setAbsoluteFile(config.spec.absolute)
        this.startLoading()
      } else if (this.suiteId) {
        this.setActive(true)
      }
    },

    initialize () {
      if (this.newTestLineNumber) {
        getCypress().runner.setNewTestLineNumber(this.newTestLineNumber)
        // Creating a new test - need to bypass .only filtering
        getCypress().runner.setIsStudioCreatedTest(true)
        this._wasStudioCreatedTest = true
      } else if (this.testId) {
        if (this._wasStudioCreatedTest) {
          // This test was just created by studio, so we need to set the test id
          getCypress().runner.setOnlyTestId(this.testId)
          getCypress().runner.setIsStudioCreatedTest(true)
        } else {
          // this is an existing test - respect .only filtering
          getCypress().runner.setOnlyTestId(this.testId)
          getCypress().runner.setIsStudioCreatedTest(false)
        }
      }
    },

    interceptTest (test) {
      // if this test is the one we created, we can just set the test id
      if (this.newTestLineNumber && test.invocationDetails?.line === this.newTestLineNumber) {
        this._wasStudioCreatedTest = true
        this.setTestId(test.id)
        getCypress().runner.setIsStudioCreatedTest(true)
      } else if (this.suiteId) {
        this._wasStudioCreatedTest = true
        this.setTestId(test.id)
        getCypress().runner.setIsStudioCreatedTest(true)
      }

      if (this.testId) {
        if (test.invocationDetails) {
          this.setFileDetails(test.invocationDetails)
        }

Review comment (suggestion):
this doesn't have to be repeated. it could be outside the if since this needs to be set in either scenario

Code after:
      }

      if (studio.url) {
        this._initialUrl = studio.url
      }

      // if we have an existing test or are creating a new test, we need to start loading
      // otherwise if we have a suite, we can just set the studio active
      if (this.testId || studio.newTestLineNumber) {
        this.setAbsoluteFile(config.spec.absolute)
        this.startLoading()
      } else if (this.suiteId) {
        this.setActive(true)
      }
    },

    initialize () {
      if (this.newTestLineNumber) {
        getCypress().runner.setNewTestLineNumber(this.newTestLineNumber)
        // Creating a new test - need to bypass .only filtering
        getCypress().runner.setIsStudioCreatedTest(true)
        this._isStudioCreatedTest = true
      } else if (this.testId) {
        getCypress().runner.setOnlyTestId(this.testId)
        getCypress().runner.setIsStudioCreatedTest(this._isStudioCreatedTest)
      }
    },

    interceptTest (test) {
      // if this test is the one we created, we can just set the test id
      if ((this.newTestLineNumber && test.invocationDetails?.line === this.newTestLineNumber) || this.suiteId) {
        this._isStudioCreatedTest = true
        this.setTestId(test.id)
        getCypress().runner.setIsStudioCreatedTest(true)
      }

      if (this.testId) {
        if (test.invocationDetails) {
          this.setFileDetails(test.invocationDetails)
        }

        this.setRunnableTitle(test.title)
      }
    },

    start () {
      this.isActive = true
      this.isLoading = false
      this.logs = []
      this._currentId = 1
      this._hasStarted = true