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

Aperta
#27 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
42/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript
Ambito
testing-qa

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Nessun dato sulla lingua
Stelle
3
Fork
4
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/test-runner

Tutte le issue di nodejs/test-runner

Issue simili

Altre issue su Testing & QA

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.