Skip to content

Commit ec226a2

Browse files
Trottitaloacasas
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 <[email protected]> Reviewed-By: Italo A. Casas <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
1 parent b73e98b commit ec226a2

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

doc/guides/writing-tests.md

+16-5
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.
@@ -205,3 +204,15 @@ require('../common');
205204
const assert = require('assert');
206205
const freelist = require('internal/freelist');
207206
```
207+
208+
## Naming Test Files
209+
210+
Test files are named using kebab casing. The first component of the name is
211+
`test`. The second is the module or subsystem being tested. The third is usually
212+
the method or event name being tested. Subsequent components of the name add
213+
more information about what is being tested.
214+
215+
For example, a test for the `beforeExit` event on the `process` object might be
216+
named `test-process-before-exit.js`. If the test specifically checked that arrow
217+
functions worked correctly with the `beforeExit` event, then it might be named
218+
`test-process-before-exit-arrow-functions.js`.

0 commit comments

Comments
 (0)