Skip to content

Add toMatchInlineSnapshot support#55892

Closed
andrewdacenko wants to merge 1 commit intofacebook:mainfrom
andrewdacenko:export-D95077617
Closed

Add toMatchInlineSnapshot support#55892
andrewdacenko wants to merge 1 commit intofacebook:mainfrom
andrewdacenko:export-D95077617

Conversation

@andrewdacenko
Copy link
Contributor

Summary:
Adds toMatchInlineSnapshot() to the Fantom custom expect implementation,
matching Jest's inline snapshot behavior. On first run, snapshot values are
written directly into the test source file as template literal arguments.
On subsequent runs, values are compared and the test fails on mismatch
unless the -u flag is passed to force an update.

The implementation spans the two-process Fantom architecture:

Runtime (Hermes VM):

  • snapshotContext.js: New toMatchInlineSnapshot method that compares
    received values against existing inline snapshots, captures stack traces
    for new/mismatched snapshots, and tracks results per test.
  • expect.js: New toMatchInlineSnapshot method on the Expect class
    that serializes values with prettyFormat and delegates to snapshot context.
  • setup.js: Plumbs inlineSnapshotResults through TestCaseResult.

Runner (Node.js):

  • snapshotUtils.js: New processInlineSnapshotResults resolves VM stack
    traces back to original source locations via source map symbolication.
    New saveInlineSnapshotsToSource directly rewrites the test source file
    by finding each toMatchInlineSnapshot(...) call and replacing its
    argument with the formatted template literal. This avoids jest-snapshot's
    saveInlineSnapshots which requires Babel and Prettier 2.x.
  • runner.js: Generates source maps when inline snapshots need updating,
    collects pending snapshots across test configs, and writes them after
    all configs complete.

Changelog: [Internal]

Differential Revision: D95077617

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 3, 2026
@meta-codesync
Copy link

meta-codesync bot commented Mar 3, 2026

@andrewdacenko has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95077617.

andrewdacenko added a commit to andrewdacenko/react-native that referenced this pull request Mar 3, 2026
Summary:
Pull Request resolved: facebook#55892

Adds `toMatchInlineSnapshot()` to the Fantom custom `expect` implementation,
matching Jest's inline snapshot behavior. On first run, snapshot values are
written directly into the test source file as template literal arguments.
On subsequent runs, values are compared and the test fails on mismatch
unless the `-u` flag is passed to force an update.

The implementation spans the two-process Fantom architecture:

**Runtime (Hermes VM):**
- `snapshotContext.js`: New `toMatchInlineSnapshot` method that compares
  received values against existing inline snapshots, captures stack traces
  for new/mismatched snapshots, and tracks results per test.
- `expect.js`: New `toMatchInlineSnapshot` method on the `Expect` class
  that serializes values with `prettyFormat` and delegates to snapshot context.
- `setup.js`: Plumbs `inlineSnapshotResults` through `TestCaseResult`.

**Runner (Node.js):**
- `snapshotUtils.js`: New `processInlineSnapshotResults` resolves VM stack
  traces back to original source locations via source map symbolication.
  New `saveInlineSnapshotsToSource` directly rewrites the test source file
  by finding each `toMatchInlineSnapshot(...)` call and replacing its
  argument with the formatted template literal. This avoids jest-snapshot's
  `saveInlineSnapshots` which requires Babel and Prettier 2.x.
- `runner.js`: Generates source maps when inline snapshots need updating,
  collects pending snapshots across test configs, and writes them after
  all configs complete.

Changelog: [Internal]

Differential Revision: D95077617
andrewdacenko added a commit to andrewdacenko/react-native that referenced this pull request Mar 3, 2026
Summary:
Pull Request resolved: facebook#55892

Adds `toMatchInlineSnapshot()` to the Fantom custom `expect` implementation,
matching Jest's inline snapshot behavior. On first run, snapshot values are
written directly into the test source file as template literal arguments.
On subsequent runs, values are compared and the test fails on mismatch
unless the `-u` flag is passed to force an update.

