{"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/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/js/40_test_snapshot.js#L335-L371","documentation":"In check mode (a normal `deno test` run), assertSnapshot reads the snapshot file resolved from options.dir/options.path (defaulting next to the test file). If that file does not exist at all, it throws AssertionError \"Missing snapshot file.\" before any comparison (cli/js/40_test_snapshot.js). In update mode (`deno test --update`) the same situation instead creates the file, which is why this error classically appears on the first check-mode run of brand-new snapshot tests.","triggerScenarios":"Running `deno test` (check mode) on tests that call assertSnapshot for the first time with no snapshot file present; the __snapshots__ file was deleted or never committed; options.dir/options.path point at a directory where no snapshot file exists.","commonSituations":"New snapshot tests written but never run with --update; the snapshot file missing from version control so CI fails locally-passing tests; a custom dir/path option that does not match where snapshots were generated; .gitignore rules swallowing the snapshots directory.","solutions":["Run `deno test --update` (or `-u`) once to generate the snapshot file, then re-run plain `deno test`.","Commit the generated snapshot file to version control so CI and teammates have it.","Verify options.dir/options.path resolve to the same location in generate and check runs.","Check that .gitignore does not exclude the __snapshots__ directory or *.snap files."],"exampleFix":"# before\ndeno test   # AssertionError: Missing snapshot file.\n\n# after\ndeno test --update   # create/refresh snapshots\ndeno test            # now passes","handlingStrategy":"validation","validationCode":"// Fail with a clear message before tests run if the snapshot file is absent:\nimport { assert } from \"jsr:@std/assert\";\nconst snap = new URL(\"./__snapshots__/main.spec.snap\", import.meta.url);\nif (import.meta.main === false && !isFirstRun) {\n  assert(Deno.statSync(snap).isFile, `missing snapshot file: ${snap.pathname} — run 'deno test --update'`);\n}","typeGuard":null,"tryCatchPattern":"Deno.test(\"snap\", async (t) => {\n  try {\n    await t.assertSnapshot(value);\n  } catch (err) {\n    if (err instanceof Deno.errors.NotFound || String(err.message).includes(\"Missing snapshot file\")) {\n      throw new Error(\"No snapshot file — run 'deno test --update' first\");\n    }\n    throw err;\n  }\n});","preventionTips":["Run `deno test --update` once when adding new snapshot tests, then run plain `deno test`.","Commit snapshot files to version control and make sure .gitignore excludes neither __snapshots__/ nor *.snap.","Keep options.dir/options.path identical between the run that generates and the run that checks."],"tags":["deno","deno-test","snapshot","assertion","missing-file"],"backgroundTag":"missing-snapshot-file","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}