Skip to content

Commit 6fc0f1b

Browse files
gibfahnMyles Borins
authored and
Myles Borins
committed
doc: note that tests should include a description
Update the Writing Tests guide to specify that tests should include a brief description of what they are designed to test. PR-URL: #9415 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>oc
1 parent d36c6f5 commit 6fc0f1b

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

doc/guides/writing_tests.md

+34-19
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,27 @@ Tests can be added for multiple reasons:
2323
Let's analyze this very basic test from the Node.js test suite:
2424

2525
```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 });
4347
```
4448

4549
**Lines 1-2**
@@ -60,7 +64,18 @@ require('../common');
6064

6165
Why? It checks for leaks of globals.
6266

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**
6479

6580
```javascript
6681
const http = require('http');
@@ -72,7 +87,7 @@ modules should only include core modules.
7287
The `assert` module is used by most of the tests to check that the assumptions
7388
for the test are met.
7489

75-
**Lines 6-17**
90+
**Lines 10-21**
7691

7792
This is the body of the test. This test is quite simple, it just tests that an
7893
HTTP server accepts `non-ASCII` characters in the headers of an incoming

0 commit comments

Comments
 (0)