summaryrefslogtreecommitdiff
path: root/doc/guides
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2016-12-13 09:12:05 -0800
committerMyles Borins <mylesborins@google.com>2017-01-31 17:07:46 -0500
commit2eccea06b5940ba4701415dd7f26a6821f1b687b (patch)
tree9248e62c3ce496feddd12fb469886fc10ddfee67 /doc/guides
parent92e3f8f26e2598b234a4eb521a2b2e4000bb4325 (diff)
downloadnode-new-2eccea06b5940ba4701415dd7f26a6821f1b687b.tar.gz
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: https://github.com/nodejs/node/pull/10251 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'doc/guides')
-rw-r--r--doc/guides/writing-tests.md19
1 files changed, 11 insertions, 8 deletions
diff --git a/doc/guides/writing-tests.md b/doc/guides/writing-tests.md
index d00be9cdbc..d628e3f6f5 100644
--- a/doc/guides/writing-tests.md
+++ b/doc/guides/writing-tests.md
@@ -19,7 +19,6 @@ Tests can be added for multiple reasons:
- When fixing regressions and bugs.
- When expanding test coverage.
-
## Test structure
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:
const common = require('../common');
```
-These two lines are mandatory and should be included on every test.
-The `common` module is a helper module that provides useful tools for the tests.
-If for some reason, no functionality from `common` is used, it should still be
-included like this:
+The first line enables strict mode. All tests should be in strict mode unless
+the nature of the test requires that the test run without it.
+
+The second line loads the `common` module. The `common` module is a helper
+module that provides useful tools for the tests.
+
+Even if no functions or other properties exported by `common` are used in a
+test, the `common` module should still be included. This is because the `common`
+module includes code that will cause tests to fail if variables are leaked into
+the global space. In situations where no functions or other properties exported
+by `common` are used, it can be included without assigning it to an identifier:
```javascript
require('../common');
```
-Why? It checks for leaks of globals.
-
**Lines 4-5**
```javascript
@@ -76,7 +80,6 @@ Why? It checks for leaks of globals.
A test should start with a comment containing a brief description of what it is
designed to test.
-
**Lines 7-8**
```javascript