Repository navigation
Description
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
- Clone the reproducer below and run
./fantom/reproduce.sh snapshot-keys. It needs only Docker: it clonesreact/react-nativeatmain, builds Fantom's tester withyarn workspace @react-native/fantom buildusing Clang and LLD 23.1.3, with two settings the reproducer adds for that Clang (-Wno-error=deprecated-literal-operator, andSKCMS_NO_RUNTIME_CPU_DETECTIONfor Skia's skcms), copiesfantom/SnapshotKeys-itest.jsintoprivate/react-native-fantom/src/__tests__/and runsyarn fantom --ci=falsetwice 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
Activity