-
-
Notifications
You must be signed in to change notification settings - Fork 5
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 queryWhen 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.