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

Code before:
  if (/\s/.test(path))
    return `"${path}"`;
  return path;
}

const kReportedSymbol = Symbol('reported');

export function formatResultFailure(screen: Screen, test: TestCase, result: TestResult, initialIndent: string): ErrorDetails[] {
  const errorDetails: ErrorDetails[] = [];

  if (result.status === 'passed' && test.expectedStatus === 'failed') {
    errorDetails.push({
      message: indent(screen.colors.red(`Expected to fail, but passed.`), initialIndent),
    });
  }
  if (result.status === 'interrupted') {
    errorDetails.push({
      message: indent(screen.colors.red(`Test was interrupted.`), initialIndent),
    });
  }

  const reportedIndex = (result as any)[kReportedSymbol] || 0;
  (result as any)[kReportedSymbol] = result.errors.length;
  for (const error of result.errors.slice(reportedIndex)) {
    const formattedError = formatError(screen, error);
    errorDetails.push({
      message: indent(formattedError.message, initialIndent),
      location: formattedError.location,
    });
  }
  return errorDetails;
}

export function relativeFilePath(screen: Screen, config: FullConfig, file: string): string {
  if (screen.resolveFiles === 'cwd')
    return path.relative(process.cwd(), file);
  return path.relative(config.rootDir, file);
}

function relativeTestPath(screen: Screen, config: FullConfig, test: TestCase): string {
  return relativeFilePath(screen, config, test.location.file);
}

export function stepSuffix(step: TestStep | undefined) {
  const stepTitles = step ? step.titlePath() : [];
  return stepTitles.map(t => t.split('\n')[0]).map(t => ' › ' + t).join('');
}

function formatTestTitle(screen: Screen, config: FullConfig, test: TestCase, step?: TestStep, options: { includeTestId?: boolean } = {}): string {
  // root, project, file, ...describes, test
  const [, projectName, , ...titles] = test.titlePath();

Review comment (suggestion):
Let's make this an explicit call, something like `markErrorsAsReported(result)`, to avoid surprises in the future.

Code after:
  if (/\s/.test(path))
    return `"${path}"`;
  return path;
}

const kReportedSymbol = Symbol('reported');

export function markErrorsAsReported(result: TestResult) {
  (result as any)[kReportedSymbol] = result.errors.length;
}

export function formatResultFailure(screen: Screen, test: TestCase, result: TestResult, initialIndent: string): ErrorDetails[] {
  const errorDetails: ErrorDetails[] = [];

  if (result.status === 'passed' && test.expectedStatus === 'failed') {
    errorDetails.push({
      message: indent(screen.colors.red(`Expected to fail, but passed.`), initialIndent),
    });
  }
  if (result.status === 'interrupted') {
    errorDetails.push({
      message: indent(screen.colors.red(`Test was interrupted.`), initialIndent),
    });
  }

  const reportedIndex = (result as any)[kReportedSymbol] || 0;
  for (const error of result.errors.slice(reportedIndex)) {
    const formattedError = formatError(screen, error);
    errorDetails.push({
      message: indent(formattedError.message, initialIndent),
      location: formattedError.location,
    });
  }
  return errorDetails;
}

export function relativeFilePath(screen: Screen, config: FullConfig, file: string): string {
  if (screen.resolveFiles === 'cwd')
    return path.relative(process.cwd(), file);
  return path.relative(config.rootDir, file);
}

function relativeTestPath(screen: Screen, config: FullConfig, test: TestCase): string {
  return relativeFilePath(screen, config, test.location.file);
}

export function stepSuffix(step: TestStep | undefined) {
  const stepTitles = step ? step.titlePath() : [];
  return stepTitles.map(t => t.split('\n')[0]).map(t => ' › ' + t).join('');
}