Skip to content

bun test --update-snapshots rewrites the .snap file in execution order, reordering unchanged entries #42969

Open

Description

@slaskis

What version of Bun is running?

1.4.2

What platform is your computer?

Darwin 24.6.0 arm64 arm

What steps can reproduce the bug?

order.test.ts:

import { describe, expect, test } from "bun:test";
describe("suite", () => {
  test("zeta", () => { expect({ z: 1 }).toMatchSnapshot(); });
  test("alpha", () => { expect({ a: 1 }).toMatchSnapshot(); });
});
  1. bun test order.test.ts writes __snapshots__/order.test.ts.snap with suite zeta 1 before suite alpha 1 (execution order).
  2. Hand-sort the file (alpha first), run bun test order.test.ts: passes, order kept. Add a third test: the new entry is appended. Good so far.
  3. bun test --update-snapshots order.test.ts: the file is rewritten as zeta, mid, alpha, i.e. every unchanged entry moves.

What is the expected behavior?

Jest sorts snapshot keys (natural compare) on every write, so a regenerated file only shows the entries whose values changed. Either sorted keys, or keeping the existing file order and appending new keys (what the plain run already does), would keep --update-snapshots diffs reviewable.

What do you see instead?

--update-snapshots emits entries in the order the tests ran, so a one-value update to a file whose tests are not declared alphabetically reorders the whole file. In a repo with 10 snapshot files and 87 entries the migration diff was about 2900 lines of reorder for one changed value.

Additional information

Related: node:test's t.assert.snapshot is not implemented in the node:test shim, so suites moving from Node's runner also lose the >-joined keys and the <test>.snapshot file next to the test.

Activity

  1. robobun commented on Sep 16, 2026

    @robobun
    Collaborator

    Reproduced on 1.4.3: bun test --update-snapshots truncates the .snap file and writes every entry in execution order.
    Fix in progress: #43043. It keeps the existing file order, replaces changed values in place, and appends new keys. It also keeps the entries of tests that did not run (-t, .only, .skip). It replaces #42980.

  2. added
    bun:testSomething related to the `bun test` runner
    on Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbun:testSomething related to the `bun test` runnerneeds triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions