mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 20:39:05 +00:00
Fixes snapshot tests so that when using -u to update snapshots, the order of snapshots in the file is preserved instead of being rewritten in test execution order. This also fixes using -u in combination with -t test filters. **Problem:** When updating snapshots with the -u flag, the entire snapshot file was being truncated and rewritten in the order tests execute, causing: 1. Large diffs in version control 2. Confusing order changes 3. Issues when using -t filters to update specific snapshots **Solution:** - Track the location of each snapshot in the file using a LocationsHashMap - When updating a snapshot, replace it in-place rather than rewriting the entire file - Preserve the original formatting (leading newlines) when updating - Only read the file once (don't truncate on update mode) **Changes:** - Added SnapshotLocation struct to track start/end offsets - Added locations HashMap to Snapshots struct - Modified parseFile to track snapshot locations as it parses - Modified getOrPut to update snapshots in-place when update_snapshots is true - Removed O.TRUNC flag from file opening in update mode - Added regression test 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>