Repository: microsoft/playwright
File: packages/playwright/src/reporters/teleEmitter.ts (TypeScript)

Code before:

  onTestEnd(test: reporterTypes.TestCase, result: reporterTypes.TestResult): void {
    const testEnd: teleReceiver.JsonTestEnd = {
      testId: test.id,
      expectedStatus: test.expectedStatus,
      timeout: test.timeout,
      annotations: []
    };
    this._sendNewErrors(result, test.id);
    this._sendNewAttachments(result, test.id);
    this._messageSink({
      method: 'onTestEnd',
      params: {
        test: testEnd,
        result: this._serializeResultEnd(result),
      }
    });

    const resultId = (result as any)[this._idSymbol] as string;
    this._resultKnownAttachmentCounts.delete(resultId);
    this._resultKnownErrorsCounts.delete(resultId);
  }

  onStepBegin(test: reporterTypes.TestCase, result: reporterTypes.TestResult, step: reporterTypes.TestStep): void {
    (step as any)[this._idSymbol] = createGuid();
    this._sendNewErrors(result, test.id);
    this._messageSink({
      method: 'onStepBegin',
      params: {
        testId: test.id,
        resultId: (result as any)[this._idSymbol],
        step: this._serializeStepStart(step),
      }
    });
  }

  onStepEnd(test: reporterTypes.TestCase, result: reporterTypes.TestResult, step: reporterTypes.TestStep): void {
    // Create synthetic onAttach event so we serialize the entire attachment along with the step
    const resultId = (result as any)[this._idSymbol] as string;
    this._sendNewAttachments(result, test.id);

    this._messageSink({
      method: 'onStepEnd',
      params: {
        testId: test.id,
        resultId,
        step: this._serializeStepEnd(step, result)
      }
    });
  }


Review comment (suggestion):
```suggestion
    // This is here to support "test paused" step, where we want to see all errors
    // at the time of the pause. If we were to have `onTestError()` reporter api, this
    // won't be needed.
    this._sendNewErrors(result, test.id);
```

Code after:
  onTestError(test: reporterTypes.TestCase, result: reporterTypes.TestResult, error: reporterTypes.TestError): void {
    this._messageSink({
      method: 'onTestError',
      params: {
        testId: test.id,
        resultId: (result as any)[this._idSymbol],
        error,
      }
    });
  }

  onTestEnd(test: reporterTypes.TestCase, result: reporterTypes.TestResult): void {
    const testEnd: teleReceiver.JsonTestEnd = {
      testId: test.id,
      expectedStatus: test.expectedStatus,
      timeout: test.timeout,
      annotations: []
    };
    this._sendNewAttachments(result, test.id);
    this._messageSink({
      method: 'onTestEnd',
      params: {
        test: testEnd,
        result: this._serializeResultEnd(result),
      }
    });

    this._resultKnownAttachmentCounts.delete((result as any)[this._idSymbol]);
  }

  onStepBegin(test: reporterTypes.TestCase, result: reporterTypes.TestResult, step: reporterTypes.TestStep): void {
    (step as any)[this._idSymbol] = createGuid();
    this._messageSink({
      method: 'onStepBegin',
      params: {
        testId: test.id,
        resultId: (result as any)[this._idSymbol],
        step: this._serializeStepStart(step)
      }
    });
  }

  onStepEnd(test: reporterTypes.TestCase, result: reporterTypes.TestResult, step: reporterTypes.TestStep): void {
    // Create synthetic onAttach event so we serialize the entire attachment along with the step
    const resultId = (result as any)[this._idSymbol] as string;
    this._sendNewAttachments(result, test.id);

    this._messageSink({
      method: 'onStepEnd',
      params: {
        testId: test.id,