Repository: facebook/jest
File: packages/jest-core/src/TestScheduler.ts (TypeScript)

Code before:
        if (!testRuns[runner]) {
          testRuns[runner] = [];
        }
        testRuns[runner].push(test);
        return testRuns;
      }, Object.create(null));
    } else if (tests.length > 0 && tests[0] != null) {
      // If there is only one runner, don't partition the tests.
      return Object.assign(Object.create(null), {
        [tests[0].context.config.runner]: tests,
      });
    } else {
      return null;
    }
  }

  async _setupReporters() {
    const {collectCoverage: coverage, notify, verbose} = this._globalConfig;
    const reporters = this._globalConfig.reporters || [['default', {}]];
    let summaryOptions;

    for (const [reporter, options] of reporters) {
      switch (reporter) {
        case 'default':
          summaryOptions = options;
          verbose
            ? this.addReporter(new VerboseReporter(this._globalConfig))
            : this.addReporter(new DefaultReporter(this._globalConfig));
          break;
        case 'github-actions':
          GITHUB_ACTIONS &&
            this.addReporter(
              new GitHubActionsReporter(this._globalConfig, options),
            );
          break;
        case 'summary':
          summaryOptions = options;
          break;
        default:
          await this._addCustomReporter(reporter, options);
      }
    }

    if (notify) {
      this.addReporter(new NotifyReporter(this._globalConfig, this._context));
    }

    if (coverage) {
      this.addReporter(new CoverageReporter(this._globalConfig, this._context));
    }


Review comment (suggestion):
I went checking if `options` is always defined. Apparently normalization always add an object. That’s smart idea!

Code after:
        const runner = test.context.config.runner;
        if (!testRuns[runner]) {
          testRuns[runner] = [];
        }
        testRuns[runner].push(test);
        return testRuns;
      }, Object.create(null));
    } else if (tests.length > 0 && tests[0] != null) {
      // If there is only one runner, don't partition the tests.
      return Object.assign(Object.create(null), {
        [tests[0].context.config.runner]: tests,
      });
    } else {
      return null;
    }
  }

  async _setupReporters() {
    const {collectCoverage: coverage, notify, verbose} = this._globalConfig;
    const reporters = this._globalConfig.reporters || [['default', {}]];
    let summaryOptions: SummaryReporterOptions | null = null;

    for (const [reporter, options] of reporters) {
      switch (reporter) {
        case 'default':
          summaryOptions = options;
          verbose
            ? this.addReporter(new VerboseReporter(this._globalConfig))
            : this.addReporter(new DefaultReporter(this._globalConfig));
          break;
        case 'github-actions':
          GITHUB_ACTIONS &&
            this.addReporter(
              new GitHubActionsReporter(this._globalConfig, options),
            );
          break;
        case 'summary':
          summaryOptions = options;
          break;
        default:
          await this._addCustomReporter(reporter, options);
      }
    }

    if (notify) {
      this.addReporter(new NotifyReporter(this._globalConfig, this._context));
    }

    if (coverage) {
      this.addReporter(new CoverageReporter(this._globalConfig, this._context));
    }