@@ -25,39 +25,44 @@ Let's analyze this basic test from the Node.js test suite:
25
25
``` javascript
26
26
' use strict' ; // 1
27
27
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
47
49
```
48
50
49
- ### ** Lines 1-2 **
51
+ ### ** Lines 1-3 **
50
52
51
53
``` javascript
52
54
' use strict' ;
53
55
const common = require (' ../common' );
56
+ const fixtures = require (' ../common/fixtures' );
54
57
```
55
58
56
59
The first line enables strict mode. All tests should be in strict mode unless
57
60
the nature of the test requires that the test run without it.
58
61
59
62
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.
61
66
62
67
Even if a test uses no functions or other properties exported by ` common ` ,
63
68
the test should still include the ` common ` module before any other modules. This
@@ -70,7 +75,7 @@ assigning it to an identifier:
70
75
require (' ../common' );
71
76
```
72
77
73
- ### ** Lines 4-5 **
78
+ ### ** Lines 5-6 **
74
79
75
80
``` javascript
76
81
// This test ensures that the http-parser can handle UTF-8 characters
@@ -80,7 +85,7 @@ require('../common');
80
85
A test should start with a comment containing a brief description of what it is
81
86
designed to test.
82
87
83
- ### ** Lines 7-8 **
88
+ ### ** Lines 8-9 **
84
89
85
90
``` javascript
86
91
const assert = require (' assert' );
@@ -95,7 +100,7 @@ The require statements are sorted in
95
100
[ ASCII] [ ] order (digits, upper
96
101
case, ` _ ` , lower case).
97
102
98
- ### ** Lines 10-21 **
103
+ ### ** Lines 11-22 **
99
104
100
105
This is the body of the test. This test is simple, it just tests that an
101
106
HTTP server accepts ` non-ASCII ` characters in the headers of an incoming
0 commit comments