The implementation spans the two-process Fantom architecture:

**Runtime (Hermes VM):**
- `snapshotContext.js`: New `toMatchInlineSnapshot` method that compares
  received values against existing inline snapshots, captures stack traces
  for new/mismatched snapshots, and tracks results per test.
- `expect.js`: New `toMatchInlineSnapshot` method on the `Expect` class
  that serializes values with `prettyFormat` and delegates to snapshot context.
- `setup.js`: Plumbs `inlineSnapshotResults` through `TestCaseResult`.

**Runner (Node.js):**
- `snapshotUtils.js`: New `processInlineSnapshotResults` resolves VM stack
  traces back to original source locations via source map symbolication.
  New `saveInlineSnapshotsToSource` directly rewrites the test source file
  by finding each `toMatchInlineSnapshot(...)` call and replacing its
  argument with the formatted template literal. This avoids jest-snapshot's
  `saveInlineSnapshots` which requires Babel and Prettier 2.x.
- `runner.js`: Generates source maps when inline snapshots need updating,
  collects pending snapshots across test configs, and writes them after
  all configs complete.

Changelog: [Internal]

Differential Revision: D95077617
@andrewdacenko andrewdacenko force-pushed the export-D95077617 branch 2 times, most recently from 39aaab6 to 0c22230 Compare March 4, 2026 17:01
andrewdacenko added a commit to andrewdacenko/react-native that referenced this pull request Mar 4, 2026
Summary:

Adds `toMatchInlineSnapshot()` to the Fantom custom `expect` implementation,
matching Jest's inline snapshot behavior. On first run, snapshot values are
written directly into the test source file as template literal arguments.
On subsequent runs, values are compared and the test fails on mismatch
unless the `-u` flag is passed to force an update.

The implementation spans the two-process Fantom architecture:

**Runtime (Hermes VM):**
- `snapshotContext.js`: New `toMatchInlineSnapshot` method that compares
  received values against existing inline snapshots, captures stack traces
  for new/mismatched snapshots, and tracks results per test.
- `expect.js`: New `toMatchInlineSnapshot` method on the `Expect` class
  that serializes values with `prettyFormat` and delegates to snapshot context.
- `setup.js`: Plumbs `inlineSnapshotResults` through `TestCaseResult`.

**Runner (Node.js):**
- `snapshotUtils.js`: New `processInlineSnapshotResults` resolves VM stack
  traces back to original source locations via source map symbolication.
  New `saveInlineSnapshotsToSource` directly rewrites the test source file
  by finding each `toMatchInlineSnapshot(...)` call and replacing its
  argument with the formatted template literal. This avoids jest-snapshot's
  `saveInlineSnapshots` which requires Babel and Prettier 2.x.
- `runner.js`: Generates source maps when inline snapshots need updating,
  collects pending snapshots across test configs, and writes them after
  all configs complete.

Changelog: [Internal]

Differential Revision: D95077617
andrewdacenko added a commit to andrewdacenko/react-native that referenced this pull request Mar 4, 2026
Summary:
Pull Request resolved: facebook#55892

Adds `toMatchInlineSnapshot()` to the Fantom custom `expect` implementation,
matching Jest's inline snapshot behavior. On first run, snapshot values are
written directly into the test source file as template literal arguments.
On subsequent runs, values are compared and the test fails on mismatch
unless the `-u` flag is passed to force an update.

The implementation spans the two-process Fantom architecture:

**Runtime (Hermes VM):**
- `snapshotContext.js`: New `toMatchInlineSnapshot` method that compares
  received values against existing inline snapshots, captures stack traces
  for new/mismatched snapshots, and tracks results per test.
- `expect.js`: New `toMatchInlineSnapshot` method on the `Expect` class
  that serializes values with `prettyFormat` and delegates to snapshot context.
- `setup.js`: Plumbs `inlineSnapshotResults` through `TestCaseResult`.

