{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/node/pulls/comments/64676617","id":64676617,"diff_hunk":"@@ -0,0 +1,166 @@\n+# How to write a Node.js test\n+\n+## What is a test?\n+\n+A test must be a node script that exercises a specific functionality provided by node and\n+checks that it behaves as expected. It should return 0 on success, otherwise it will\n+fail. A test will fail if:\n+\n+- It exits by calling `process.exit(code)` where `code != 0`\n+- It exits due to an uncaught exception.\n+- It never exits. In this case, the test runner will terminate the test because it sets a maximum time limit.\n+\n+They can be added for multiple reasons:\n+\n+- When adding new functionality.\n+- When fixing regression and bugs.\n+- Expanding test coverage.\n+\n+\n+## Test structure\n+\n+Let's analyze this very basic test from the Node.js test suite:\n+\n+```javascript\n+1  'use strict'; \n+2  const common = require('../common');\n+3  const http = require('http');\n+4  const assert = require('assert');\n+5\n+6  const server = http.createServer(common.mustCall((req, res) => {\n+7    res.end('ok');\n+8  }));\n+9  server.listen(common.PORT, () => {\n+10   http.get({\n+11     port: common.PORT,\n+12     headers: {'Test': 'Düsseldorf'}\n+13   }, common.mustCall((res) => {\n+14     assert.equal(res.statusCode, 200);\n+15     server.close();\n+16   }));\n+17 });\n+```\n+\n+**Lines 1-2**\n+\n+```\n+'use strict';\n+const common = require('../common');\n+```\n+\n+These two lines are mandatory and should be included on every test.\n+The `common` module is a helper module that provides useful tools for the tests.\n+If for some reason, no functionality from `common` is used, it should still be included like this:\n+\n+```\n+require('../common');\n+````\n+\n+Why? It checks for leaks of globals.\n+\n+**Lines 3-4**\n+\n+```\n+const http = require('http');\n+const assert = require('assert');\n+```\n+\n+These modules are required for the test to run. Except for special cases, these modules should only include core modules.\n+The `assert` module is used by most of the tests to check that the assumptions for the test are met.\n+\n+**Lines 6-17**\n+\n+This is the body of the test. This test is quite simple, it just tests that an HTTP server accepts `obs-text` characters in the headers of an incoming request. Interesting things to notice:","path":"doc/guides/writing_tests.md","position":73,"original_position":73,"commit_id":"cf3a6eb91a0d1f552b99231a78e1dbd6725dd9fe","original_commit_id":"cf3a6eb91a0d1f552b99231a78e1dbd6725dd9fe","user":{"login":"addaleax","id":899444,"avatar_url":"https://avatars.githubusercontent.com/u/899444?v=3","gravatar_id":"","url":"https://api.github.com/users/addaleax","html_url":"https://github.com/addaleax","followers_url":"https://api.github.com/users/addaleax/followers","following_url":"https://api.github.com/users/addaleax/following{/other_user}","gists_url":"https://api.github.com/users/addaleax/gists{/gist_id}","starred_url":"https://api.github.com/users/addaleax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/addaleax/subscriptions","organizations_url":"https://api.github.com/users/addaleax/orgs","repos_url":"https://api.github.com/users/addaleax/repos","events_url":"https://api.github.com/users/addaleax/events{/privacy}","received_events_url":"https://api.github.com/users/addaleax/received_events","type":"User","site_admin":false},"body":"long line (that occurs multiple times here) and `obs-text` should be explained (or replaced by `non-ASCII` characters, as I’m assuming this is a guide for newcomers?)","created_at":"2016-05-26T00:41:56Z","updated_at":"2016-05-26T00:41:56Z","html_url":"https://github.com/nodejs/node/pull/6984#discussion_r64676617","pull_request_url":"https://api.github.com/repos/nodejs/node/pulls/6984","_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments/64676617"},"html":{"href":"https://github.com/nodejs/node/pull/6984#discussion_r64676617"},"pull_request":{"href":"https://api.github.com/repos/nodejs/node/pulls/6984"}}},"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/6984","id":71484241,"html_url":"https://github.com/nodejs/node/pull/6984","diff_url":"https://github.com/nodejs/node/pull/6984.diff","patch_url":"https://github.com/nodejs/node/pull/6984.patch","issue_url":"https://api.github.com/repos/nodejs/node/issues/6984","number":6984,"state":"open","locked":false,"title":"doc: add `How to write a Node.js` guide","user":{"login":"santigimeno","id":1084056,"avatar_url":"https://avatars.githubusercontent.com/u/1084056?v=3","gravatar_id":"","url":"https://api.github.com/users/santigimeno","html_url":"https://github.com/santigimeno","followers_url":"https://api.github.com/users/santigimeno/followers","following_url":"https://api.github.com/users/santigimeno/following{/other_user}","gists_url":"https://api.github.com/users/santigimeno/gists{/gist_id}","starred_url":"https://api.github.com/users/santigimeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santigimeno/subscriptions","organizations_url":"https://api.github.com/users/santigimeno/orgs","repos_url":"https://api.github.com/users/santigimeno/repos","events_url":"https://api.github.com/users/santigimeno/events{/privacy}","received_events_url":"https://api.github.com/users/santigimeno/received_events","type":"User","site_admin":false},"body":"<!--\r\nThank you for your pull request. Please review below requirements and walk\r\nthrough the checklist. You can 'tick' a box by using the letter \"x\": [x].\r\n\r\nRun the test suite with: `make -j4 test` on UNIX or `vcbuild test nosign` on\r\nWindows.\r\n\r\nIf this aims to fix a regression or you’re adding a feature, make sure you also\r\nwrite a test. If possible, include a benchmark that quantifies your changes.\r\n\r\nFinally, read through our contributors guide and make adjustments as necessary:\r\nhttps://github.com/nodejs/node/blob/master/CONTRIBUTING.md\r\n-->\r\n\r\n##### Checklist\r\n<!-- remove lines that do not apply to you -->\r\n- [x] documentation is changed or added\r\n- [x] the commit message follows commit guidelines\r\n\r\n\r\n##### Affected core subsystem(s)\r\n<!-- provide affected core subsystem(s) (like doc, cluster, crypto, etc) -->\r\ndoc, test\r\n\r\n##### Description of change\r\n<!-- provide a description of the change below this comment -->\r\n\r\nRefs: https://github.com/nodejs/testing/pull/30\r\n\r\n/cc @nodejs/testing @nodejs/documentation \r\n","created_at":"2016-05-26T00:31:16Z","updated_at":"2016-05-26T00:41:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"808d98eef8d74d0d212f0013d7906904cd0c509c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/node/pulls/6984/commits","review_comments_url":"https://api.github.com/repos/nodejs/node/pulls/6984/comments","review_comment_url":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/node/issues/6984/comments","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/cf3a6eb91a0d1f552b99231a78e1dbd6725dd9fe","head":{"label":"santigimeno:test_guid","ref":"test_guid","sha":"cf3a6eb91a0d1f552b99231a78e1dbd6725dd9fe","user":{"login":"santigimeno","id":1084056,"avatar_url":"https://avatars.githubusercontent.com/u/1084056?v=3","gravatar_id":"","url":"https://api.github.com/users/santigimeno","html_url":"https://github.com/santigimeno","followers_url":"https://api.github.com/users/santigimeno/followers","following_url":"https://api.github.com/users/santigimeno/following{/other_user}","gists_url":"https://api.github.com/users/santigimeno/gists{/gist_id}","starred_url":"https://api.github.com/users/santigimeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santigimeno/subscriptions","organizations_url":"https://api.github.com/users/santigimeno/orgs","repos_url":"https://api.github.com/users/santigimeno/repos","events_url":"https://api.github.com/users/santigimeno/events{/privacy}","received_events_url":"https://api.github.com/users/santigimeno/received_events","type":"User","site_admin":false},"repo":{"id":46618546,"name":"node","full_name":"santigimeno/node","owner":{"login":"santigimeno","id":1084056,"avatar_url":"https://avatars.githubusercontent.com/u/1084056?v=3","gravatar_id":"","url":"https://api.github.com/users/santigimeno","html_url":"https://github.com/santigimeno","followers_url":"https://api.github.com/users/santigimeno/followers","following_url":"https://api.github.com/users/santigimeno/following{/other_user}","gists_url":"https://api.github.com/users/santigimeno/gists{/gist_id}","starred_url":"https://api.github.com/users/santigimeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santigimeno/subscriptions","organizations_url":"https://api.github.com/users/santigimeno/orgs","repos_url":"https://api.github.com/users/santigimeno/repos","events_url":"https://api.github.com/users/santigimeno/events{/privacy}","received_events_url":"https://api.github.com/users/santigimeno/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/santigimeno/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":true,"url":"https://api.github.com/repos/santigimeno/node","forks_url":"https://api.github.com/repos/santigimeno/node/forks","keys_url":"https://api.github.com/repos/santigimeno/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/santigimeno/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/santigimeno/node/teams","hooks_url":"https://api.github.com/repos/santigimeno/node/hooks","issue_events_url":"https://api.github.com/repos/santigimeno/node/issues/events{/number}","events_url":"https://api.github.com/repos/santigimeno/node/events","assignees_url":"https://api.github.com/repos/santigimeno/node/assignees{/user}","branches_url":"https://api.github.com/repos/santigimeno/node/branches{/branch}","tags_url":"https://api.github.com/repos/santigimeno/node/tags","blobs_url":"https://api.github.com/repos/santigimeno/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/santigimeno/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/santigimeno/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/santigimeno/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/santigimeno/node/statuses/{sha}","languages_url":"https://api.github.com/repos/santigimeno/node/languages","stargazers_url":"https://api.github.com/repos/santigimeno/node/stargazers","contributors_url":"https://api.github.com/repos/santigimeno/node/contributors","subscribers_url":"https://api.github.com/repos/santigimeno/node/subscribers","subscription_url":"https://api.github.com/repos/santigimeno/node/subscription","commits_url":"https://api.github.com/repos/santigimeno/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/santigimeno/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/santigimeno/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/santigimeno/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/santigimeno/node/contents/{+path}","compare_url":"https://api.github.com/repos/santigimeno/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/santigimeno/node/merges","archive_url":"https://api.github.com/repos/santigimeno/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/santigimeno/node/downloads","issues_url":"https://api.github.com/repos/santigimeno/node/issues{/number}","pulls_url":"https://api.github.com/repos/santigimeno/node/pulls{/number}","milestones_url":"https://api.github.com/repos/santigimeno/node/milestones{/number}","notifications_url":"https://api.github.com/repos/santigimeno/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/santigimeno/node/labels{/name}","releases_url":"https://api.github.com/repos/santigimeno/node/releases{/id}","deployments_url":"https://api.github.com/repos/santigimeno/node/deployments","created_at":"2015-11-21T14:27:00Z","updated_at":"2016-03-09T00:35:06Z","pushed_at":"2016-05-26T00:29:26Z","git_url":"git://github.com/santigimeno/node.git","ssh_url":"git@github.com:santigimeno/node.git","clone_url":"https://github.com/santigimeno/node.git","svn_url":"https://github.com/santigimeno/node","homepage":"https://nodejs.org","size":206429,"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":"nodejs:master","ref":"master","sha":"048b3de22d843a8dd3d00b00b702205ca90dbf58","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":27193779,"name":"node","full_name":"nodejs/node","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":false,"url":"https://api.github.com/repos/nodejs/node","forks_url":"https://api.github.com/repos/nodejs/node/forks","keys_url":"https://api.github.com/repos/nodejs/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/node/teams","hooks_url":"https://api.github.com/repos/nodejs/node/hooks","issue_events_url":"https://api.github.com/repos/nodejs/node/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/node/events","assignees_url":"https://api.github.com/repos/nodejs/node/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/node/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/node/tags","blobs_url":"https://api.github.com/repos/nodejs/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/node/languages","stargazers_url":"https://api.github.com/repos/nodejs/node/stargazers","contributors_url":"https://api.github.com/repos/nodejs/node/contributors","subscribers_url":"https://api.github.com/repos/nodejs/node/subscribers","subscription_url":"https://api.github.com/repos/nodejs/node/subscription","commits_url":"https://api.github.com/repos/nodejs/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/node/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/node/merges","archive_url":"https://api.github.com/repos/nodejs/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/node/downloads","issues_url":"https://api.github.com/repos/nodejs/node/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/node/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/node/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/node/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/node/releases{/id}","deployments_url":"https://api.github.com/repos/nodejs/node/deployments","created_at":"2014-11-26T19:57:11Z","updated_at":"2016-05-25T23:52:17Z","pushed_at":"2016-05-26T00:31:17Z","git_url":"git://github.com/nodejs/node.git","ssh_url":"git@github.com:nodejs/node.git","clone_url":"https://github.com/nodejs/node.git","svn_url":"https://github.com/nodejs/node","homepage":"https://nodejs.org","size":276384,"stargazers_count":23477,"watchers_count":23477,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3357,"mirror_url":null,"open_issues_count":675,"forks":3357,"open_issues":675,"watchers":23477,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/6984"},"html":{"href":"https://github.com/nodejs/node/pull/6984"},"issue":{"href":"https://api.github.com/repos/nodejs/node/issues/6984"},"comments":{"href":"https://api.github.com/repos/nodejs/node/issues/6984/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/node/pulls/6984/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/node/pulls/6984/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/node/statuses/cf3a6eb91a0d1f552b99231a78e1dbd6725dd9fe"}}}}
{"actor":{"display_login":"addaleax"}}