Skip to content

Commit b6929e2

Browse files
gibfahnMylesBorins
authored andcommittedDec 12, 2017
test,doc: document where common modules go
Keep the `require('../common')` separate from other common modules, as it's the only line that must be there. PR-URL: #16089 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 14ebda5 commit b6929e2

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed
 

‎doc/guides/writing-tests.md

+29-24
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,44 @@ Let's analyze this basic test from the Node.js test suite:
2525
```javascript
2626
'use strict'; // 1
2727
const common = require('../common'); // 2
28-
29-
// This test ensures that the http-parser can handle UTF-8 characters // 4
30-
// in the http header. // 5
31-
32-
const assert = require('assert'); // 7
33-
const http = require('http'); // 8
34-
35-
const server = http.createServer(common.mustCall((req, res) => { // 10
36-
res.end('ok'); // 11
37-
})); // 12
38-
server.listen(0, () => { // 13
39-
http.get({ // 14
40-
port: server.address().port, // 15
41-
headers: { 'Test': 'Düsseldorf' } // 16
42-
}, common.mustCall((res) => { // 17
43-
assert.strictEqual(res.statusCode, 200); // 18
44-
server.close(); // 19
45-
})); // 20
46-
}); // 21
28+
const fixtures = require('../common/fixtures'); // 3
29+
30+
// This test ensures that the http-parser can handle UTF-8 characters // 5
31+
// in the http header. // 6
32+
33+
const assert = require('assert'); // 8
34+
const http = require('http'); // 9
35+
36+
const server = http.createServer(common.mustCall((req, res) => { // 11
37+
res.end('ok'); // 12
38+
})); // 13
39+
server.listen(0, () => { // 14
40+
http.get({ // 15
41+
port: server.address().port, // 16
42+
headers: { 'Test': 'Düsseldorf' } // 17
43+
}, common.mustCall((res) => { // 18
44+
assert.strictEqual(res.statusCode, 200); // 19
45+
server.close(); // 20
46+
})); // 21
47+
}); // 22
48+
// ... // 23
4749
```
4850

49-
### **Lines 1-2**
51+
### **Lines 1-3**
5052

5153
```javascript
5254
'use strict';
5355
const common = require('../common');
56+
const fixtures = require('../common/fixtures');
5457
```
5558

5659
The first line enables strict mode. All tests should be in strict mode unless
5760
the nature of the test requires that the test run without it.
5861

5962
The second line loads the `common` module. The [`common` module][] is a helper
60-
module that provides useful tools for the tests.
63+
module that provides useful tools for the tests. Some common functionality has
64+
been extracted into submodules, which are required separately like the fixtures
65+
module here.
6166

6267
Even if a test uses no functions or other properties exported by `common`,
6368
the test should still include the `common` module before any other modules. This
@@ -70,7 +75,7 @@ assigning it to an identifier:
7075
require('../common');
7176
```
7277

73-
### **Lines 4-5**
78+
### **Lines 5-6**
7479

7580
```javascript
7681
// This test ensures that the http-parser can handle UTF-8 characters
@@ -80,7 +85,7 @@ require('../common');
8085
A test should start with a comment containing a brief description of what it is
8186
designed to test.
8287

83-
### **Lines 7-8**
88+
### **Lines 8-9**
8489

8590
```javascript
8691
const assert = require('assert');
@@ -95,7 +100,7 @@ The require statements are sorted in
95100
[ASCII][] order (digits, upper
96101
case, `_`, lower case).
97102

98-
### **Lines 10-21**
103+
### **Lines 11-22**
99104

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

0 commit comments

Comments
 (0)