**Runner (Node.js):**
- `snapshotUtils.js`: New `processInlineSnapshotResults` resolves VM stack
  traces back to original source locations via source map symbolication.
  New `saveInlineSnapshotsToSource` directly rewrites the test source file
  by finding each `toMatchInlineSnapshot(...)` call and replacing its
  argument with the formatted template literal. This avoids jest-snapshot's
  `saveInlineSnapshots` which requires Babel and Prettier 2.x.
- `runner.js`: Generates source maps when inline snapshots need updating,
  collects pending snapshots across test configs, and writes them after
  all configs complete.

Changelog: [Internal]

Differential Revision: D95077617
andrewdacenko added a commit to andrewdacenko/react-native that referenced this pull request Mar 4, 2026
Summary:
Pull Request resolved: facebook#55892

Adds `toMatchInlineSnapshot()` to the Fantom custom `expect` implementation,
matching Jest's inline snapshot behavior. On first run, snapshot values are
written directly into the test source file as template literal arguments.
On subsequent runs, values are compared and the test fails on mismatch
unless the `-u` flag is passed to force an update.

The implementation spans the two-process Fantom architecture:

**Runtime (Hermes VM):**
- `snapshotContext.js`: New `toMatchInlineSnapshot` method that compares
  received values against existing inline snapshots, captures stack traces
  for new/mismatched snapshots, and tracks results per test.
- `expect.js`: New `toMatchInlineSnapshot` method on the `Expect` class
  that serializes values with `prettyFormat` and delegates to snapshot context.
- `setup.js`: Plumbs `inlineSnapshotResults` through `TestCaseResult`.

**Runner (Node.js):**
- `snapshotUtils.js`: New `processInlineSnapshotResults` resolves VM stack
  traces back to original source locations via source map symbolication.
  New `saveInlineSnapshotsToSource` directly rewrites the test source file
  by finding each `toMatchInlineSnapshot(...)` call and replacing its
  argument with the formatted template literal. This avoids jest-snapshot's
  `saveInlineSnapshots` which requires Babel and Prettier 2.x.
- `runner.js`: Generates source maps when inline snapshots need updating,
  collects pending snapshots across test configs, and writes them after
  all configs complete.

Changelog: [Internal]

Differential Revision: D95077617
Summary:

Adds `toMatchInlineSnapshot()` to the Fantom custom `expect` implementation,
matching Jest's inline snapshot behavior. On first run, snapshot values are
written directly into the test source file as template literal arguments.
On subsequent runs, values are compared and the test fails on mismatch
unless the `-u` flag is passed to force an update.

The implementation spans the two-process Fantom architecture:

**Runtime (Hermes VM):**
- `snapshotContext.js`: New `toMatchInlineSnapshot` method that compares
  received values against existing inline snapshots, captures stack traces
  for new/mismatched snapshots, and tracks results per test.
- `expect.js`: New `toMatchInlineSnapshot` method on the `Expect` class
  that serializes values with `prettyFormat` and delegates to snapshot context.
- `setup.js`: Plumbs `inlineSnapshotResults` through `TestCaseResult`.

**Runner (Node.js):**
- `snapshotUtils.js`: New `processInlineSnapshotResults` resolves VM stack
  traces back to original source locations via source map symbolication.
  New `saveInlineSnapshotsToSource` directly rewrites the test source file
  by finding each `toMatchInlineSnapshot(...)` call and replacing its
  argument with the formatted template literal. This avoids jest-snapshot's
  `saveInlineSnapshots` which requires Babel and Prettier 2.x.
- `runner.js`: Generates source maps when inline snapshots need updating,
  collects pending snapshots across test configs, and writes them after
  all configs complete.

Changelog: [Internal]

Differential Revision: D95077617
@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @andrewdacenko in 43278f9

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Mar 5, 2026
@meta-codesync
Copy link

meta-codesync bot commented Mar 5, 2026

This pull request has been merged in 43278f9.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants