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

Code before:
        aggregatedResults.snapshot.filesRemovedList = (
          aggregatedResults.snapshot.filesRemovedList || []
        ).concat(status.filesRemovedList);
      });
      const updateAll = this._globalConfig.updateSnapshot === 'all';
      aggregatedResults.snapshot.didUpdate = updateAll;
      aggregatedResults.snapshot.failure = !!(
        !updateAll &&
        (aggregatedResults.snapshot.unchecked ||
          aggregatedResults.snapshot.unmatched ||
          aggregatedResults.snapshot.filesRemoved)
      );
    };
    const buildExecError = (err: unknown): SerializableError => {
      const fromString = (errString: string): SerializableError => {
        const {message, stack} = separateMessageFromStack(errString);
        if (stack.length > 0) {
          return {message, stack};
        }
        const error = new ErrorWithStack(message, buildExecError);
        return {message, stack: error.stack || ''};
      };
      if (typeof err === 'string' || err == null) {
        return fromString(err || 'Error');
      }
      const anyErr: any = err as any;
      if (typeof anyErr.message === 'string') {
        if (typeof anyErr.stack === 'string' && anyErr.stack.length > 0) {
          return anyErr;
        }
        return fromString(anyErr.message);
      }
      return fromString(JSON.stringify(err));
    };

    await this._dispatcher.onRunStart(aggregatedResults, {
      estimatedTime,
      showStatus: !runInBand,
    });

    const testRunners: Record<string, JestTestRunner> = Object.create(null);
    const contextsByTestRunner = new WeakMap<JestTestRunner, TestContext>();

    try {
      await Promise.all(
        Array.from(testContexts).map(async context => {
          const {config} = context;
          if (!testRunners[config.runner]) {
            const transformer = await createScriptTransformer(config);
            const Runner: TestRunnerConstructor =
              await transformer.requireAndTranspileModule(config.runner);

Review comment (suggestion):
```suggestion
      const anyErr = err as any;
```

Code after:
        aggregatedResults.snapshot.filesRemovedList = (
          aggregatedResults.snapshot.filesRemovedList || []
        ).concat(status.filesRemovedList);
      });
      const updateAll = this._globalConfig.updateSnapshot === 'all';
      aggregatedResults.snapshot.didUpdate = updateAll;
      aggregatedResults.snapshot.failure = !!(
        !updateAll &&
        (aggregatedResults.snapshot.unchecked ||
          aggregatedResults.snapshot.unmatched ||
          aggregatedResults.snapshot.filesRemoved)
      );
    };

    await this._dispatcher.onRunStart(aggregatedResults, {
      estimatedTime,
      showStatus: !runInBand,
    });

    const testRunners: Record<string, JestTestRunner> = Object.create(null);
    const contextsByTestRunner = new WeakMap<JestTestRunner, TestContext>();

    try {
      await Promise.all(
        Array.from(testContexts).map(async context => {
          const {config} = context;
          if (!testRunners[config.runner]) {
            const transformer = await createScriptTransformer(config);
            const Runner: TestRunnerConstructor =
              await transformer.requireAndTranspileModule(config.runner);
            const runner = new Runner(this._globalConfig, {
              changedFiles: this._context.changedFiles,
              sourcesRelatedToTestsInChangedFiles:
                this._context.sourcesRelatedToTestsInChangedFiles,
            });
            testRunners[config.runner] = runner;
            contextsByTestRunner.set(runner, context);
          }
        }),
      );

      const testsByRunner = this._partitionTests(testRunners, tests);

      if (testsByRunner) {
        try {
          for (const runner of Object.keys(testRunners)) {
            const testRunner = testRunners[runner];
            const context = contextsByTestRunner.get(testRunner);

            invariant(context);