Repository: facebook/jest
File: packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts (TypeScript)

Code before:
          },
        ],
        failureMessage: 'Failure message',
        perfStats: {
          runtime: 20,
          slow: false,
        },
        testFilePath: '/testDir/test1.js',
        testResults: [
          {
            ancestorTitles: [],
            duration: 10,
            status: 'passed',
            title: 'test1',
          },
        ],
      };
      const mockResults = {
        numFailedTestSuites: 1,
        numPassedTestSuites: 2,
        numTotalTestSuites: 3,
        testResults: [mockTestResult],
      };
      const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
        silent: false,
      });
      gha.generateAnnotations = jest.fn();

      gha.onTestResult(
        mockTest as Test,
        mockTestResult as unknown as TestResult,
        mockResults as unknown as AggregatedResult,
      );

      expect(mockedStderrWrite.mock.calls).toMatchSnapshot();
    });

    test('onTestResult last with console output for success test', () => {
      const mockTest = {
        context: {
          config: {
            rootDir: '/testDir',
          },
        },
      };
      const mockTestResult = {
        console: [
          {
            message: 'bar',
            origin:
              '    at Object.log (/tmp/jest-test/a.test.js:2:13)\n    at Promise.finally.completed (/github.com/jestjs/jest/packages/jest-circus/build/jestAdapterInit.js:1557:28)',

Review comment (refactor):
you can use helpers from `@jest/test-utils` to create global and project configs

https://github.com/jestjs/jest/blob/6813dfa8c78f0232726db88e31c04780d785b3bf/packages/test-utils/src/config.ts#L141-L175

Code after:
        ],
        failureMessage: 'Failure message',
        perfStats: {
          runtime: 20,
          slow: false,
        },
        testFilePath: '/testDir/test1.js',
        testResults: [
          {
            ancestorTitles: [],
            duration: 10,
            status: 'passed',
            title: 'test1',
          },
        ],
      };
      const mockResults = {
        numFailedTestSuites: 1,
        numPassedTestSuites: 2,
        numTotalTestSuites: 3,
        testResults: [mockTestResult],
      };
      const gha = new GitHubActionsReporter(makeGlobalConfig(), {
        silent: false,
      });
      gha.generateAnnotations = jest.fn();

      gha.onTestResult(
        mockTest as Test,
        mockTestResult as unknown as TestResult,
        mockResults as unknown as AggregatedResult,
      );

      expect(mockedStderrWrite.mock.calls).toMatchSnapshot();
    });

    test('onTestResult last with console output for success test', () => {
      const mockTest = {
        context: {
          config: {
            rootDir: '/testDir',
          },
        },
      };
      const mockTestResult = {
        console: [
          {
            message: 'bar',
            origin:
              '    at Object.log (/tmp/jest-test/a.test.js:2:13)\n    at Promise.finally.completed (/github.com/jestjs/jest/packages/jest-circus/build/jestAdapterInit.js:1557:28)',
            type: 'log',