{"record":{"id":"16c602ab9f6457bf","repo":"denoland/deno","slug":"missing-snapshot-file","errorCode":null,"errorMessage":"Missing snapshot file.","messagePattern":"Missing snapshot file\\.","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"cli/js/40_test_snapshot.js","lineNumber":353,"sourceCode":"  const actualSnapshot = serializer(actual);\n  if (typeof actualSnapshot !== \"string\") {\n    throw new TypeError(\"Snapshot serializer must return a string\");\n  }\n\n  const expectedSnapshot = MapPrototypeGet(context.currentValues, name);\n\n  if (getIsUpdateMode()) {\n    if (actualSnapshot !== expectedSnapshot) {\n      MapPrototypeSet(context.updatedValues, name, actualSnapshot);\n      if (!ArrayPrototypeIncludes(context.updatedNames, name)) {\n        ArrayPrototypePush(context.updatedNames, name);\n      }\n    }\n    return;\n  }\n\n  if (!context.fileExists) {\n    throw new AssertionError(\n      getErrorMessage(\"Missing snapshot file.\", options),\n    );\n  }\n  if (expectedSnapshot === undefined) {\n    throw new AssertionError(\n      getErrorMessage(`Missing snapshot: ${name}`, options),\n    );\n  }\n  if (actualSnapshot === expectedSnapshot) {\n    return;\n  }\n  throw new AssertionError(\n    getErrorMessage(\n      getSnapshotNotMatchMessage(actualSnapshot, expectedSnapshot),\n      options,\n    ),\n  );\n}","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/cli/js/40_test_snapshot.js#L335-L371","documentation":"AssertionError from assertSnapshot() (cli/js/40_test_snapshot.js): the test asserts a snapshot but the snapshot file (context.fileExists is false) does not exist, and the run is not in update mode. Snapshot files are only created/updated when `deno test --update-snapshots` runs, so a first run without the flag cannot pass.","triggerScenarios":"Adding t.assertSnapshot() to a test file whose __snapshot__ file hasn't been generated yet; deleting or renaming the snapshot file; running tests in a fresh checkout/CI where snapshot files are not committed; CI running a path-filtered subset before snapshots were ever committed.","commonSituations":"First introduction of snapshot testing to a repo without immediately running with --update-snapshots; .gitignore accidentally excluding __snapshot__ directories; snapshot file generated locally but not committed, so CI fails.","solutions":["Run `deno test --update-snapshots` once to create the file, then commit it","Ensure the __snapshot__ directory is not gitignored and ships with the repo","In CI, run the plain `deno test` (no flag) so committed snapshots are verified rather than rewritten"],"exampleFix":"# before\ndeno test                     # AssertionError: Missing snapshot file.\n\n# after\ndeno test --update-snapshots   # creates/refreshes __snapshot__ files; commit them\ngit add **/__snapshot__/** && git commit -m \"test: add snapshots\"","handlingStrategy":"validation","validationCode":"// before running the suite, verify the snapshot file exists\nimport { existsSync } from \"node:fs\";\nif (!existsSync(new URL(\"./__snapshot__/<file>_test.ts.snap\", import.meta.url))) {\n  // first run: generate instead of fail\n  await new Deno.Command(Deno.execPath(), {\n    args: [\"test\", \"--update-snapshots\", import.meta.filename],\n  }).spawn().status;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `deno test --update-snapshots` immediately after adding a snapshot test, and commit the file","Do not gitignore __snapshot__ directories; CI must verify committed snapshots without the flag"],"tags":["testing","snapshot","assertion","ci","workflow"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}