Skip to content

testing: expectDiagnostics() should provide an option to ignore ordering #5818

Open
@garethj-msft

Description

@garethj-msft

Clear and concise description of the problem

Overview

Code churn can easily cause diagnostics to appear in changing orders over time, and this should, in general, not be considered a breaking change.

However, library tests that use this helper function will fail when diagnostic order changes.
It's onerous for every library test author to have to add a wrapper to pre-sort the collections; rather the core library should have a mode that enables this with a simple binary switch, as an addition to the options object.

The existing strict option could be used, but that would technically be a behavioral breaking change to the test condition.

Current

compiler/expect.ts/expectDiagnostics(
  diagnostics: readonly Diagnostic[],
  match: DiagnosticMatch | DiagnosticMatch[],
  options = {
    strict: true,
  });

Expected

compiler/expect.ts/expectDiagnostics(
  diagnostics: readonly Diagnostic[],
  match: DiagnosticMatch | DiagnosticMatch[],
  options = {
    strict: true,
    fixedOrder: true
  });

Checklist

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions