{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/jest/pulls/comments/63967375","id":63967375,"diff_hunk":"@@ -0,0 +1,76 @@\n+/**\n+ * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.\n+ *\n+ * This source code is licensed under the BSD-style license found in the\n+ * LICENSE file in the root directory of this source tree. An additional grant\n+ * of patent rights can be found in the PATENTS file in the same directory.\n+ */\n+'use strict';\n+\n+module.exports = (filePath, options, jasmine, snapshotState) => ({\n+  toMatchSnapshot: (util, customEquality) => {\n+    return {\n+      compare(rendered, expected) {\n+\n+        const specRunningFullName = snapshotState.specRunningFullName;\n+\n+        if (expected !== undefined) {\n+          throw new Error('toMatchSnapshot() does not accepts parameters.');\n+        }\n+        if (typeof rendered !== 'string') {\n+          throw new Error('toMatchSnapshot() only works with Strings.');\n+        }\n+\n+        const snapshot = snapshotState.snapshot;\n+\n+        const specRunningCallCounter = (\n+            snapshotState.specsNextCallCounter[specRunningFullName]\n+        );\n+\n+        let pass = false;\n+        let message;\n+        let res = {};","path":"packages/jest-snapshot/src/getMatchers.js","position":32,"original_position":32,"commit_id":"5e6e2114ce927378fd8f0eec115bf6ad7ece0895","original_commit_id":"5e6e2114ce927378fd8f0eec115bf6ad7ece0895","user":{"login":"cpojer","id":13352,"avatar_url":"https://avatars.githubusercontent.com/u/13352?v=3","gravatar_id":"","url":"https://api.github.com/users/cpojer","html_url":"https://github.com/cpojer","followers_url":"https://api.github.com/users/cpojer/followers","following_url":"https://api.github.com/users/cpojer/following{/other_user}","gists_url":"https://api.github.com/users/cpojer/gists{/gist_id}","starred_url":"https://api.github.com/users/cpojer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpojer/subscriptions","organizations_url":"https://api.github.com/users/cpojer/orgs","repos_url":"https://api.github.com/users/cpojer/repos","events_url":"https://api.github.com/users/cpojer/events{/privacy}","received_events_url":"https://api.github.com/users/cpojer/received_events","type":"User","site_admin":false},"body":"this should be a const further down.","created_at":"2016-05-19T22:54:58Z","updated_at":"2016-05-19T22:54:58Z","html_url":"https://github.com/facebook/jest/pull/1000#discussion_r63967375","pull_request_url":"https://api.github.com/repos/facebook/jest/pulls/1000","_links":{"self":{"href":"https://api.github.com/repos/facebook/jest/pulls/comments/63967375"},"html":{"href":"https://github.com/facebook/jest/pull/1000#discussion_r63967375"},"pull_request":{"href":"https://api.github.com/repos/facebook/jest/pulls/1000"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/jest/pulls/1000","id":69867083,"html_url":"https://github.com/facebook/jest/pull/1000","diff_url":"https://github.com/facebook/jest/pull/1000.diff","patch_url":"https://github.com/facebook/jest/pull/1000.patch","issue_url":"https://api.github.com/repos/facebook/jest/issues/1000","number":1000,"state":"open","locked":false,"title":"[WIP] Snapshot functionality","user":{"login":"kentaromiura","id":87300,"avatar_url":"https://avatars.githubusercontent.com/u/87300?v=3","gravatar_id":"","url":"https://api.github.com/users/kentaromiura","html_url":"https://github.com/kentaromiura","followers_url":"https://api.github.com/users/kentaromiura/followers","following_url":"https://api.github.com/users/kentaromiura/following{/other_user}","gists_url":"https://api.github.com/users/kentaromiura/gists{/gist_id}","starred_url":"https://api.github.com/users/kentaromiura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kentaromiura/subscriptions","organizations_url":"https://api.github.com/users/kentaromiura/orgs","repos_url":"https://api.github.com/users/kentaromiura/repos","events_url":"https://api.github.com/users/kentaromiura/events{/privacy}","received_events_url":"https://api.github.com/users/kentaromiura/received_events","type":"User","site_admin":false},"body":"This commit introduce a new matcher to `jest`:\r\n`toMatchSnapshot`.\r\nthis new matcher can be called as usual:\r\n`expect(something).toMatchSnapshot()`\r\nthe main idea is that the first time the test run it will store whatever is inside expect in a snapshot file,\r\nthe next time `jest` runs it will check against it to see if something has changed.\r\n\r\nIn order to store something on file we need to serialize it, so I currently implemented two different serialization strategies, if we are _expecting_ a `React` element to match a snapshot representation then it will be _currently_ be serialized using the `React.renderToString` method, otherwise it fallbacks to `jest`'s pretty printer.\r\nI choose it because it provides out of the box support for `Maps` and `Sets` other than `Object`s and `Array`s.\r\nAs the title mention this is a work in progress as I plan to iterate on it to improve the serialization strategies and possible the output when it fails the expectation.\r\n\r\nThe matcher uses jasmine `Spec` `getFullName` as the key in the snapshot file, adding an index at the end, this enable us to use multiple `toMatchSnapshot`, not just in the same `Suite`, but also in the same `Spec`, when failing it will highlight which snapshot has failed prepending `#` in front of an index of it (it starts at 0, but we can change it to 1 if it creates confusion).\r\n\r\nWhen a test fails one can either fix the code breaking the expectation or, if the expectation is not up to date anymore, pass `--overwriteSnapshot` to `jest` to update it:\r\n\r\n<img width=\"733\" alt=\"screen shot 2016-05-12 at 4 57 56 pm\" src=\"https://cloud.githubusercontent.com/assets/87300/15221840/016ac28a-1865-11e6-87aa-b563e88e7d0e.png\">\r\n\r\nThis is an example of a failing test for a React component  \r\n<img width=\"849\" alt=\"screen shot 2016-05-12 at 5 25 33 pm\" src=\"https://cloud.githubusercontent.com/assets/87300/15222242/96ce6d8a-1866-11e6-81f4-59d759e5cb8a.png\">\r\n\r\n","created_at":"2016-05-12T16:27:33Z","updated_at":"2016-05-19T22:54:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d8045269ef94d71dd4d3fd439d1b9ee3e7492ec3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/facebook/jest/pulls/1000/commits","review_comments_url":"https://api.github.com/repos/facebook/jest/pulls/1000/comments","review_comment_url":"https://api.github.com/repos/facebook/jest/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/jest/issues/1000/comments","statuses_url":"https://api.github.com/repos/facebook/jest/statuses/5e6e2114ce927378fd8f0eec115bf6ad7ece0895","head":{"label":"kentaromiura:snapshot_wip","ref":"snapshot_wip","sha":"5e6e2114ce927378fd8f0eec115bf6ad7ece0895","user":{"login":"kentaromiura","id":87300,"avatar_url":"https://avatars.githubusercontent.com/u/87300?v=3","gravatar_id":"","url":"https://api.github.com/users/kentaromiura","html_url":"https://github.com/kentaromiura","followers_url":"https://api.github.com/users/kentaromiura/followers","following_url":"https://api.github.com/users/kentaromiura/following{/other_user}","gists_url":"https://api.github.com/users/kentaromiura/gists{/gist_id}","starred_url":"https://api.github.com/users/kentaromiura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kentaromiura/subscriptions","organizations_url":"https://api.github.com/users/kentaromiura/orgs","repos_url":"https://api.github.com/users/kentaromiura/repos","events_url":"https://api.github.com/users/kentaromiura/events{/privacy}","received_events_url":"https://api.github.com/users/kentaromiura/received_events","type":"User","site_admin":false},"repo":{"id":52747373,"name":"jest","full_name":"kentaromiura/jest","owner":{"login":"kentaromiura","id":87300,"avatar_url":"https://avatars.githubusercontent.com/u/87300?v=3","gravatar_id":"","url":"https://api.github.com/users/kentaromiura","html_url":"https://github.com/kentaromiura","followers_url":"https://api.github.com/users/kentaromiura/followers","following_url":"https://api.github.com/users/kentaromiura/following{/other_user}","gists_url":"https://api.github.com/users/kentaromiura/gists{/gist_id}","starred_url":"https://api.github.com/users/kentaromiura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kentaromiura/subscriptions","organizations_url":"https://api.github.com/users/kentaromiura/orgs","repos_url":"https://api.github.com/users/kentaromiura/repos","events_url":"https://api.github.com/users/kentaromiura/events{/privacy}","received_events_url":"https://api.github.com/users/kentaromiura/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kentaromiura/jest","description":"Painless JavaScript Unit Testing built on top of the Jasmine test framework.","fork":true,"url":"https://api.github.com/repos/kentaromiura/jest","forks_url":"https://api.github.com/repos/kentaromiura/jest/forks","keys_url":"https://api.github.com/repos/kentaromiura/jest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kentaromiura/jest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kentaromiura/jest/teams","hooks_url":"https://api.github.com/repos/kentaromiura/jest/hooks","issue_events_url":"https://api.github.com/repos/kentaromiura/jest/issues/events{/number}","events_url":"https://api.github.com/repos/kentaromiura/jest/events","assignees_url":"https://api.github.com/repos/kentaromiura/jest/assignees{/user}","branches_url":"https://api.github.com/repos/kentaromiura/jest/branches{/branch}","tags_url":"https://api.github.com/repos/kentaromiura/jest/tags","blobs_url":"https://api.github.com/repos/kentaromiura/jest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kentaromiura/jest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kentaromiura/jest/git/refs{/sha}","trees_url":"https://api.github.com/repos/kentaromiura/jest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kentaromiura/jest/statuses/{sha}","languages_url":"https://api.github.com/repos/kentaromiura/jest/languages","stargazers_url":"https://api.github.com/repos/kentaromiura/jest/stargazers","contributors_url":"https://api.github.com/repos/kentaromiura/jest/contributors","subscribers_url":"https://api.github.com/repos/kentaromiura/jest/subscribers","subscription_url":"https://api.github.com/repos/kentaromiura/jest/subscription","commits_url":"https://api.github.com/repos/kentaromiura/jest/commits{/sha}","git_commits_url":"https://api.github.com/repos/kentaromiura/jest/git/commits{/sha}","comments_url":"https://api.github.com/repos/kentaromiura/jest/comments{/number}","issue_comment_url":"https://api.github.com/repos/kentaromiura/jest/issues/comments{/number}","contents_url":"https://api.github.com/repos/kentaromiura/jest/contents/{+path}","compare_url":"https://api.github.com/repos/kentaromiura/jest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kentaromiura/jest/merges","archive_url":"https://api.github.com/repos/kentaromiura/jest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kentaromiura/jest/downloads","issues_url":"https://api.github.com/repos/kentaromiura/jest/issues{/number}","pulls_url":"https://api.github.com/repos/kentaromiura/jest/pulls{/number}","milestones_url":"https://api.github.com/repos/kentaromiura/jest/milestones{/number}","notifications_url":"https://api.github.com/repos/kentaromiura/jest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kentaromiura/jest/labels{/name}","releases_url":"https://api.github.com/repos/kentaromiura/jest/releases{/id}","deployments_url":"https://api.github.com/repos/kentaromiura/jest/deployments","created_at":"2016-02-28T22:14:21Z","updated_at":"2016-02-28T22:14:22Z","pushed_at":"2016-05-19T18:56:15Z","git_url":"git://github.com/kentaromiura/jest.git","ssh_url":"git@github.com:kentaromiura/jest.git","clone_url":"https://github.com/kentaromiura/jest.git","svn_url":"https://github.com/kentaromiura/jest","homepage":"http://facebook.github.io/jest/","size":2170,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"6ee9ba2f01ddd228fe0c1ce207b0f9cb923a1f06","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":15062869,"name":"jest","full_name":"facebook/jest","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/jest","description":"Painless JavaScript Unit Testing.","fork":false,"url":"https://api.github.com/repos/facebook/jest","forks_url":"https://api.github.com/repos/facebook/jest/forks","keys_url":"https://api.github.com/repos/facebook/jest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/jest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/jest/teams","hooks_url":"https://api.github.com/repos/facebook/jest/hooks","issue_events_url":"https://api.github.com/repos/facebook/jest/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/jest/events","assignees_url":"https://api.github.com/repos/facebook/jest/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/jest/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/jest/tags","blobs_url":"https://api.github.com/repos/facebook/jest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/jest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/jest/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/jest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/jest/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/jest/languages","stargazers_url":"https://api.github.com/repos/facebook/jest/stargazers","contributors_url":"https://api.github.com/repos/facebook/jest/contributors","subscribers_url":"https://api.github.com/repos/facebook/jest/subscribers","subscription_url":"https://api.github.com/repos/facebook/jest/subscription","commits_url":"https://api.github.com/repos/facebook/jest/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/jest/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/jest/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/jest/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/jest/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/jest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/jest/merges","archive_url":"https://api.github.com/repos/facebook/jest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/jest/downloads","issues_url":"https://api.github.com/repos/facebook/jest/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/jest/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/jest/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/jest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/jest/labels{/name}","releases_url":"https://api.github.com/repos/facebook/jest/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/jest/deployments","created_at":"2013-12-10T00:18:04Z","updated_at":"2016-05-19T21:10:43Z","pushed_at":"2016-05-19T22:00:38Z","git_url":"git://github.com/facebook/jest.git","ssh_url":"git@github.com:facebook/jest.git","clone_url":"https://github.com/facebook/jest.git","svn_url":"https://github.com/facebook/jest","homepage":"http://facebook.github.io/jest/","size":4031,"stargazers_count":4023,"watchers_count":4023,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":471,"mirror_url":null,"open_issues_count":45,"forks":471,"open_issues":45,"watchers":4023,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/jest/pulls/1000"},"html":{"href":"https://github.com/facebook/jest/pull/1000"},"issue":{"href":"https://api.github.com/repos/facebook/jest/issues/1000"},"comments":{"href":"https://api.github.com/repos/facebook/jest/issues/1000/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/jest/pulls/1000/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/jest/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/jest/pulls/1000/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/jest/statuses/5e6e2114ce927378fd8f0eec115bf6ad7ece0895"}}}}
{"actor":{"display_login":"cpojer"}}