-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Deterministic snaphot files, declaration-ordered snapshot reports #2610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Produce a taskIndex for each hook and test. Sort snapshot headers (called `belongsTo`) according to the taskIndex in which their first snapshot was declared.
This should ensure that all sort keys are unique and so determinism is not affected by the stability of Array.prototype.sort().
Adds a third sort key, associatedTaskIndex, only set on Each hooks. Preserves sort determinism on node v10.
624a47c
to
d6b25db
Compare
Sorry, it seems like the testing approach I took doesn't work in CI. I'll have to rethink how to test this. |
This looks really promising @ninevra! Let me know how I can help!
No, I think this is fine. As long as existing snapshot files are accepted we're good. |
When ava is run in CI, new snapshots cannot be written. In normal circumstances, this ensures that snapshot assertions don't get merged without a recorded snapshot; lacking this feature, CI could appear to pass when in fact snapshot assertions were not checked. In this case, however, writing snapshots is intended.
The remaining CI failures are also present on master when running on node v15.3.0. This appears to be unrelated to this PR, and may not actually a bug; reported in #2616. I'd still like to add more tests to this, ideally asserting that existing snapshots aren't rewritten. |
These snapshots are always recreated and their exact content is not tested, so they shouldn't be version controlled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still like to add more tests to this, ideally asserting that existing snapshots aren't rewritten.
The test coverage is impressively thorough already! What do you mean by not rewriting existing snapshots? FWIW if the files are deterministic I'm not overly concerned about writing unnecessarily. Not sure how to test that either other than by looking at modification dates maybe… doesn't seem worthwhile.
I left two minor comments on the tests. Nice use of the self-testing setup.
The remaining CI failures are also present on master when running on node v15.3.0. This appears to be unrelated to this PR, and may not actually a bug; reported in #2616.
Thanks, fixing in #2618.
@ninevra if you pull in latest It does contain some linter related changes so there may be a bit of churn. |
I was referring to the The test coverage is complete now as far as I'm concerned. (Although, the |
Co-authored-by: Mark Wubben <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, the
backwards-compatibility
suite is not of any real value after this point, and is difficult to maintain; if the snapshot file format is changed in the future, obtaining valid & unsorted snapshots will be difficult, so the suite should probably be removed at that point. We could remove it preemptively now to reduce maintainence burden.
Yes let's do that.
There's a few more places where we could write the in-memory buffers. Other than that I think this is good to go!
If you wouldn't mind touching this up I'll try and get it out in a release soon.
Removed the |
Awesome, thanks @ninevra! |
3.14 is live with these changes. |
Wow, maybe I can remove this hack sindresorhus/eslint-plugin-unicorn#842 👍 |
Closes #2311
Closes #2324
Ensures that
*.snap
files are deterministic by sorting entry blocks by the hash of their test name or id.Ensures that
*.md
snapshot report files are sorted in as close to declaration order as is reasonably possible, bytaskIndex
incremental id for each test case and hook,associatedTaskIndex
for eachbeforeEach
,afterEach
, andafterEachAlways
hook, indicating the associated task case,snapshotCount
through tosnapshotManager
, andtaskIndex
,associatedTaskIndex
, andsnapshotCount
of the first snapshot therein.Caveats
*.snap
files are not sorted by declaration order, only*.md
files. Sorting*.snap
s by declaration order is more complicated, because when running inappendOnly
mode (i.e. without the-u
flag) they may contain entries which are never touched during the course of the run. These entries would then have to be sorted among the others in a deterministic fashion. While this could be accomplished with a fallback to sorting by hash, it's not clear where such entries should appear in the sort order. It's also not clear that this grants any benefit, since after encoding and compressing the order of entries is not readily apparent to a human reader in any case.appendOnly
mode, only the new report entries are sorted in declaration order, and only among themselves.beforeEach
andafterEach
hooks. Further,*Each
hooks are run multiple times, sotaskIndex
andsnapshotCount
don't uniquely identify them, requiring a third sort key (associatedTaskIndex
). This should only matter until the next AVA major version, given Disable snapshots and try assertions in hooks #2523.Release concerns
As far as I can tell, this change won't affect any existing codebases'
*.snap
or*.md
files until either AVA is run with-u
or some change is made to the corresponding tests.snapshotManager
s existing behavior is to not record anything, even internally, unless-u
is enabled or there was no preexisting snapshot to compare to. However, this is difficult to definitively test.No changes have been made to the snapshot file format.
Remaining issues
When AVA is run with
-u
, projects may see unexpected snapshot updates as their snapshots and reports are resorted. Avoiding this would require reworkingsnapshotManager
to: load saved snapshots even when-u
is present; always report success fromcompare()
if-u
is present; and write updates only if some conflict or new snapshot was encountered.Should this be placed behind a feature flag, to reduce the incidence of spurious updates?