Skip to content

test(Autofix Snapshots): Update tests to only display snapshots from last iteration #713

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maxreichmann
Copy link
Member

For devX purposes, it is more convenient to only display Ava snapshot from the last autofix iteration to compare those with the original snapshot.

Without this change, only the less important first iteration is being compared to when being in Ava watch mode.

@maxreichmann maxreichmann requested a review from a team June 18, 2025 10:18
t.snapshot(content, `AutofixResult iteration #${i}: ${filePath}`);
}
// Get the last autofix call to only compare the end result with the current snapshot.
// - 2 because there is always one call without any changes (no fixes applied)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, and good thinking. There's just one case where this doesn't work: Once we hit the maximum number of iterations (currently 10) and still produce fixes.

Maybe a better approach would be to again, go through all the calls in reverse order, and for the first (actually last) one that contains results, create a snapshot?

Actually thinking of this, if an autofix touches multiple files (e.g. when fixing a whole project), you might need a different number of iterations per file. So always only going for the last iteration might completely miss fixes that have been applied to files in earlier iterations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We then probably also have to adjust:

for (let i = 0; i < t.context.autofixSpy.callCount; i++) {
const autofixResult = await t.context.autofixSpy.getCall(i).returnValue;
expectedWrites += autofixResult.size;
const autofixResultEntries = Array.from(autofixResult.entries());
autofixResultEntries.sort((a, b) => a[0].localeCompare(b[0]));
for (const [filePath, content] of autofixResultEntries) {
t.snapshot(content, `AutofixResult iteration #${i}: ${filePath}`);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants