{"_id":"@brillout/vitest-snapshot","name":"@brillout/vitest-snapshot","dist-tags":{"latest":"0.35.0-prerelease"},"versions":{"0.35.0-prerelease":{"name":"@brillout/vitest-snapshot","publishConfig":{"access":"public"},"type":"module","version":"0.35.0-prerelease","description":"Vitest snapshot manager","license":"MIT","funding":"https://opencollective.com/vitest","homepage":"https://github.com/vitest-dev/vitest/tree/main/packages/snapshot#readme","repository":{"type":"git","url":"git+https://github.com/vitest-dev/vitest.git","directory":"packages/snapshot"},"bugs":{"url":"https://github.com/vitest-dev/vitest/issues"},"sideEffects":false,"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./environment":{"types":"./dist/environment.d.ts","import":"./dist/environment.js"},"./manager":{"types":"./dist/manager.d.ts","import":"./dist/manager.js"},"./*":"./*"},"main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","dependencies":{"magic-string":"^0.30.1","pathe":"^1.1.1","pretty-format":"^29.5.0"},"devDependencies":{"@types/natural-compare":"^1.4.1","natural-compare":"^1.4.0","@vitest/utils":"0.34.1"},"scripts":{"build":"rimraf dist && rollup -c","dev":"rollup -c --watch"},"_id":"@brillout/vitest-snapshot@0.35.0-prerelease","_integrity":"sha512-QTLTM1h0RV+mh203+i6vW8U5Nxp8wUhissc9bZs8pONkoXq2vx9APkxIawmT3GPKpsQJsnTZvJyp2RyZCbS0cw==","_resolved":"/tmp/2d228eee6b875ff581efea7412527bdc/brillout-vitest-snapshot-0.35.0-prerelease.tgz","_from":"file:brillout-vitest-snapshot-0.35.0-prerelease.tgz","_nodeVersion":"18.15.0","_npmVersion":"9.5.0","dist":{"integrity":"sha512-QTLTM1h0RV+mh203+i6vW8U5Nxp8wUhissc9bZs8pONkoXq2vx9APkxIawmT3GPKpsQJsnTZvJyp2RyZCbS0cw==","shasum":"559cea3661039dd24c9cbd3b1e754ac42d8758b2","tarball":"https://registry.npmjs.org/@brillout/vitest-snapshot/-/vitest-snapshot-0.35.0-prerelease.tgz","fileCount":14,"unpackedSize":106324,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBPofjnT6P/hbEFui8tdueEEJtuJYVuJoH0jZI1gG7/xAiEA8jS1Ax1FkrBuDApUHmVeKLF3XDEOU5Pa/tEpPdvpEZ0="}]},"_npmUser":{"name":"brillout","email":"npm@brillout.com"},"directories":{},"maintainers":[{"name":"brillout","email":"npm@brillout.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vitest-snapshot_0.35.0-prerelease_1693751581394_0.02065615767689355"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-03T14:33:01.270Z","0.35.0-prerelease":"2023-09-03T14:33:01.778Z","modified":"2023-09-03T14:33:02.281Z"},"maintainers":[{"name":"brillout","email":"npm@brillout.com"}],"description":"Vitest snapshot manager","homepage":"https://github.com/vitest-dev/vitest/tree/main/packages/snapshot#readme","repository":{"type":"git","url":"git+https://github.com/vitest-dev/vitest.git","directory":"packages/snapshot"},"bugs":{"url":"https://github.com/vitest-dev/vitest/issues"},"license":"MIT","readme":"# @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\nexport class CustomSnapshotClient extends SnapshotClient {\n  // by default, @vitest/snapshot checks equality with `!==`\n  // you need to provide your own equality check implementation\n  // this function is called when `.toMatchSnapshot({ property: 1 })` is called\n  equalityCheck(received, expected) {\n    return equals(received, expected, [iterableEquality, subsetEquality])\n  }\n}\n\nconst client = new CustomSnapshotClient()\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\nfunction getCurrentFilepath() {\n  return '/file.spec.ts'\n}\nfunction getCurrentTestName() {\n  return 'test1'\n}\n\nfunction wrapper(received) {\n  function __INLINE_SNAPSHOT__(inlineSnapshot, message) {\n    client.assert({\n      received,\n      message,\n      isInline: true,\n      inlineSnapshot,\n      // you need to implement this yourselves,\n      // this depends on your runner\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.setTest(getCurrentFilepath(), getCurrentTestName(), options)\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.resetCurrent() // 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```","readmeFilename":"README.md"}