Proposal: adjust snapshot file label to account for subtest label (~breaking)

Offen
#27 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
42/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
javascript
Bereich
testing-qa

Rechercherichtung

No files or tests are named. Start by locating the snapshot assertion handling and the snapshot-file reading and writing entry points in this repository. Done means subtest labels replace ordinal labels, and unchanged cases can be migrated with a console notice as described.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Problem(s) to solve

When a test leverages snapshot assertions, the label of the case within the snapshot file references only suite (describe) and test (it) labels, and then an integer representing the sequential position of that snapshot assertion within the test.

For example:

describe('Widget', () => {
  it('should do a thing', (t) => {
    t.test('db query', () => t.assert.snapshot(…));
    t.test('post request', () => t.assert.snapshot(…));
  });
});

Results in a snapshot file like:

exports[`Widget > should do a thing 1`] = `…`; // db query
exports[`Widget > should do a thing 2`] = `…`; // post query

When another snapshot assertion is added between them, Widget > should do a thing 2's value is changed to the new thing (and Widget > should do a thing 3 is appended with the value of what was formerly "2"). This creates two problems:

  • a confusing and overly large diff
  • a rather unfriendly file for a human to read

Proposed solution(s)

When a subtest wraps the snapshot assertion, use the subtest's label instead of the sequential counter:

exports[`Widget > should do a thing > db query`] = `…`;
exports[`Widget > should do a thing > post query`] = `…`;

We can mitigate a breaking change by temporarily including a migration: when reading the snapshot file, if there is an ordinal and there is a subtest, when the case value is unchanged, replace the ordinal with the subtest label and write it to disk whilst outputting a notice to the console.

Vorherrschende Sprache
Keine Sprachdaten
Sterne
3
Forks
4
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus nodejs/test-runner

Alle Issues in nodejs/test-runner

Ähnliche Issues

Weitere Issues zu Testing & QA

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.