{"name":"@vitest/snapshot","version":"5.0.2","keywords":["vitest","test","snapshot"],"license":"MIT","_id":"@vitest/snapshot@5.0.2","maintainers":[{"name":"ariperkkio","email":"ari.perkkio@gmail.com"},{"name":"antfu","email":"anthonyfu117@hotmail.com"},{"name":"hiogawa","email":"hi.ogawa.zz@gmail.com"},{"name":"oreanno","email":"foxzdavinci@gmail.com"},{"name":"yyx990803","email":"yyx990803@gmail.com"}],"homepage":"https://vitest.dev/guide/snapshot","bugs":{"url":"https://github.com/vitest-dev/vitest/issues"},"dist":{"shasum":"a403aa8fa04124f0dd2ddd49ae879f5f77020246","tarball":"http://registry-npm.ywwl.com/@vitest/snapshot/download/@vitest/snapshot-5.0.2.tgz","fileCount":13,"integrity":"sha512-G5FHntzv8AVx5wkoWPgWqpJm2ngrdnFcQtjbsGFToNoNin5XTzd5qQjllYqX5xxplXs5BMOaZXqKVx0Zks8GpA==","signatures":[{"sig":"MEYCIQCGu3TAVYXqC1oCPkKB5caoh0PT85IoSgA9lb7TyVKPngIhANlINUTBW+vXv55of19tSzdV2nw7xkqvOvvtPG5D9r8q","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@vitest%2fsnapshot@5.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":61348,"size":17931,"noattachment":false,"key":"/@vitest/snapshot/-/@vitest/snapshot-5.0.2.tgz"},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js","__vitest_source__":"./src/index.ts"},"./manager":{"types":"./dist/manager.d.ts","default":"./dist/manager.js","__vitest_source__":"./src/manager.ts"},"./environment":{"types":"./dist/environment.d.ts","default":"./dist/environment.js","__vitest_source__":"./src/environment.ts"},"./package.json":"./package.json"},"funding":"https://opencollective.com/vitest","scripts":{"dev":"rollup -c --watch","build":"premove dist && rollup -c"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","approver":{"name":"ariperkkio","email":"ari.perkkio@gmail.com"},"trustedPublisher":{"id":"github","oidcConfigId":"oidc:ae21fa98-4ba9-4146-be24-9feb4cbf959d"}},"repository":{"url":"git+https://github.com/vitest-dev/vitest.git","type":"git","directory":"packages/snapshot"},"description":"Vitest snapshot manager","directories":{},"sideEffects":false,"_nodeVersion":"24.21.0","dependencies":{"pathe":"^2.0.3","magic-string":"^1.2.3","@vitest/utils":"5.0.2","@vitest/pretty-format":"5.0.2"},"_hasShrinkwrap":false,"devDependencies":{"natural-compare":"^1.4.0","@types/natural-compare":"^1.4.3"},"_npmOperationalInternal":{"tmp":"tmp/snapshot_5.0.2_1790326791413_0.9516346589569069","host":"s3://npm-registry-packages-npm-production"},"readme":"# @vitest/snapshot\n\n[![NPM version](https://img.shields.io/npm/v/@vitest/snapshot?color=a1b858&label=)](https://npmx.dev/package/@vitest/snapshot)\n\nLightweight implementation of Jest's snapshots.\n\n## Usage\n\n```js\nimport { SnapshotClient } from '@vitest/snapshot'\nimport { NodeSnapshotEnvironment } from '@vitest/snapshot/environment'\nimport { SnapshotManager } from '@vitest/snapshot/manager'\n\nconst client = new SnapshotClient({\n  // you need to provide your own equality check implementation if you use it\n  // this function is called when `.toMatchSnapshot({ property: 1 })` is called\n  isEqual: (received, expected) =>\n    equals(received, expected, [iterableEquality, subsetEquality]),\n})\n\n// class that implements snapshot saving and reading\n// by default uses fs module, but you can provide your own implementation depending on the environment\nconst environment = new NodeSnapshotEnvironment()\n\n// you need to implement this yourselves,\n// this depends on your runner\nfunction getCurrentFilepath() {\n  return '/file.spec.js'\n}\nfunction getCurrentTestName() {\n  return 'test1'\n}\n\n// example for inline snapshots, nothing is required to support regular snapshots,\n// just call `assert` with `isInline: false`\nfunction wrapper(received) {\n  function __INLINE_SNAPSHOT__(inlineSnapshot, message) {\n    client.assert({\n      received,\n      message,\n      isInline: true,\n      inlineSnapshot,\n      filepath: getCurrentFilepath(),\n      name: getCurrentTestName(),\n    })\n  }\n  return {\n    // the name is hard-coded, it should be inside another function, so Vitest can find the actual test file where it was called (parses call stack trace + 2)\n    // you can override this behaviour in SnapshotState's `_inferInlineSnapshotStack` method by providing your own SnapshotState to SnapshotClient constructor\n    toMatchInlineSnapshot: (...args) => __INLINE_SNAPSHOT__(...args),\n  }\n}\n\nconst options = {\n  updateSnapshot: 'new',\n  snapshotEnvironment: environment,\n}\n\nawait client.startCurrentRun(\n  getCurrentFilepath(),\n  getCurrentTestName(),\n  options\n)\n\n// this will save snapshot to a file which is returned by \"snapshotEnvironment.resolvePath\"\nclient.assert({\n  received: 'some text',\n  isInline: false,\n})\n\n// uses \"pretty-format\", so it requires quotes\n// also naming is hard-coded when parsing test files\nwrapper('text 1').toMatchInlineSnapshot()\nwrapper('text 2').toMatchInlineSnapshot('\"text 2\"')\n\nconst result = await client.finishCurrentRun() // this saves files and returns SnapshotResult\n\n// you can use manager to manage several clients\nconst manager = new SnapshotManager(options)\nmanager.add(result)\n\n// do something\n// and then read the summary\n\nconsole.log(manager.summary)\n```\n\n[GitHub](https://github.com/vitest-dev/vitest/tree/main/packages/snapshot) | [Documentation](https://vitest.dev/guide/snapshot)\n","publish_time":1790326791493,"_cnpm_publish_time":1790326791493,"dist-tags":{"beta":"5.1.0-beta.1","latest":"5.1.0","rc":"5.0.0-rc.4","V3":"3.2.7","V4":"4.1.12"}}