{"id":13413864,"url":"https://github.com/bradleyjkemp/cupaloy","last_synced_at":"2025-05-15T20:01:19.704Z","repository":{"id":23772787,"uuid":"99607677","full_name":"bradleyjkemp/cupaloy","owner":"bradleyjkemp","description":"Simple Go snapshot testing","archived":false,"fork":false,"pushed_at":"2023-05-19T08:57:25.000Z","size":347,"stargazers_count":316,"open_issues_count":13,"forks_count":26,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-08T01:37:48.120Z","etag":null,"topics":["go","golang","golden-master","snapshot","snapshot-testing","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bradleyjkemp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-07T18:30:05.000Z","updated_at":"2025-04-01T08:24:38.000Z","dependencies_parsed_at":"2024-06-18T12:32:42.396Z","dependency_job_id":"3d0b4637-85f7-4f7f-b244-9fd6d6ae9e8c","html_url":"https://github.com/bradleyjkemp/cupaloy","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradleyjkemp%2Fcupaloy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradleyjkemp%2Fcupaloy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradleyjkemp%2Fcupaloy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradleyjkemp%2Fcupaloy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bradleyjkemp","download_url":"https://codeload.github.com/bradleyjkemp/cupaloy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414457,"owners_count":22067263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","golden-master","snapshot","snapshot-testing","testing"],"created_at":"2024-07-30T20:01:51.480Z","updated_at":"2025-05-15T20:01:19.578Z","avatar_url":"https://github.com/bradleyjkemp.png","language":"Go","funding_links":[],"categories":["Go","Testing","Template Engines","Testing Frameworks","测试","\u003cspan id=\"测试-testing\"\u003e测试 Testing\u003c/span\u003e","测试相关`测试库和测试数据集生成库`","测试相关"],"sub_categories":["HTTP Clients","Testing Frameworks","Advanced Console UIs","HTTP客户端","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","查询语"],"readme":"\u003ch1 align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/bradleyjkemp/cupaloy/blob/master/mascot.png\" alt=\"Mascot\" width=\"200\"\u003e\n    \u003cbr\u003e\n    \u003cimg src=\"https://github.com/bradleyjkemp/cupaloy/workflows/Go/badge.svg\" alt=\"Build Status\" /\u003e\n    \u003ca href=\"https://coveralls.io/github/bradleyjkemp/cupaloy?branch=master\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/bradleyjkemp/cupaloy/badge.svg\" alt=\"Coverage Status\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://goreportcard.com/report/github.com/bradleyjkemp/cupaloy\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/bradleyjkemp/cupaloy\" alt=\"Go Report Card\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://godoc.org/github.com/bradleyjkemp/cupaloy\"\u003e\u003cimg src=\"https://godoc.org/github.com/bradleyjkemp/cupaloy?status.svg\" alt=\"GoDoc\" /\u003e\u003c/a\u003e\n\u003c/h1\u003e\n\nIncredibly simple Go snapshot testing: `cupaloy` takes a snapshot of your test output and compares it to a snapshot committed alongside your tests. If the values don't match then the test will be failed.\n\nThere's no need to manually manage snapshot files: just use the `cupaloy.SnapshotT(t, value)` function in your tests and `cupaloy` will automatically find the relevant snapshot file (based on the test name) and compare it with the given value.\n\n## Usage\n### Write a test\nFirstly, write a test case generating some output and pass this output to `cupaloy.SnapshotT`:\n```golang\nfunc TestParsing(t *testing.T) {\n    ast := ParseFile(\"test_input\")\n\n    // check that the result is the same as the last time the snapshot was updated\n    // if the result has changed (e.g. because the behaviour of the parser has changed)\n    // then the test will be failed with an error containing a diff of the changes\n    cupaloy.SnapshotT(t, ast)\n}\n```\nThe first time this test is run, a snapshot will be automatically created (using the [github.com/davecgh/go-spew](https://github.com/davecgh/go-spew) package).\n\n### Update a snapshot\nWhen the behaviour of your software changes causing the snapshot to change, this test will begin to fail with an error showing the difference between the old and new snapshots. Once you are happy that the new snapshot is correct (and hasn't just changed unexpectedly), you can save the new snapshot by setting the ```UPDATE_SNAPSHOTS``` environment and re-running your tests:\n```bash\nUPDATE_SNAPSHOTS=true go test ./...\n```\nThis will fail all tests where the snapshot was updated (to stop you accidentally updating snapshots in CI) but your snapshot files will now have been updated to reflect the current output of your code.\n\n### Supported formats\nSnapshots of test output are generated using the [github.com/davecgh/go-spew](https://github.com/davecgh/go-spew) package which uses reflection to deep pretty-print your test result and so will support almost all the basic types (from simple strings, slices, and maps to deeply nested structs) without issue. The only types whose contents cannot be fully pretty-printed are functions and channels.\n\nThe most important property of your test output is that it is deterministic: if your output contains timestamps or other fields which will change on every run, then `cupaloy` will detect this as a change and so fail the test.\n\n\n### Further Examples\n#### Table driven tests\n```golang\nvar testCases = map[string][]string{\n    \"TestCaseOne\": []string{......},\n    \"AnotherTestCase\": []string{......},\n    ....\n}\n\nfunc TestCases(t *testing.T) {\n    for testName, args := range testCases {\n        t.Run(testName, func(t *testing.T) {\n            result := functionUnderTest(args...)\n            cupaloy.SnapshotT(t, result)\n        })\n    }\n}\n```\n#### Changing output directory\n```golang\nfunc TestSubdirectory(t *testing.T) {\n    result := someFunction()\n    snapshotter := cupaloy.New(cupaloy.SnapshotSubdirectory(\"testdata\"))\n    err := snapshotter.Snapshot(result)\n    if err != nil {\n        t.Fatalf(\"error: %s\", err)\n    }\n}\n```\nFor further usage examples see basic_test.go and advanced_test.go in the examples/ directory which are both kept up to date and run on CI.\n\n## Debugging\n### Windows\nIt is important to note that git on Windows might be configured in a way that `\\n` is replaced by `\\r\\n` during checkout (it is the case on GitHub actions). In such a case, the snapshot appears to be the same, but the test fails. Please ensure that git is configured correctly everywhere. There are multiple ways to do it, please check https://github.com/actions/checkout/issues/135 and https://github.com/bradleyjkemp/cupaloy/pull/73 for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradleyjkemp%2Fcupaloy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbradleyjkemp%2Fcupaloy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradleyjkemp%2Fcupaloy/lists"}