Skip to content

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

Open

Description

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.

Activity

  1. added
    good first issue
    compiler:core
    on Jan 30, 2025
  2. timotheeguerin commented on Jan 30, 2025

    @timotheeguerin
    Member

    That would be nice but I think in general it would be better practice to make sure your test only emit a single diagnostic.
    Not doing order makes it also potentially harder to see what isn't matching(would just be able to say didn't find this exect diagnostic in this list).

  3. added
    design:needed
    on Feb 3, 2025
  4. added
    feature
    and removed
    design:needed
    on Feb 3, 2025
  5. markcowl commented on Feb 3, 2025

    @markcowl
    Contributor

    Have expectDiagnostics sort the diagnostics

  6. harlanenciso112 commented on May 23, 2025

    @harlanenciso112

    I would like to work on this

  7. zVapor-Dev commented on Nov 20, 2026

    @zVapor-Dev
    Member

    I'd like to work on this since pr #7453 was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler:corefeaturegood first issuetriaged:core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions