Skip to content

Commit 7e8c5e3

Browse files
Trottitaloacasas
authored andcommitted
doc: expand common module material in test guide
Provide a little more information about the `common` module. This doesn't really provide much that wasn't already there, but hopefully makes some things a bit more explicit for first-time readers. PR-URL: #10251 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Italo A. Casas <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 28ffd59 commit 7e8c5e3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

doc/guides/writing-tests.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Tests can be added for multiple reasons:
1919
- When fixing regressions and bugs.
2020
- When expanding test coverage.
2121

22-
2322
## Test structure
2423

2524
Let's analyze this very basic test from the Node.js test suite:
@@ -55,17 +54,22 @@ Let's analyze this very basic test from the Node.js test suite:
5554
const common = require('../common');
5655
```
5756

58-
These two lines are mandatory and should be included on every test.
59-
The `common` module is a helper module that provides useful tools for the tests.
60-
If for some reason, no functionality from `common` is used, it should still be
61-
included like this:
57+
The first line enables strict mode. All tests should be in strict mode unless
58+
the nature of the test requires that the test run without it.
59+
60+
The second line loads the `common` module. The `common` module is a helper
61+
module that provides useful tools for the tests.
62+
63+
Even if no functions or other properties exported by `common` are used in a
64+
test, the `common` module should still be included. This is because the `common`
65+
module includes code that will cause tests to fail if variables are leaked into
66+
the global space. In situations where no functions or other properties exported
67+
by `common` are used, it can be included without assigning it to an identifier:
6268

6369
```javascript
6470
require('../common');
6571
```
6672

67-
Why? It checks for leaks of globals.
68-
6973
**Lines 4-5**
7074

7175
```javascript
@@ -76,7 +80,6 @@ Why? It checks for leaks of globals.
7680
A test should start with a comment containing a brief description of what it is
7781
designed to test.
7882

79-
8083
**Lines 7-8**
8184

8285
```javascript

0 commit comments

Comments
 (0)