Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: note that tests should include a description #9415

Merged
merged 2 commits into from
Nov 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions doc/guides/writing_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,27 @@ Tests can be added for multiple reasons:
Let's analyze this very basic test from the Node.js test suite:

```javascript
1 'use strict';
2 const common = require('../common');
3 const http = require('http');
4 const assert = require('assert');
5
6 const server = http.createServer(common.mustCall((req, res) => {
7 res.end('ok');
8 }));
9 server.listen(0, () => {
10 http.get({
11 port: server.address().port,
12 headers: {'Test': 'Düsseldorf'}
13 }, common.mustCall((res) => {
14 assert.equal(res.statusCode, 200);
15 server.close();
16 }));
17 });
1 'use strict';
2 const common = require('../common');
3
4 // This test ensures that the http-parser can handle UTF-8 characters
5 // in the http header.
6
7 const http = require('http');
8 const assert = require('assert');
9
10 const server = http.createServer(common.mustCall((req, res) => {
11 res.end('ok');
12 }));
13 server.listen(0, () => {
14 http.get({
15 port: server.address().port,
16 headers: {'Test': 'Düsseldorf'}
17 }, common.mustCall((res) => {
18 assert.strictEqual(res.statusCode, 200);
19 server.close();
20 }));
21 });
```

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

Why? It checks for leaks of globals.

**Lines 3-4**
**Lines 4-5**

```javascript
// This test ensures that the http-parser can handle UTF-8 characters
// in the http header.
```

A test should start with a comment containing a brief description of what it is
designed to test.


**Lines 7-8**

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

**Lines 6-17**
**Lines 10-21**

This is the body of the test. This test is quite simple, it just tests that an
HTTP server accepts `non-ASCII` characters in the headers of an incoming
Expand Down
7 changes: 5 additions & 2 deletions test/parallel/test-http-header-obstext.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

const common = require('../common');

// This test ensures that the http-parser can handle UTF-8 characters
// in the http header.

const http = require('http');
const assert = require('assert');

Expand All @@ -12,7 +15,7 @@ server.listen(0, () => {
port: server.address().port,
headers: {'Test': 'Düsseldorf'}
}, common.mustCall((res) => {
assert.equal(res.statusCode, 200);
assert.strictEqual(res.statusCode, 200);
server.close();
}));
});