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

Ouverte
#27 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
42/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Calme
Stack technique
javascript
Domaine
testing-qa

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Aucune donnée de langage
Étoiles
3
Forks
4
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de nodejs/test-runner

Toutes les issues de nodejs/test-runner

Issues similaires

Plus d'issues Testing & QA

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.