| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bc2d1c9 commit ed8df17
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,23 +23,27 @@ Tests can be added for multiple reasons: | |||
| 23 | 23 | Let's analyze this very basic test from the Node.js test suite: | |
| 24 | 24 | ||
| 25 | 25 | ```javascript | |
| 26 | - 1 'use strict'; | ||
| 27 | - 2 const common = require('../common'); | ||
| 28 | - 3 const http = require('http'); | ||
| 29 | - 4 const assert = require('assert'); | ||
| 30 | - 5 | ||
| 31 | - 6 const server = http.createServer(common.mustCall((req, res) => { | ||
| 32 | - 7 res.end('ok'); | ||
| 33 | - 8 })); | ||
| 34 | - 9 server.listen(0, () => { | ||
| 35 | - 10 http.get({ | ||
| 36 | - 11 port: server.address().port, | ||
| 37 | - 12 headers: {'Test': 'Düsseldorf'} | ||
| 38 | - 13 }, common.mustCall((res) => { | ||
| 39 | - 14 assert.equal(res.statusCode, 200); | ||
| 40 | - 15 server.close(); | ||
| 41 | - 16 })); | ||
| 42 | - 17 }); | ||
| 26 | + 1 'use strict'; | ||
| 27 | + 2 const common = require('../common'); | ||
| 28 | + 3 | ||
| 29 | + 4 // This test ensures that the http-parser can handle UTF-8 characters | ||
| 30 | + 5 // in the http header. | ||
| 31 | + 6 | ||
| 32 | + 7 const http = require('http'); | ||
| 33 | + 8 const assert = require('assert'); | ||
| 34 | + 9 | ||
| 35 | + 10 const server = http.createServer(common.mustCall((req, res) => { | ||
| 36 | + 11 res.end('ok'); | ||
| 37 | + 12 })); | ||
| 38 | + 13 server.listen(0, () => { | ||
| 39 | + 14 http.get({ | ||
| 40 | + 15 port: server.address().port, | ||
| 41 | + 16 headers: {'Test': 'Düsseldorf'} | ||
| 42 | + 17 }, common.mustCall((res) => { | ||
| 43 | + 18 assert.strictEqual(res.statusCode, 200); | ||
| 44 | + 19 server.close(); | ||
| 45 | + 20 })); | ||
| 46 | + 21 }); | ||
| 43 | 47 | ``` | |
| 44 | 48 | ||
| 45 | 49 | **Lines 1-2** | |
@@ -60,7 +64,18 @@ require('../common'); | |||
| 60 | 64 | ||
| 61 | 65 | Why? It checks for leaks of globals. | |
| 62 | 66 | ||
| 63 | - **Lines 3-4** | ||
| 67 | + **Lines 4-5** | ||
| 68 | + | ||
| 69 | + ```javascript | ||
| 70 | + // This test ensures that the http-parser can handle UTF-8 characters | ||
| 71 | + // in the http header. | ||
| 72 | + ``` | ||
| 73 | + | ||
| 74 | + A test should start with a comment containing a brief description of what it is | ||
| 75 | + designed to test. | ||
| 76 | + | ||
| 77 | + | ||
| 78 | + **Lines 7-8** | ||
| 64 | 79 | ||
| 65 | 80 | ```javascript | |
| 66 | 81 | const http = require('http'); | |
@@ -72,7 +87,7 @@ modules should only include core modules. | |||
| 72 | 87 | The `assert` module is used by most of the tests to check that the assumptions | |
| 73 | 88 | for the test are met. | |
| 74 | 89 | ||
| 75 | - **Lines 6-17** | ||
| 90 | + **Lines 10-21** | ||
| 76 | 91 | ||
| 77 | 92 | This is the body of the test. This test is quite simple, it just tests that an | |
| 78 | 93 | HTTP server accepts `non-ASCII` characters in the headers of an incoming | |
| Back | FazBrowse Home | New Git URL |
0 commit comments