Skip to content

Fantom: two tests with the same full name share one snapshot key, so one of them fails on the next run #60590

Backlog

Description

@YevheniiKotyrlo

Description

I found this while reading how Fantom keys snapshots, with test.each tables in mind, whose rows can share a title.

Fantom starts each test's snapshot count at 0 (runtime/snapshotContext.js L91-L97) and keys each toMatchSnapshot by the test's full name and that count (L117), so two tests with the same full name both key their first snapshot <full name> 1. The snapshot file then holds one of their values, and the other test fails against it. Jest's snapshot state counts calls per full name across the whole file, so two tests titled same write same 1 and same 2.

Steps to reproduce

  1. Clone the reproducer below and run ./fantom/reproduce.sh snapshot-keys. It needs only Docker: it clones react/react-native at main, builds Fantom's tester with yarn workspace @react-native/fantom build using Clang and LLD 23.1.3, with two settings the reproducer adds for that Clang (-Wno-error=deprecated-literal-operator, and SKCMS_NO_RUNTIME_CPU_DETECTION for Skia's skcms), copies fantom/SnapshotKeys-itest.js into private/react-native-fantom/src/__tests__/ and runs yarn fantom --ci=false twice on it, printing the snapshot file between the runs:
[…]
test('same', () => {
  expect(1).toMatchSnapshot();
});

test('same', () => {
  expect(2).toMatchSnapshot();
});

Expected: the first run writes same 1 and same 2, and the second run passes both tests.

Actual: the first run writes same 1 alone and reports the second test's snapshot as failed while the test passes; the second run fails the second test, and the script exits 1:

[…]
react-native eb37db0c4448a7d26684a5d8b4027166c13fc3e2, committed 2026-12-05T08:30:53+00:00
[…]
== the first run, which writes the snapshots
[…]
PASS fantom private/react-native-fantom/src/__tests__/SnapshotKeys-itest.js (5.643 s)
  SnapshotKeys (hermes)
    ✓ same (4 ms)
    ✓ same

 › 1 snapshot written.
 › 1 snapshot failed.
[…]
Tests:       2 passed, 2 total
Snapshots:   1 failed, 1 written, 2 total
[…]
yarn fantom exited with status 1
== private/react-native-fantom/src/__tests__/__snapshots__/SnapshotKeys-itest.js.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`same 1`] = `1`;
== the second run
[…]
FAIL fantom private/react-native-fantom/src/__tests__/SnapshotKeys-itest.js
  SnapshotKeys (hermes)
    ✓ same (4 ms)
    ✕ same (6 ms)

  ● SnapshotKeys (hermes) › same

    Expected to match snapshot.
    - Expected
    + Received

    - 1
    + 2
[…]
Tests:       1 failed, 1 passed, 2 total
Snapshots:   1 failed, 1 passed, 2 total
[…]
yarn fantom exited with status 1
SUMMARY: both tests' snapshots are keyed same 1, so the file holds one of them and the second run fails the other test

React Native Version

main at eb37db0; 0.88.1 keys snapshots the same way

Affected Platforms

Other (please specify): Fantom, yarn fantom

Output of npx @react-native-community/cli info

Not applicable: Fantom runs from a checkout of this repository. The reproducer builds and runs it in the reactnativecommunity/react-native-android image with clang version 23.1.3.

Stacktrace or Logs

[…]
  ● SnapshotKeys (hermes) › same

    Expected to match snapshot.
    - Expected
    + Received

    - 1
    + 2
        at construct (native)
        at apply (native)

       9 |
      10 | test('same', () => {
    > 11 |   expect(2).toMatchSnapshot();
         |                            ^
      12 | });
      13 |
[…]

MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/react-native-fantom-reproducer

Screenshots and Videos

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions