ChilliCream / ChilliCream/graphql-platform

Snapshot.Match — support configurable snapshot root independent of source file location

Open
#9,654 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ hot chocolate
Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
15h 39m
Merged PRs (30d)
98

Description

Product

Hot Chocolate

Is your feature request related to a problem?

Snapshot.Match resolves the snapshot directory by walking the call-site StackTrace to derive
the test file's source path, then appending __snapshots__/. This breaks when the canonical
snapshot file lives outside the project directory. In a monorepo it's common to keep shared
artifacts at a top-level path (e.g. schemas/graphql/service.graphqls at repo root) that is
intentionally shared across consumers. The test project lives at cloud/my-service/tests/, so
the source-derived path resolves to somewhere under there — not to schemas/.

Because there is no way to override the resolved path, we could not use Snapshot.Match for a
GraphQL schema snapshot test that needed to compare against schemas/graphql/service.graphqls.
We had to reimplement the pattern manually: read via Assembly.GetManifestResourceStream and write
the mismatch to an AppContext-injected path on failure.

The solution you'd like

Two complementary overloads/settings would cover the main cases:

1 — explicit expected value overload

Snapshot.Match(actual, expected);

When expected is supplied explicitly, skip all StackFrame-based resolution. On mismatch,
write actual to the mismatch path and produce the usual diff in the assertion failure message.

2 — configurable snapshot root and mismatch directory

// global default (e.g. from AppContext / runtimeconfig.json)
SnapshotSettings.Default.SnapshotRootDirectory = "/repo/schemas/graphql";
SnapshotSettings.Default.MismatchDirectory     = "/repo/schemas/graphql/__mismatch__";

// or per-call
Snapshot.Match(actual, s => s.SnapshotRootDirectory("/repo/schemas/graphql"));

Resolve .snap relative to this directory instead of the source file. The mismatch write
on failure follows the same configured path rather than a source-tree-relative one.

Either option would let us remove the manual boilerplate we have today and use Snapshot.Match
directly, while keeping the auto-write-on-fail UX that makes snapshot tests practical.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Snapshot.Match entry point and inspect its StackTrace-based snapshot-path resolution and mismatch writing behavior. Compare the explicit expected-value and configurable-root options described here, then verify that snapshots and mismatches can resolve outside the test project's source tree while preserving the usual diff and failure behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.