Skip to content

Commit 8f0e31b

Browse files
TrottMylesBorins
authored andcommitted
doc: add test naming information to guide
The guide for writing tests is missing information on how tests are named. This adds that information. There is also some copy-editing done on the first paragraph of the guide. PR-URL: #10584 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
1 parent 56b779d commit 8f0e31b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

doc/guides/writing-tests.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
## What is a test?
44

5-
A test must be a node script that exercises a specific functionality provided
6-
by node and checks that it behaves as expected. It should exit with code `0` on success,
7-
otherwise it will fail. A test will fail if:
5+
Most tests in Node.js core are JavaScript programs that exercise a functionality
6+
provided by Node.js and check that it behaves as expected. Tests should exit
7+
with code `0` on success. A test will fail if:
88

99
- It exits by setting `process.exitCode` to a non-zero number.
10-
- This is most often done by having an assertion throw an uncaught
11-
Error.
10+
- This is usually done by having an assertion throw an uncaught Error.
1211
- Occasionally, using `process.exit(code)` may be appropriate.
1312
- It never exits. In this case, the test runner will terminate the test because
1413
it sets a maximum time limit.
@@ -186,3 +185,15 @@ require('../common');
186185
const assert = require('assert');
187186
const freelist = require('internal/freelist');
188187
```
188+
189+
## Naming Test Files
190+
191+
Test files are named using kebab casing. The first component of the name is
192+
`test`. The second is the module or subsystem being tested. The third is usually
193+
the method or event name being tested. Subsequent components of the name add
194+
more information about what is being tested.
195+
196+
For example, a test for the `beforeExit` event on the `process` object might be
197+
named `test-process-before-exit.js`. If the test specifically checked that arrow
198+
functions worked correctly with the `beforeExit` event, then it might be named
199+
`test-process-before-exit-arrow-functions.js`.

0 commit comments

Comments
 (0)